4
0

test_moebot.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 ..const import MOEBOT_PAYLOAD
  11. from ..helpers import assert_device_properties_set
  12. from .base_device_tests import TuyaDeviceTestCase
  13. BATTERY_DP = "6"
  14. STATUS_DP = "101"
  15. ERROR_DP = "102"
  16. PROBLEM_DP = "103"
  17. RAINMODE_DP = "104"
  18. RUNTIME_DP = "105"
  19. PASSWD_DP = "106"
  20. CLEARSCHED_DP = "107"
  21. QUERYSCHED_DP = "108"
  22. QUERYZONE_DP = "109"
  23. SCHEDULE_DP = "110"
  24. ERRLOG_DP = "111"
  25. WORKLOG_DP = "112"
  26. ZONES_DP = "113"
  27. AUTOMODE_DP = "114"
  28. COMMAND_DP = "115"
  29. class TestMoebot(TuyaDeviceTestCase):
  30. __test__ = True
  31. def setUp(self):
  32. self.setUpForConfig("moebot_s_mower.yaml", MOEBOT_PAYLOAD)
  33. self.mower = self.entities.get("lawn_mower")
  34. self.start_button = self.entities.get("button_start_fixed_mowing")
  35. self.mark_secondary(
  36. [
  37. "binary_sensor_cover",
  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.mower.supported_features,
  51. (
  52. LawnMowerEntityFeature.START_MOWING
  53. | LawnMowerEntityFeature.PAUSE
  54. | LawnMowerEntityFeature.DOCK
  55. ),
  56. )
  57. def test_lawnmower_activity(self):
  58. self.dps[STATUS_DP] = "ERROR"
  59. self.assertEqual(self.mower.activity, LawnMowerActivity.ERROR)
  60. self.dps[STATUS_DP] = "EMERGENCY"
  61. self.assertEqual(self.mower.activity, LawnMowerActivity.ERROR)
  62. self.dps[STATUS_DP] = "PAUSED"
  63. self.assertEqual(self.mower.activity, LawnMowerActivity.PAUSED)
  64. self.dps[STATUS_DP] = "PARK"
  65. self.assertEqual(self.mower.activity, LawnMowerActivity.RETURNING)
  66. self.dps[STATUS_DP] = "MOWING"
  67. self.assertEqual(self.mower.activity, LawnMowerActivity.MOWING)
  68. self.dps[STATUS_DP] = "FIXED_MOWING"
  69. self.assertEqual(self.mower.activity, LawnMowerActivity.MOWING)
  70. self.dps[STATUS_DP] = "STANDBY"
  71. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  72. self.dps[STATUS_DP] = "CHARGING"
  73. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  74. self.dps[STATUS_DP] = "LOCKED"
  75. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  76. self.dps[STATUS_DP] = "CHARGING_WITH_TASK_SUSPEND"
  77. self.assertEqual(self.mower.activity, LawnMowerActivity.DOCKED)
  78. async def test_async_start_mowing(self):
  79. async with assert_device_properties_set(
  80. self.mower._device,
  81. {COMMAND_DP: "StartMowing"},
  82. ):
  83. await self.mower.async_start_mowing()
  84. async def test_async_start_fixed_mowing(self):
  85. async with assert_device_properties_set(
  86. self.start_button._device,
  87. {COMMAND_DP: "StartFixedMowing"},
  88. ):
  89. await self.start_button.async_press()
  90. async def test_async_pause(self):
  91. async with assert_device_properties_set(
  92. self.mower._device,
  93. {COMMAND_DP: "PauseWork"},
  94. ):
  95. await self.mower.async_pause()
  96. async def test_async_dock(self):
  97. async with assert_device_properties_set(
  98. self.mower._device,
  99. {COMMAND_DP: "StartReturnStation"},
  100. ):
  101. await self.mower.async_dock()