test_lefant_m213_vacuum.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. from homeassistant.components.sensor import SensorDeviceClass
  2. from homeassistant.components.vacuum import (
  3. STATE_CLEANING,
  4. STATE_DOCKED,
  5. STATE_ERROR,
  6. STATE_IDLE,
  7. STATE_PAUSED,
  8. STATE_RETURNING,
  9. VacuumEntityFeature,
  10. )
  11. from homeassistant.const import AREA_SQUARE_METERS, UnitOfTime
  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": UnitOfTime.MINUTES,
  48. "device_class": SensorDeviceClass.DURATION,
  49. },
  50. ],
  51. )
  52. self.mark_secondary(["sensor_clean_area", "sensor_clean_time"])
  53. def test_supported_features(self):
  54. self.assertEqual(
  55. self.subject.supported_features,
  56. (
  57. VacuumEntityFeature.STATE
  58. | VacuumEntityFeature.STATUS
  59. | VacuumEntityFeature.SEND_COMMAND
  60. | VacuumEntityFeature.BATTERY
  61. | VacuumEntityFeature.TURN_ON
  62. | VacuumEntityFeature.TURN_OFF
  63. | VacuumEntityFeature.START
  64. | VacuumEntityFeature.PAUSE
  65. | VacuumEntityFeature.LOCATE
  66. | VacuumEntityFeature.RETURN_HOME
  67. | VacuumEntityFeature.CLEAN_SPOT
  68. | VacuumEntityFeature.FAN_SPEED
  69. ),
  70. )
  71. def test_battery_level(self):
  72. self.dps[BATTERY_DPS] = 50
  73. self.assertEqual(self.subject.battery_level, 50)
  74. def test_fan_speed(self):
  75. self.dps[FAN_DPS] = "low"
  76. self.assertEqual(self.subject.fan_speed, "Low")
  77. self.dps[FAN_DPS] = "nar"
  78. self.assertEqual(self.subject.fan_speed, "Medium")
  79. self.dps[FAN_DPS] = "high"
  80. self.assertEqual(self.subject.fan_speed, "High")
  81. def test_status(self):
  82. self.dps[STATUS_DPS] = "0"
  83. self.assertEqual(self.subject.status, "paused")
  84. self.dps[STATUS_DPS] = "1"
  85. self.assertEqual(self.subject.status, "smart")
  86. self.dps[STATUS_DPS] = "2"
  87. self.assertEqual(self.subject.status, "wall follow")
  88. self.dps[STATUS_DPS] = "3"
  89. self.assertEqual(self.subject.status, "spiral")
  90. self.dps[STATUS_DPS] = "4"
  91. self.assertEqual(self.subject.status, "returning")
  92. self.dps[STATUS_DPS] = "5"
  93. self.assertEqual(self.subject.status, "charging")
  94. self.dps[STATUS_DPS] = "6"
  95. self.assertEqual(self.subject.status, "random")
  96. self.dps[STATUS_DPS] = "7"
  97. self.assertEqual(self.subject.status, "standby")
  98. def test_state(self):
  99. self.dps[POWER_DPS] = True
  100. self.dps[SWITCH_DPS] = True
  101. self.dps[ERROR_DPS] = 0
  102. self.dps[STATUS_DPS] = "4"
  103. self.assertEqual(self.subject.state, STATE_RETURNING)
  104. self.dps[STATUS_DPS] = "7"
  105. self.assertEqual(self.subject.state, STATE_IDLE)
  106. self.dps[STATUS_DPS] = "6"
  107. self.assertEqual(self.subject.state, STATE_CLEANING)
  108. self.dps[POWER_DPS] = False
  109. self.assertEqual(self.subject.state, STATE_IDLE)
  110. self.dps[POWER_DPS] = True
  111. self.dps[SWITCH_DPS] = False
  112. self.assertEqual(self.subject.state, STATE_PAUSED)
  113. self.dps[ERROR_DPS] = 1
  114. self.assertEqual(self.subject.state, STATE_ERROR)
  115. async def test_async_turn_on(self):
  116. async with assert_device_properties_set(
  117. self.subject._device,
  118. {POWER_DPS: True},
  119. ):
  120. await self.subject.async_turn_on()
  121. async def test_async_turn_off(self):
  122. async with assert_device_properties_set(
  123. self.subject._device,
  124. {POWER_DPS: False},
  125. ):
  126. await self.subject.async_turn_off()
  127. async def test_async_toggle(self):
  128. self.dps[POWER_DPS] = False
  129. async with assert_device_properties_set(
  130. self.subject._device,
  131. {POWER_DPS: True},
  132. ):
  133. await self.subject.async_toggle()
  134. async def test_async_start(self):
  135. async with assert_device_properties_set(
  136. self.subject._device,
  137. {SWITCH_DPS: True},
  138. ):
  139. await self.subject.async_start()
  140. async def test_async_pause(self):
  141. async with assert_device_properties_set(
  142. self.subject._device,
  143. {SWITCH_DPS: False},
  144. ):
  145. await self.subject.async_pause()
  146. async def test_async_return_to_base(self):
  147. async with assert_device_properties_set(
  148. self.subject._device,
  149. {COMMAND_DPS: "chargego"},
  150. ):
  151. await self.subject.async_return_to_base()
  152. async def test_async_clean_spot(self):
  153. async with assert_device_properties_set(
  154. self.subject._device,
  155. {COMMAND_DPS: "spiral"},
  156. ):
  157. await self.subject.async_clean_spot()
  158. async def test_async_locate(self):
  159. async with assert_device_properties_set(
  160. self.subject._device,
  161. {LOCATE_DPS: True},
  162. ):
  163. await self.subject.async_locate()
  164. async def test_async_send_standby_command(self):
  165. async with assert_device_properties_set(
  166. self.subject._device,
  167. {COMMAND_DPS: "standby"},
  168. ):
  169. await self.subject.async_send_command("standby")
  170. async def test_async_send_smart_command(self):
  171. async with assert_device_properties_set(
  172. self.subject._device,
  173. {COMMAND_DPS: "smart"},
  174. ):
  175. await self.subject.async_send_command("smart")
  176. async def test_async_send_random_command(self):
  177. async with assert_device_properties_set(
  178. self.subject._device,
  179. {COMMAND_DPS: "random"},
  180. ):
  181. await self.subject.async_send_command("random")
  182. async def test_async_send_wall_follow_command(self):
  183. async with assert_device_properties_set(
  184. self.subject._device,
  185. {COMMAND_DPS: "wall_follow"},
  186. ):
  187. await self.subject.async_send_command("wall_follow")
  188. async def test_async_send_reverse_command(self):
  189. async with assert_device_properties_set(
  190. self.subject._device,
  191. {DIRECTION_DPS: "backward"},
  192. ):
  193. await self.subject.async_send_command("reverse")
  194. async def test_async_send_left_command(self):
  195. async with assert_device_properties_set(
  196. self.subject._device,
  197. {DIRECTION_DPS: "turn_left"},
  198. ):
  199. await self.subject.async_send_command("left")
  200. async def test_async_send_right_command(self):
  201. async with assert_device_properties_set(
  202. self.subject._device,
  203. {DIRECTION_DPS: "turn_right"},
  204. ):
  205. await self.subject.async_send_command("right")
  206. async def test_async_send_stop_command(self):
  207. async with assert_device_properties_set(
  208. self.subject._device,
  209. {DIRECTION_DPS: "stop"},
  210. ):
  211. await self.subject.async_send_command("stop")