test_lefant_m213_vacuum.py 8.3 KB

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