test_kyvol_e30_vacuum.py 10 KB

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