test_kyvol_e30_vacuum.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. from homeassistant.components.button import ButtonDeviceClass
  2. from homeassistant.components.sensor import SensorDeviceClass
  3. from homeassistant.components.vacuum import (
  4. STATE_CLEANING,
  5. STATE_DOCKED,
  6. STATE_ERROR,
  7. STATE_IDLE,
  8. STATE_PAUSED,
  9. STATE_RETURNING,
  10. VacuumEntityFeature,
  11. )
  12. from homeassistant.const import AREA_SQUARE_METERS, PERCENTAGE, UnitOfTime
  13. from ..const import KYVOL_E30_VACUUM_PAYLOAD
  14. from ..helpers import assert_device_properties_set
  15. from ..mixins.button import MultiButtonTests
  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. EDGE_DPS = "7"
  25. ROLL_DPS = "8"
  26. FILTER_DPS = "9"
  27. RSTEDGE_DPS = "10"
  28. RSTROLL_DPS = "11"
  29. RSTFILTER_DPS = "12"
  30. LOCATE_DPS = "13"
  31. FAN_DPS = "14"
  32. AREA_DPS = "16"
  33. TIME_DPS = "17"
  34. ERROR_DPS = "18"
  35. WATER_DPS = "101"
  36. MODEL_DPS = "102"
  37. MODE_DPS = "104"
  38. CARPET_DPS = "107"
  39. class TestKyvolE30Vacuum(MultiButtonTests, MultiSensorTests, TuyaDeviceTestCase):
  40. __test__ = True
  41. def setUp(self):
  42. self.setUpForConfig("kyvol_e30_vacuum.yaml", KYVOL_E30_VACUUM_PAYLOAD)
  43. self.subject = self.entities.get("vacuum")
  44. self.setUpMultiButtons(
  45. [
  46. {
  47. "dps": RSTEDGE_DPS,
  48. "name": "button_edge_brush_reset",
  49. "device_class": ButtonDeviceClass.RESTART,
  50. },
  51. {
  52. "dps": RSTROLL_DPS,
  53. "name": "button_roll_brush_reset",
  54. "device_class": ButtonDeviceClass.RESTART,
  55. },
  56. {
  57. "dps": RSTFILTER_DPS,
  58. "name": "button_filter_reset",
  59. "device_class": ButtonDeviceClass.RESTART,
  60. },
  61. ]
  62. )
  63. self.setUpMultiSensors(
  64. [
  65. {
  66. "dps": AREA_DPS,
  67. "name": "sensor_clean_area",
  68. "unit": AREA_SQUARE_METERS,
  69. "testdata": (30, 3.0),
  70. },
  71. {
  72. "dps": TIME_DPS,
  73. "name": "sensor_clean_time",
  74. "unit": UnitOfTime.MINUTES,
  75. "device_class": SensorDeviceClass.DURATION,
  76. },
  77. {
  78. "dps": EDGE_DPS,
  79. "name": "sensor_edge_brush",
  80. "unit": PERCENTAGE,
  81. },
  82. {
  83. "dps": ROLL_DPS,
  84. "name": "sensor_roll_brush",
  85. "unit": PERCENTAGE,
  86. },
  87. {
  88. "dps": FILTER_DPS,
  89. "name": "sensor_filter",
  90. "unit": PERCENTAGE,
  91. },
  92. {
  93. "dps": STATUS_DPS,
  94. "name": "sensor_status",
  95. },
  96. ],
  97. )
  98. self.mark_secondary(
  99. [
  100. "button_edge_brush_reset",
  101. "button_roll_brush_reset",
  102. "button_filter_reset",
  103. "sensor_clean_area",
  104. "sensor_clean_time",
  105. "sensor_edge_brush",
  106. "sensor_roll_brush",
  107. "sensor_filter",
  108. "sensor_status",
  109. ]
  110. )
  111. def test_supported_features(self):
  112. self.assertEqual(
  113. self.subject.supported_features,
  114. (
  115. VacuumEntityFeature.STATE
  116. | VacuumEntityFeature.STATUS
  117. | VacuumEntityFeature.SEND_COMMAND
  118. | VacuumEntityFeature.BATTERY
  119. | VacuumEntityFeature.FAN_SPEED
  120. | VacuumEntityFeature.TURN_ON
  121. | VacuumEntityFeature.TURN_OFF
  122. | VacuumEntityFeature.START
  123. | VacuumEntityFeature.PAUSE
  124. | VacuumEntityFeature.LOCATE
  125. | VacuumEntityFeature.RETURN_HOME
  126. | VacuumEntityFeature.CLEAN_SPOT
  127. ),
  128. )
  129. def test_battery_level(self):
  130. self.dps[BATTERY_DPS] = 50
  131. self.assertEqual(self.subject.battery_level, 50)
  132. def test_status(self):
  133. self.dps[COMMAND_DPS] = "standby"
  134. self.assertEqual(self.subject.status, "standby")
  135. self.dps[COMMAND_DPS] = "smart"
  136. self.assertEqual(self.subject.status, "smart")
  137. self.dps[COMMAND_DPS] = "chargego"
  138. self.assertEqual(self.subject.status, "return_to_base")
  139. self.dps[COMMAND_DPS] = "random"
  140. self.assertEqual(self.subject.status, "random")
  141. self.dps[COMMAND_DPS] = "wall_follow"
  142. self.assertEqual(self.subject.status, "wall_follow")
  143. self.dps[COMMAND_DPS] = "spiral"
  144. self.assertEqual(self.subject.status, "clean_spot")
  145. def test_state(self):
  146. self.dps[POWER_DPS] = True
  147. self.dps[SWITCH_DPS] = True
  148. self.dps[ERROR_DPS] = 0
  149. self.dps[COMMAND_DPS] = "return_to_base"
  150. self.assertEqual(self.subject.state, STATE_RETURNING)
  151. self.dps[COMMAND_DPS] = "standby"
  152. self.assertEqual(self.subject.state, STATE_IDLE)
  153. self.dps[COMMAND_DPS] = "random"
  154. self.assertEqual(self.subject.state, STATE_CLEANING)
  155. self.dps[POWER_DPS] = False
  156. self.assertEqual(self.subject.state, STATE_IDLE)
  157. self.dps[POWER_DPS] = True
  158. self.dps[SWITCH_DPS] = False
  159. self.assertEqual(self.subject.state, STATE_PAUSED)
  160. self.dps[ERROR_DPS] = 1
  161. self.assertEqual(self.subject.state, STATE_ERROR)
  162. async def test_async_turn_on(self):
  163. async with assert_device_properties_set(
  164. self.subject._device,
  165. {POWER_DPS: True},
  166. ):
  167. await self.subject.async_turn_on()
  168. async def test_async_turn_off(self):
  169. async with assert_device_properties_set(
  170. self.subject._device,
  171. {POWER_DPS: False},
  172. ):
  173. await self.subject.async_turn_off()
  174. async def test_async_toggle(self):
  175. self.dps[POWER_DPS] = False
  176. async with assert_device_properties_set(
  177. self.subject._device,
  178. {POWER_DPS: True},
  179. ):
  180. await self.subject.async_toggle()
  181. async def test_async_start(self):
  182. async with assert_device_properties_set(
  183. self.subject._device,
  184. {SWITCH_DPS: True},
  185. ):
  186. await self.subject.async_start()
  187. async def test_async_pause(self):
  188. async with assert_device_properties_set(
  189. self.subject._device,
  190. {SWITCH_DPS: False},
  191. ):
  192. await self.subject.async_pause()
  193. async def test_async_return_to_base(self):
  194. async with assert_device_properties_set(
  195. self.subject._device,
  196. {COMMAND_DPS: "chargego"},
  197. ):
  198. await self.subject.async_return_to_base()
  199. async def test_async_clean_spot(self):
  200. async with assert_device_properties_set(
  201. self.subject._device,
  202. {COMMAND_DPS: "spiral"},
  203. ):
  204. await self.subject.async_clean_spot()
  205. async def test_async_locate(self):
  206. async with assert_device_properties_set(
  207. self.subject._device,
  208. {LOCATE_DPS: True},
  209. ):
  210. await self.subject.async_locate()
  211. async def test_async_send_standby_command(self):
  212. async with assert_device_properties_set(
  213. self.subject._device,
  214. {COMMAND_DPS: "standby"},
  215. ):
  216. await self.subject.async_send_command("standby")
  217. async def test_async_send_smart_command(self):
  218. async with assert_device_properties_set(
  219. self.subject._device,
  220. {COMMAND_DPS: "smart"},
  221. ):
  222. await self.subject.async_send_command("smart")
  223. async def test_async_send_random_command(self):
  224. async with assert_device_properties_set(
  225. self.subject._device,
  226. {COMMAND_DPS: "random"},
  227. ):
  228. await self.subject.async_send_command("random")
  229. async def test_async_send_wall_follow_command(self):
  230. async with assert_device_properties_set(
  231. self.subject._device,
  232. {COMMAND_DPS: "wall_follow"},
  233. ):
  234. await self.subject.async_send_command("wall_follow")
  235. async def test_async_send_reverse_command(self):
  236. async with assert_device_properties_set(
  237. self.subject._device,
  238. {DIRECTION_DPS: "backward"},
  239. ):
  240. await self.subject.async_send_command("reverse")
  241. async def test_async_send_left_command(self):
  242. async with assert_device_properties_set(
  243. self.subject._device,
  244. {DIRECTION_DPS: "turn_left"},
  245. ):
  246. await self.subject.async_send_command("left")
  247. async def test_async_send_right_command(self):
  248. async with assert_device_properties_set(
  249. self.subject._device,
  250. {DIRECTION_DPS: "turn_right"},
  251. ):
  252. await self.subject.async_send_command("right")
  253. async def test_async_send_stop_command(self):
  254. async with assert_device_properties_set(
  255. self.subject._device,
  256. {DIRECTION_DPS: "stop"},
  257. ):
  258. await self.subject.async_send_command("stop")
  259. def test_fan_speed(self):
  260. self.dps[FAN_DPS] = "2"
  261. self.assertEqual(self.subject.fan_speed, "quiet")
  262. def test_fan_speed_list(self):
  263. self.assertCountEqual(
  264. self.subject.fan_speed_list,
  265. [
  266. "strong",
  267. "normal",
  268. "quiet",
  269. "gentle",
  270. "closed",
  271. ],
  272. )
  273. async def test_async_set_fan_speed(self):
  274. async with assert_device_properties_set(self.subject._device, {FAN_DPS: "3"}):
  275. await self.subject.async_set_fan_speed(fan_speed="gentle")