test_lefant_m213_vacuum.py 8.2 KB

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