test_kyvol_e30_vacuum.py 10 KB

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