test_lefant_m213_vacuum.py 8.3 KB

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