test_moebot.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. """
  2. Test MoeBot S mower.
  3. Primarily for testing the STOP command which this device is the first to use,
  4. and the lawn_mower platform.
  5. """
  6. from homeassistant.components.lawn_mower.const import (
  7. LawnMowerActivity,
  8. LawnMowerEntityFeature,
  9. )
  10. from ..const import MOEBOT_PAYLOAD
  11. from ..helpers import assert_device_properties_set
  12. from .base_device_tests import TuyaDeviceTestCase
  13. BATTERY_DP = "6"
  14. STATUS_DP = "101"
  15. ERROR_DP = "102"
  16. PROBLEM_DP = "103"
  17. RAINMODE_DP = "104"
  18. RUNTIME_DP = "105"
  19. PASSWD_DP = "106"
  20. CLEARSCHED_DP = "107"
  21. QUERYSCHED_DP = "108"
  22. QUERYZONE_DP = "109"
  23. SCHEDULE_DP = "110"
  24. ERRLOG_DP = "111"
  25. WORKLOG_DP = "112"
  26. ZONES_DP = "113"
  27. AUTOMODE_DP = "114"
  28. COMMAND_DP = "115"
  29. class TestMoebot(TuyaDeviceTestCase):
  30. __test__ = True
  31. def setUp(self):
  32. self.setUpForConfig("moebot_s_mower.yaml", MOEBOT_PAYLOAD)
  33. self.mower = self.entities.get("lawn_mower")
  34. self.start_button = self.entities.get("button_start_fixed_mowing")
  35. self.mark_secondary(
  36. [
  37. "binary_sensor_cover",
  38. "binary_sensor_problem",
  39. "select_mowing_mode",
  40. "sensor_problem",
  41. "switch_rain_mode",
  42. "number_running_time",
  43. "button_clear_schedule",
  44. "button_query_schedule",
  45. "button_query_zones",
  46. "switch_hedgehog_protection",
  47. ]
  48. )
  49. def test_supported_features(self):
  50. self.assertEqual(
  51. self.mower.supported_features,
  52. (
  53. LawnMowerEntityFeature.START_MOWING
  54. | LawnMowerEntityFeature.PAUSE
  55. | LawnMowerEntityFeature.DOCK
  56. ),
  57. )
  58. def test_lawnmower_activity(self):
  59. self.dps[STATUS_DP] = "ERROR"
  60. self.assertEqual(self.mower.activity, LawnMowerActivity.ERROR)
  61. self.dps[STATUS_DP] = "EMERGENCY"
  62. self.assertEqual(self.mower.activity, LawnMowerActivity.ERROR)
  63. self.dps[STATUS_DP] = "PAUSED"
  64. self.assertEqual(self.mower.activity, LawnMowerActivity.PAUSED)
  65. self.dps[STATUS_DP] = "PARK"
  66. self.assertEqual(self.mower.activity, LawnMowerActivity.RETURNING)
  67. self.dps[STATUS_DP] = "MOWING"
  68. self.assertEqual(self.mower.activity, LawnMowerActivity.MOWING)
  69. self.dps[STATUS_DP] = "FIXED_MOWING"
  70. self.assertEqual(self.mower.activity, LawnMowerActivity.MOWING)
  71. self.dps[STATUS_DP] = "STANDBY"
  72. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  73. self.dps[STATUS_DP] = "CHARGING"
  74. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  75. self.dps[STATUS_DP] = "LOCKED"
  76. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  77. self.dps[STATUS_DP] = "CHARGING_WITH_TASK_SUSPEND"
  78. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  79. async def test_async_start_mowing(self):
  80. async with assert_device_properties_set(
  81. self.mower._device,
  82. {COMMAND_DP: "StartMowing"},
  83. ):
  84. await self.mower.async_start_mowing()
  85. async def test_async_start_fixed_mowing(self):
  86. async with assert_device_properties_set(
  87. self.start_button._device,
  88. {COMMAND_DP: "StartFixedMowing"},
  89. ):
  90. await self.start_button.async_press()
  91. async def test_async_pause(self):
  92. async with assert_device_properties_set(
  93. self.mower._device,
  94. {COMMAND_DP: "PauseWork"},
  95. ):
  96. await self.mower.async_pause()
  97. async def test_async_dock(self):
  98. async with assert_device_properties_set(
  99. self.mower._device,
  100. {COMMAND_DP: "StartReturnStation"},
  101. ):
  102. await self.mower.async_dock()