4
0

test_kyvol_e30_vacuum.py 10 KB

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