test_lefant_m213_vacuum.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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(["sensor_clean_area", "sensor_clean_time"])
  59. def test_supported_features(self):
  60. self.assertEqual(
  61. self.subject.supported_features,
  62. (
  63. VacuumEntityFeature.STATE
  64. | VacuumEntityFeature.STATUS
  65. | VacuumEntityFeature.SEND_COMMAND
  66. | VacuumEntityFeature.TURN_ON
  67. | VacuumEntityFeature.TURN_OFF
  68. | VacuumEntityFeature.START
  69. | VacuumEntityFeature.PAUSE
  70. | VacuumEntityFeature.LOCATE
  71. | VacuumEntityFeature.RETURN_HOME
  72. | VacuumEntityFeature.CLEAN_SPOT
  73. | VacuumEntityFeature.FAN_SPEED
  74. ),
  75. )
  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_IDLE)
  112. self.dps[POWER_DPS] = True
  113. self.dps[SWITCH_DPS] = False
  114. self.assertEqual(self.subject.state, STATE_PAUSED)
  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")