test_moebot.py 4.1 KB

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