test_moebot.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. """
  2. Test MoeBot S mower.
  3. Primarily for testing the STOP command which this device is the first to use,
  4. and the lawn_mower platform.
  5. """
  6. from homeassistant.components.lawn_mower.const import (
  7. LawnMowerActivity,
  8. LawnMowerEntityFeature,
  9. )
  10. from homeassistant.components.vacuum import VacuumEntityFeature
  11. from ..const import MOEBOT_PAYLOAD
  12. from ..helpers import assert_device_properties_set
  13. from .base_device_tests import TuyaDeviceTestCase
  14. BATTERY_DP = "6"
  15. STATUS_DP = "101"
  16. ERROR_DP = "102"
  17. PROBLEM_DP = "103"
  18. RAINMODE_DP = "104"
  19. RUNTIME_DP = "105"
  20. PASSWD_DP = "106"
  21. CLEARSCHED_DP = "107"
  22. QUERYSCHED_DP = "108"
  23. QUERYZONE_DP = "109"
  24. SCHEDULE_DP = "110"
  25. ERRLOG_DP = "111"
  26. WORKLOG_DP = "112"
  27. ZONES_DP = "113"
  28. AUTOMODE_DP = "114"
  29. COMMAND_DP = "115"
  30. class TestMoebot(TuyaDeviceTestCase):
  31. __test__ = True
  32. def setUp(self):
  33. self.setUpForConfig("moebot_s_mower.yaml", MOEBOT_PAYLOAD)
  34. self.subject = self.entities.get("vacuum")
  35. self.mower = self.entities.get("lawn_mower")
  36. self.mark_secondary(
  37. [
  38. "binary_sensor_cover",
  39. "binary_sensor_problem",
  40. "select_mowing_mode",
  41. "sensor_problem",
  42. "switch_rain_mode",
  43. "number_running_time",
  44. "button_clear_schedule",
  45. "button_query_schedule",
  46. "button_query_zones",
  47. ]
  48. )
  49. def test_supported_features(self):
  50. self.assertEqual(
  51. self.subject.supported_features,
  52. (
  53. VacuumEntityFeature.CLEAN_SPOT
  54. | VacuumEntityFeature.PAUSE
  55. | VacuumEntityFeature.RETURN_HOME
  56. | VacuumEntityFeature.SEND_COMMAND
  57. | VacuumEntityFeature.START
  58. | VacuumEntityFeature.STATE
  59. | VacuumEntityFeature.STATUS
  60. | VacuumEntityFeature.STOP
  61. ),
  62. )
  63. self.assertEqual(
  64. self.mower.supported_features,
  65. (
  66. LawnMowerEntityFeature.START_MOWING
  67. | LawnMowerEntityFeature.PAUSE
  68. | LawnMowerEntityFeature.DOCK
  69. ),
  70. )
  71. async def test_async_stop(self):
  72. async with assert_device_properties_set(
  73. self.subject._device,
  74. {COMMAND_DP: "CancelWork"},
  75. ):
  76. await self.subject.async_stop()
  77. def test_lawnmower_activity(self):
  78. self.dps[STATUS_DP] = "ERROR"
  79. self.assertEqual(self.mower.activity, LawnMowerActivity.ERROR)
  80. self.dps[STATUS_DP] = "EMERGENCY"
  81. self.assertEqual(self.mower.activity, LawnMowerActivity.ERROR)
  82. self.dps[STATUS_DP] = "PAUSED"
  83. self.assertEqual(self.mower.activity, LawnMowerActivity.PAUSED)
  84. self.dps[STATUS_DP] = "PARK"
  85. self.assertEqual(self.mower.activity, LawnMowerActivity.PAUSED)
  86. self.dps[STATUS_DP] = "MOWING"
  87. self.assertEqual(self.mower.activity, LawnMowerActivity.MOWING)
  88. self.dps[STATUS_DP] = "FIXED_MOWING"
  89. self.assertEqual(self.mower.activity, LawnMowerActivity.MOWING)
  90. self.dps[STATUS_DP] = "STANDBY"
  91. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  92. self.dps[STATUS_DP] = "CHARGING"
  93. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  94. self.dps[STATUS_DP] = "LOCKED"
  95. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  96. self.dps[STATUS_DP] = "CHARGING_WITH_TASK_SUSPEND"
  97. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  98. async def test_async_start_mowing(self):
  99. async with assert_device_properties_set(
  100. self.mower._device,
  101. {COMMAND_DP: "StartMowing"},
  102. ):
  103. await self.mower.async_start_mowing()
  104. async def test_async_pause(self):
  105. async with assert_device_properties_set(
  106. self.mower._device,
  107. {COMMAND_DP: "PauseWork"},
  108. ):
  109. await self.mower.async_pause()
  110. async def test_async_dock(self):
  111. async with assert_device_properties_set(
  112. self.mower._device,
  113. {COMMAND_DP: "StartReturnStation"},
  114. ):
  115. await self.mower.async_dock()