test_lefant_m213_vacuum.py 7.9 KB

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