test_lefant_m213_vacuum.py 8.2 KB

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