test_lefant_m213_vacuum.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
  2. from homeassistant.components.vacuum import (
  3. VacuumActivity,
  4. VacuumEntityFeature,
  5. )
  6. from homeassistant.const import PERCENTAGE, UnitOfArea, UnitOfTime
  7. from ..const import LEFANT_M213_VACUUM_PAYLOAD
  8. from ..helpers import assert_device_properties_set
  9. from ..mixins.sensor import MultiSensorTests
  10. from .base_device_tests import TuyaDeviceTestCase
  11. POWER_DPS = "1"
  12. SWITCH_DPS = "2"
  13. COMMAND_DPS = "3"
  14. DIRECTION_DPS = "4"
  15. STATUS_DPS = "5"
  16. BATTERY_DPS = "6"
  17. LOCATE_DPS = "13"
  18. AREA_DPS = "16"
  19. TIME_DPS = "17"
  20. ERROR_DPS = "18"
  21. FAN_DPS = "101"
  22. UNKNOWN102_DPS = "102"
  23. UNKNOWN103_DPS = "103"
  24. UNKNOWN104_DPS = "104"
  25. UNKNOWN106_DPS = "106"
  26. UNKNOWN108_DPS = "108"
  27. class TestLefantM213Vacuum(MultiSensorTests, TuyaDeviceTestCase):
  28. def setUp(self):
  29. self.setUpForConfig("lefant_m213_vacuum.yaml", LEFANT_M213_VACUUM_PAYLOAD)
  30. self.subject = self.entities.get("vacuum")
  31. self.setUpMultiSensors(
  32. [
  33. {
  34. "dps": AREA_DPS,
  35. "name": "sensor_clean_area",
  36. "unit": UnitOfArea.SQUARE_METERS,
  37. "device_class": SensorDeviceClass.AREA,
  38. },
  39. {
  40. "dps": TIME_DPS,
  41. "name": "sensor_clean_time",
  42. "unit": UnitOfTime.MINUTES,
  43. "device_class": SensorDeviceClass.DURATION,
  44. },
  45. {
  46. "dps": BATTERY_DPS,
  47. "name": "sensor_battery",
  48. "unit": PERCENTAGE,
  49. "device_class": SensorDeviceClass.BATTERY,
  50. "state_class": SensorStateClass.MEASUREMENT,
  51. },
  52. ],
  53. )
  54. self.mark_secondary(
  55. ["sensor_clean_area", "sensor_clean_time", "binary_sensor_problem"]
  56. )
  57. def test_supported_features(self):
  58. self.assertEqual(
  59. self.subject.supported_features,
  60. (
  61. VacuumEntityFeature.CLEAN_SPOT
  62. | VacuumEntityFeature.FAN_SPEED
  63. | VacuumEntityFeature.LOCATE
  64. | VacuumEntityFeature.PAUSE
  65. | VacuumEntityFeature.RETURN_HOME
  66. | VacuumEntityFeature.SEND_COMMAND
  67. | VacuumEntityFeature.START
  68. | VacuumEntityFeature.STATE
  69. | VacuumEntityFeature.STATUS
  70. | VacuumEntityFeature.STOP
  71. | VacuumEntityFeature.TURN_ON
  72. | VacuumEntityFeature.TURN_OFF
  73. ),
  74. )
  75. def test_fan_speed(self):
  76. self.dps[FAN_DPS] = "low"
  77. self.assertEqual(self.subject.fan_speed, "Low")
  78. self.dps[FAN_DPS] = "nar"
  79. self.assertEqual(self.subject.fan_speed, "Medium")
  80. self.dps[FAN_DPS] = "high"
  81. self.assertEqual(self.subject.fan_speed, "High")
  82. def test_status(self):
  83. self.dps[STATUS_DPS] = "0"
  84. self.assertEqual(self.subject.status, "paused")
  85. self.dps[STATUS_DPS] = "1"
  86. self.assertEqual(self.subject.status, "smart")
  87. self.dps[STATUS_DPS] = "2"
  88. self.assertEqual(self.subject.status, "wall follow")
  89. self.dps[STATUS_DPS] = "3"
  90. self.assertEqual(self.subject.status, "spiral")
  91. self.dps[STATUS_DPS] = "4"
  92. self.assertEqual(self.subject.status, "returning")
  93. self.dps[STATUS_DPS] = "5"
  94. self.assertEqual(self.subject.status, "charging")
  95. self.dps[STATUS_DPS] = "6"
  96. self.assertEqual(self.subject.status, "random")
  97. self.dps[STATUS_DPS] = "7"
  98. self.assertEqual(self.subject.status, "standby")
  99. def test_activity(self):
  100. self.dps[POWER_DPS] = True
  101. self.dps[SWITCH_DPS] = True
  102. self.dps[ERROR_DPS] = 0
  103. self.dps[STATUS_DPS] = "4"
  104. self.assertEqual(self.subject.activity, VacuumActivity.RETURNING)
  105. self.dps[STATUS_DPS] = "7"
  106. self.assertEqual(self.subject.activity, VacuumActivity.IDLE)
  107. self.dps[STATUS_DPS] = "6"
  108. self.assertEqual(self.subject.activity, VacuumActivity.CLEANING)
  109. self.dps[POWER_DPS] = False
  110. self.assertEqual(self.subject.activity, VacuumActivity.IDLE)
  111. self.dps[POWER_DPS] = True
  112. self.dps[SWITCH_DPS] = False
  113. self.assertEqual(self.subject.activity, VacuumActivity.PAUSED)
  114. self.dps[ERROR_DPS] = 1
  115. self.assertEqual(self.subject.activity, VacuumActivity.ERROR)
  116. async def test_async_turn_on(self):
  117. async with assert_device_properties_set(
  118. self.subject._device,
  119. {POWER_DPS: True},
  120. ):
  121. await self.subject.async_turn_on()
  122. async def test_async_turn_off(self):
  123. async with assert_device_properties_set(
  124. self.subject._device,
  125. {POWER_DPS: False},
  126. ):
  127. await self.subject.async_turn_off()
  128. async def test_async_toggle(self):
  129. self.dps[POWER_DPS] = False
  130. async with assert_device_properties_set(
  131. self.subject._device,
  132. {POWER_DPS: True},
  133. ):
  134. await self.subject.async_toggle()
  135. async def test_async_start(self):
  136. async with assert_device_properties_set(
  137. self.subject._device,
  138. {SWITCH_DPS: True},
  139. ):
  140. await self.subject.async_start()
  141. async def test_async_pause(self):
  142. async with assert_device_properties_set(
  143. self.subject._device,
  144. {SWITCH_DPS: False},
  145. ):
  146. await self.subject.async_pause()
  147. async def test_async_return_to_base(self):
  148. async with assert_device_properties_set(
  149. self.subject._device,
  150. {COMMAND_DPS: "chargego"},
  151. ):
  152. await self.subject.async_return_to_base()
  153. async def test_async_clean_spot(self):
  154. async with assert_device_properties_set(
  155. self.subject._device,
  156. {COMMAND_DPS: "spiral"},
  157. ):
  158. await self.subject.async_clean_spot()
  159. async def test_async_locate(self):
  160. async with assert_device_properties_set(
  161. self.subject._device,
  162. {LOCATE_DPS: True},
  163. ):
  164. await self.subject.async_locate()
  165. async def test_async_stop(self):
  166. async with assert_device_properties_set(
  167. self.subject._device,
  168. {COMMAND_DPS: "standby"},
  169. ):
  170. await self.subject.async_stop()
  171. async def test_async_send_smart_command(self):
  172. async with assert_device_properties_set(
  173. self.subject._device,
  174. {COMMAND_DPS: "smart"},
  175. ):
  176. await self.subject.async_send_command("smart")
  177. async def test_async_send_random_command(self):
  178. async with assert_device_properties_set(
  179. self.subject._device,
  180. {COMMAND_DPS: "random"},
  181. ):
  182. await self.subject.async_send_command("random")
  183. async def test_async_send_wall_follow_command(self):
  184. async with assert_device_properties_set(
  185. self.subject._device,
  186. {COMMAND_DPS: "wall_follow"},
  187. ):
  188. await self.subject.async_send_command("wall_follow")
  189. async def test_async_send_reverse_command(self):
  190. async with assert_device_properties_set(
  191. self.subject._device,
  192. {DIRECTION_DPS: "backward"},
  193. ):
  194. await self.subject.async_send_command("reverse")
  195. async def test_async_send_left_command(self):
  196. async with assert_device_properties_set(
  197. self.subject._device,
  198. {DIRECTION_DPS: "turn_left"},
  199. ):
  200. await self.subject.async_send_command("left")
  201. async def test_async_send_right_command(self):
  202. async with assert_device_properties_set(
  203. self.subject._device,
  204. {DIRECTION_DPS: "turn_right"},
  205. ):
  206. await self.subject.async_send_command("right")
  207. async def test_async_send_stop_command(self):
  208. async with assert_device_properties_set(
  209. self.subject._device,
  210. {DIRECTION_DPS: "stop"},
  211. ):
  212. await self.subject.async_send_command("stop")