test_lefant_m213_vacuum.py 8.0 KB

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