test_moebot.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.vacuum import VacuumEntityFeature
  7. from homeassistant.components.lawn_mower.const import (
  8. LawnMowerActivity,
  9. LawnMowerEntityFeature,
  10. )
  11. from ..const import MOEBOT_PAYLOAD
  12. from ..helpers import assert_device_properties_set
  13. from .base_device_tests import TuyaDeviceTestCase
  14. BATTERY_DP = "6"
  15. STATUS_DP = "101"
  16. ERROR_DP = "102"
  17. PROBLEM_DP = "103"
  18. RAINMODE_DP = "104"
  19. RUNTIME_DP = "105"
  20. PASSWD_DP = "106"
  21. CLEARSCHED_DP = "107"
  22. QUERYSCHED_DP = "108"
  23. QUERYZONE_DP = "109"
  24. SCHEDULE_DP = "110"
  25. ERRLOG_DP = "111"
  26. WORKLOG_DP = "112"
  27. ZONES_DP = "113"
  28. AUTOMODE_DP = "114"
  29. COMMAND_DP = "115"
  30. class TestMoebot(TuyaDeviceTestCase):
  31. __test__ = True
  32. def setUp(self):
  33. self.setUpForConfig("moebot_s_mower.yaml", MOEBOT_PAYLOAD)
  34. self.subject = self.entities.get("vacuum")
  35. self.mower = self.entities.get("lawn_mower")
  36. self.mark_secondary(
  37. [
  38. "binary_sensor_error",
  39. "sensor_problem",
  40. "switch_rain_mode",
  41. "number_running_time",
  42. "button_clear_schedule",
  43. "button_query_schedule",
  44. "button_query_zones",
  45. ]
  46. )
  47. def test_supported_features(self):
  48. self.assertEqual(
  49. self.subject.supported_features,
  50. (
  51. VacuumEntityFeature.CLEAN_SPOT
  52. | VacuumEntityFeature.PAUSE
  53. | VacuumEntityFeature.RETURN_HOME
  54. | VacuumEntityFeature.SEND_COMMAND
  55. | VacuumEntityFeature.START
  56. | VacuumEntityFeature.STATE
  57. | VacuumEntityFeature.STATUS
  58. | VacuumEntityFeature.STOP
  59. ),
  60. )
  61. self.assertEqual(
  62. self.mower.supported_features,
  63. (
  64. LawnMowerEntityFeature.START_MOWING
  65. | LawnMowerEntityFeature.PAUSE
  66. | LawnMowerEntityFeature.DOCK
  67. ),
  68. )
  69. async def test_async_stop(self):
  70. async with assert_device_properties_set(
  71. self.subject._device,
  72. {COMMAND_DP: "CancelWork"},
  73. ):
  74. await self.subject.async_stop()
  75. def test_lawnmower_activity(self):
  76. self.dps[STATUS_DP] = "ERROR"
  77. self.assertEqual(
  78. self.mower.activity,
  79. LawnMowerActivity.ERROR
  80. )
  81. self.dps[STATUS_DP] = "EMERGENCY"
  82. self.assertEqual(
  83. self.mower.activity,
  84. LawnMowerActivity.ERROR
  85. )
  86. self.dps[STATUS_DP] = "PAUSED"
  87. self.assertEqual(
  88. self.mower.activity,
  89. LawnMowerActivity.PAUSED
  90. )
  91. self.dps[STATUS_DP] = "PARK"
  92. self.assertEqual(
  93. self.mower.activity,
  94. LawnMowerActivity.PAUSED
  95. )
  96. self.dps[STATUS_DP] = "MOWING"
  97. self.assertEqual(
  98. self.mower.activity,
  99. LawnMowerActivity.MOWING
  100. )
  101. self.dps[STATUS_DP] = "FIXED_MOWING"
  102. self.assertEqual(
  103. self.mower.activity,
  104. LawnMowerActivity.MOWING
  105. )
  106. self.dps[STATUS_DP] = "STANDBY"
  107. self.assertEqual(
  108. self.mower.activity,
  109. LawnMowerActivity.DOCKED
  110. )
  111. self.dps[STATUS_DP] = "CHARGING"
  112. self.assertEqual(
  113. self.mower.activity,
  114. LawnMowerActivity.DOCKED
  115. )
  116. self.dps[STATUS_DP] = "LOCKED"
  117. self.assertEqual(
  118. self.mower.activity,
  119. LawnMowerActivity.DOCKED
  120. )
  121. self.dps[STATUS_DP] = "CHARGING_WITH_TASK_SUSPEND"
  122. self.assertEqual(
  123. self.mower.activity,
  124. LawnMowerActivity.DOCKED
  125. )
  126. async def test_async_start_mowing(self):
  127. async with assert_device_properties_set(
  128. self.mower._device,
  129. {COMMAND_DP: "StartMowing"},
  130. ):
  131. await self.mower.async_start_mowing()
  132. async def test_async_pause(self):
  133. async with assert_device_properties_set(
  134. self.mower._device,
  135. {COMMAND_DP: "PauseWork"},
  136. ):
  137. await self.mower.async_pause()
  138. async def test_async_dock(self):
  139. async with assert_device_properties_set(
  140. self.mower._device,
  141. {COMMAND_DP: "StartReturnStation"},
  142. ):
  143. await self.mower.async_dock()