test_lefant_m213_vacuum.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. from homeassistant.components.vacuum import (
  2. STATE_CLEANING,
  3. STATE_DOCKED,
  4. STATE_ERROR,
  5. STATE_RETURNING,
  6. SUPPORT_BATTERY,
  7. SUPPORT_CLEAN_SPOT,
  8. SUPPORT_LOCATE,
  9. SUPPORT_PAUSE,
  10. SUPPORT_RETURN_HOME,
  11. SUPPORT_SEND_COMMAND,
  12. SUPPORT_START,
  13. SUPPORT_STATE,
  14. SUPPORT_STATUS,
  15. SUPPORT_TURN_OFF,
  16. SUPPORT_TURN_ON,
  17. )
  18. from homeassistant.const import (
  19. AREA_SQUARE_METERS,
  20. TIME_MINUTES,
  21. )
  22. from ..const import LEFANT_M213_VACUUM_PAYLOAD
  23. from ..helpers import assert_device_properties_set
  24. from ..mixins.sensor import MultiSensorTests
  25. from .base_device_tests import TuyaDeviceTestCase
  26. POWER_DPS = "1"
  27. SWITCH_DPS = "2"
  28. STATUS_DPS = "3"
  29. DIRECTION_DPS = "4"
  30. UNKNOWN5_DPS = "5"
  31. BATTERY_DPS = "6"
  32. LOCATE_DPS = "13"
  33. AREA_DPS = "16"
  34. TIME_DPS = "17"
  35. ERROR_DPS = "18"
  36. UNKNOWN101_DPS = "101"
  37. UNKNOWN102_DPS = "102"
  38. UNKNOWN103_DPS = "103"
  39. UNKNOWN104_DPS = "104"
  40. UNKNOWN106_DPS = "106"
  41. UNKNOWN108_DPS = "108"
  42. class TestLefantM213Vacuum(MultiSensorTests, TuyaDeviceTestCase):
  43. __test__ = True
  44. def setUp(self):
  45. self.setUpForConfig("lefant_m213_vacuum.yaml", LEFANT_M213_VACUUM_PAYLOAD)
  46. self.subject = self.entities.get("vacuum")
  47. self.setUpMultiSensors(
  48. [
  49. {
  50. "dps": AREA_DPS,
  51. "name": "sensor_clean_area",
  52. "unit": AREA_SQUARE_METERS,
  53. },
  54. {
  55. "dps": TIME_DPS,
  56. "name": "sensor_clean_time",
  57. "unit": TIME_MINUTES,
  58. },
  59. ],
  60. )
  61. self.mark_secondary(["sensor_clean_area", "sensor_clean_time"])
  62. def test_supported_features(self):
  63. self.assertEqual(
  64. self.subject.supported_features,
  65. SUPPORT_STATE
  66. | SUPPORT_STATUS
  67. | SUPPORT_SEND_COMMAND
  68. | SUPPORT_BATTERY
  69. | SUPPORT_TURN_ON
  70. | SUPPORT_TURN_OFF
  71. | SUPPORT_START
  72. | SUPPORT_PAUSE
  73. | SUPPORT_LOCATE
  74. | SUPPORT_RETURN_HOME
  75. | SUPPORT_CLEAN_SPOT,
  76. )
  77. def test_battery_level(self):
  78. self.dps[BATTERY_DPS] = 50
  79. self.assertEqual(self.subject.battery_level, 50)
  80. def test_status(self):
  81. self.dps[STATUS_DPS] = "standby"
  82. self.assertEqual(self.subject.status, "standby")
  83. self.dps[STATUS_DPS] = "smart"
  84. self.assertEqual(self.subject.status, "smart")
  85. self.dps[STATUS_DPS] = "chargego"
  86. self.assertEqual(self.subject.status, "return_to_base")
  87. self.dps[STATUS_DPS] = "random"
  88. self.assertEqual(self.subject.status, "random")
  89. self.dps[STATUS_DPS] = "wall_follow"
  90. self.assertEqual(self.subject.status, "wall_follow")
  91. self.dps[STATUS_DPS] = "spiral"
  92. self.assertEqual(self.subject.status, "clean_spot")
  93. def test_state(self):
  94. self.dps[POWER_DPS] = True
  95. self.dps[SWITCH_DPS] = True
  96. self.dps[ERROR_DPS] = 0
  97. self.dps[STATUS_DPS] = "return_to_base"
  98. self.assertEqual(self.subject.state, STATE_RETURNING)
  99. self.dps[STATUS_DPS] = "standby"
  100. self.assertEqual(self.subject.state, STATE_DOCKED)
  101. self.dps[STATUS_DPS] = "random"
  102. self.assertEqual(self.subject.state, STATE_CLEANING)
  103. self.dps[POWER_DPS] = False
  104. self.assertEqual(self.subject.state, STATE_DOCKED)
  105. self.dps[POWER_DPS] = True
  106. self.dps[SWITCH_DPS] = False
  107. self.assertEqual(self.subject.state, STATE_DOCKED)
  108. self.dps[ERROR_DPS] = 1
  109. self.assertEqual(self.subject.state, STATE_ERROR)
  110. async def test_async_turn_on(self):
  111. async with assert_device_properties_set(
  112. self.subject._device,
  113. {POWER_DPS: True},
  114. ):
  115. await self.subject.async_turn_on()
  116. async def test_async_turn_off(self):
  117. async with assert_device_properties_set(
  118. self.subject._device,
  119. {POWER_DPS: False},
  120. ):
  121. await self.subject.async_turn_off()
  122. async def test_async_toggle(self):
  123. self.dps[POWER_DPS] = False
  124. async with assert_device_properties_set(
  125. self.subject._device,
  126. {POWER_DPS: True},
  127. ):
  128. await self.subject.async_toggle()
  129. async def test_async_start(self):
  130. async with assert_device_properties_set(
  131. self.subject._device,
  132. {SWITCH_DPS: True},
  133. ):
  134. await self.subject.async_start()
  135. async def test_async_pause(self):
  136. async with assert_device_properties_set(
  137. self.subject._device,
  138. {SWITCH_DPS: False},
  139. ):
  140. await self.subject.async_pause()
  141. async def test_async_return_to_base(self):
  142. async with assert_device_properties_set(
  143. self.subject._device,
  144. {STATUS_DPS: "chargego"},
  145. ):
  146. await self.subject.async_return_to_base()
  147. async def test_async_clean_spot(self):
  148. async with assert_device_properties_set(
  149. self.subject._device,
  150. {STATUS_DPS: "spiral"},
  151. ):
  152. await self.subject.async_clean_spot()
  153. async def test_async_locate(self):
  154. async with assert_device_properties_set(
  155. self.subject._device,
  156. {LOCATE_DPS: True},
  157. ):
  158. await self.subject.async_locate()
  159. async def test_async_send_standby_command(self):
  160. async with assert_device_properties_set(
  161. self.subject._device,
  162. {STATUS_DPS: "standby"},
  163. ):
  164. await self.subject.async_send_command("standby")
  165. async def test_async_send_smart_command(self):
  166. async with assert_device_properties_set(
  167. self.subject._device,
  168. {STATUS_DPS: "smart"},
  169. ):
  170. await self.subject.async_send_command("smart")
  171. async def test_async_send_random_command(self):
  172. async with assert_device_properties_set(
  173. self.subject._device,
  174. {STATUS_DPS: "random"},
  175. ):
  176. await self.subject.async_send_command("random")
  177. async def test_async_send_wall_follow_command(self):
  178. async with assert_device_properties_set(
  179. self.subject._device,
  180. {STATUS_DPS: "wall_follow"},
  181. ):
  182. await self.subject.async_send_command("wall_follow")
  183. async def test_async_send_reverse_command(self):
  184. async with assert_device_properties_set(
  185. self.subject._device,
  186. {DIRECTION_DPS: "backward"},
  187. ):
  188. await self.subject.async_send_command("reverse")
  189. async def test_async_send_left_command(self):
  190. async with assert_device_properties_set(
  191. self.subject._device,
  192. {DIRECTION_DPS: "turn_left"},
  193. ):
  194. await self.subject.async_send_command("left")
  195. async def test_async_send_right_command(self):
  196. async with assert_device_properties_set(
  197. self.subject._device,
  198. {DIRECTION_DPS: "turn_right"},
  199. ):
  200. await self.subject.async_send_command("right")
  201. async def test_async_send_stop_command(self):
  202. async with assert_device_properties_set(
  203. self.subject._device,
  204. {DIRECTION_DPS: "stop"},
  205. ):
  206. await self.subject.async_send_command("stop")