test_moebot.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_problem",
  39. "select_mowing_mode",
  40. "sensor_problem",
  41. "switch_rain_mode",
  42. "number_running_time",
  43. "button_clear_schedule",
  44. "button_query_schedule",
  45. "button_query_zones",
  46. ]
  47. )
  48. def test_supported_features(self):
  49. self.assertEqual(
  50. self.subject.supported_features,
  51. (
  52. VacuumEntityFeature.CLEAN_SPOT
  53. | VacuumEntityFeature.PAUSE
  54. | VacuumEntityFeature.RETURN_HOME
  55. | VacuumEntityFeature.SEND_COMMAND
  56. | VacuumEntityFeature.START
  57. | VacuumEntityFeature.STATE
  58. | VacuumEntityFeature.STATUS
  59. | VacuumEntityFeature.STOP
  60. ),
  61. )
  62. self.assertEqual(
  63. self.mower.supported_features,
  64. (
  65. LawnMowerEntityFeature.START_MOWING
  66. | LawnMowerEntityFeature.PAUSE
  67. | LawnMowerEntityFeature.DOCK
  68. ),
  69. )
  70. async def test_async_stop(self):
  71. async with assert_device_properties_set(
  72. self.subject._device,
  73. {COMMAND_DP: "CancelWork"},
  74. ):
  75. await self.subject.async_stop()
  76. def test_lawnmower_activity(self):
  77. self.dps[STATUS_DP] = "ERROR"
  78. self.assertEqual(self.mower.activity, LawnMowerActivity.ERROR)
  79. self.dps[STATUS_DP] = "EMERGENCY"
  80. self.assertEqual(self.mower.activity, LawnMowerActivity.ERROR)
  81. self.dps[STATUS_DP] = "PAUSED"
  82. self.assertEqual(self.mower.activity, LawnMowerActivity.PAUSED)
  83. self.dps[STATUS_DP] = "PARK"
  84. self.assertEqual(self.mower.activity, LawnMowerActivity.PAUSED)
  85. self.dps[STATUS_DP] = "MOWING"
  86. self.assertEqual(self.mower.activity, LawnMowerActivity.MOWING)
  87. self.dps[STATUS_DP] = "FIXED_MOWING"
  88. self.assertEqual(self.mower.activity, LawnMowerActivity.MOWING)
  89. self.dps[STATUS_DP] = "STANDBY"
  90. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  91. self.dps[STATUS_DP] = "CHARGING"
  92. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  93. self.dps[STATUS_DP] = "LOCKED"
  94. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  95. self.dps[STATUS_DP] = "CHARGING_WITH_TASK_SUSPEND"
  96. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  97. async def test_async_start_mowing(self):
  98. async with assert_device_properties_set(
  99. self.mower._device,
  100. {COMMAND_DP: "StartMowing"},
  101. ):
  102. await self.mower.async_start_mowing()
  103. async def test_async_pause(self):
  104. async with assert_device_properties_set(
  105. self.mower._device,
  106. {COMMAND_DP: "PauseWork"},
  107. ):
  108. await self.mower.async_pause()
  109. async def test_async_dock(self):
  110. async with assert_device_properties_set(
  111. self.mower._device,
  112. {COMMAND_DP: "StartReturnStation"},
  113. ):
  114. await self.mower.async_dock()