test_kyvol_e30_vacuum.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. from homeassistant.components.button import ButtonDeviceClass
  2. from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorDeviceClass
  3. from homeassistant.components.vacuum import (
  4. STATE_CLEANING,
  5. STATE_ERROR,
  6. STATE_IDLE,
  7. STATE_PAUSED,
  8. STATE_RETURNING,
  9. VacuumEntityFeature,
  10. )
  11. from homeassistant.const import AREA_SQUARE_METERS, PERCENTAGE, UnitOfTime
  12. from ..const import KYVOL_E30_VACUUM_PAYLOAD
  13. from ..helpers import assert_device_properties_set
  14. from ..mixins.button import MultiButtonTests
  15. from ..mixins.sensor import MultiSensorTests
  16. from .base_device_tests import TuyaDeviceTestCase
  17. POWER_DPS = "1"
  18. SWITCH_DPS = "2"
  19. COMMAND_DPS = "3"
  20. DIRECTION_DPS = "4"
  21. STATUS_DPS = "5"
  22. BATTERY_DPS = "6"
  23. EDGE_DPS = "7"
  24. ROLL_DPS = "8"
  25. FILTER_DPS = "9"
  26. RSTEDGE_DPS = "10"
  27. RSTROLL_DPS = "11"
  28. RSTFILTER_DPS = "12"
  29. LOCATE_DPS = "13"
  30. FAN_DPS = "14"
  31. AREA_DPS = "16"
  32. TIME_DPS = "17"
  33. ERROR_DPS = "18"
  34. WATER_DPS = "101"
  35. MODEL_DPS = "102"
  36. MODE_DPS = "104"
  37. CARPET_DPS = "107"
  38. class TestKyvolE30Vacuum(MultiButtonTests, MultiSensorTests, TuyaDeviceTestCase):
  39. __test__ = True
  40. def setUp(self):
  41. self.setUpForConfig("kyvol_e30_vacuum.yaml", KYVOL_E30_VACUUM_PAYLOAD)
  42. self.subject = self.entities.get("vacuum")
  43. self.setUpMultiButtons(
  44. [
  45. {
  46. "dps": RSTEDGE_DPS,
  47. "name": "button_edge_brush_reset",
  48. "device_class": ButtonDeviceClass.RESTART,
  49. },
  50. {
  51. "dps": RSTROLL_DPS,
  52. "name": "button_roll_brush_reset",
  53. "device_class": ButtonDeviceClass.RESTART,
  54. },
  55. {
  56. "dps": RSTFILTER_DPS,
  57. "name": "button_filter_reset",
  58. "device_class": ButtonDeviceClass.RESTART,
  59. },
  60. ]
  61. )
  62. self.setUpMultiSensors(
  63. [
  64. {
  65. "dps": AREA_DPS,
  66. "name": "sensor_clean_area",
  67. "unit": AREA_SQUARE_METERS,
  68. "testdata": (30, 3.0),
  69. },
  70. {
  71. "dps": TIME_DPS,
  72. "name": "sensor_clean_time",
  73. "unit": UnitOfTime.MINUTES,
  74. "device_class": SensorDeviceClass.DURATION,
  75. },
  76. {
  77. "dps": EDGE_DPS,
  78. "name": "sensor_edge_brush",
  79. "unit": PERCENTAGE,
  80. },
  81. {
  82. "dps": ROLL_DPS,
  83. "name": "sensor_roll_brush",
  84. "unit": PERCENTAGE,
  85. },
  86. {
  87. "dps": FILTER_DPS,
  88. "name": "sensor_filter",
  89. "unit": PERCENTAGE,
  90. },
  91. {
  92. "dps": STATUS_DPS,
  93. "name": "sensor_status",
  94. },
  95. {
  96. "dps": BATTERY_DPS,
  97. "name": "sensor_battery",
  98. "unit": PERCENTAGE,
  99. "device_class": SensorDeviceClass.BATTERY,
  100. "state_class": STATE_CLASS_MEASUREMENT,
  101. },
  102. ],
  103. )
  104. self.mark_secondary(
  105. [
  106. "button_edge_brush_reset",
  107. "button_roll_brush_reset",
  108. "button_filter_reset",
  109. "sensor_clean_area",
  110. "sensor_clean_time",
  111. "sensor_edge_brush",
  112. "sensor_roll_brush",
  113. "sensor_filter",
  114. "sensor_status",
  115. ]
  116. )
  117. def test_supported_features(self):
  118. self.assertEqual(
  119. self.subject.supported_features,
  120. (
  121. VacuumEntityFeature.STATE
  122. | VacuumEntityFeature.STATUS
  123. | VacuumEntityFeature.SEND_COMMAND
  124. | VacuumEntityFeature.FAN_SPEED
  125. | VacuumEntityFeature.TURN_ON
  126. | VacuumEntityFeature.TURN_OFF
  127. | VacuumEntityFeature.START
  128. | VacuumEntityFeature.PAUSE
  129. | VacuumEntityFeature.LOCATE
  130. | VacuumEntityFeature.RETURN_HOME
  131. | VacuumEntityFeature.CLEAN_SPOT
  132. ),
  133. )
  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_IDLE)
  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_IDLE)
  159. self.dps[POWER_DPS] = True
  160. self.dps[SWITCH_DPS] = False
  161. self.assertEqual(self.subject.state, STATE_PAUSED)
  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")