Explorar o código

Add test for vacuum stop command.

- add tests for STOP in supported_features, and the async_stop method.
- satisfy black by removing extra whitespace

Related to PR #588

- add test for climate precision to owon device to check it works as expected

Issue #587
Jason Rumney %!s(int64=2) %!d(string=hai) anos
pai
achega
cb0c25a3a2

+ 1 - 1
custom_components/tuya_local/vacuum.py

@@ -165,7 +165,7 @@ class TuyaLocalVacuum(TuyaLocalEntity, StateVacuumEntity):
         dps = self._command_dps or self._status_dps
         if dps and SERVICE_CLEAN_SPOT in dps.values(self._device):
             await dps.async_set_value(self._device, SERVICE_CLEAN_SPOT)
-        
+
     async def async_stop(self, **kwargs):
         """Tell the vacuum cleaner to stop."""
         dps = self._command_dps or self._status_dps

+ 11 - 0
tests/const.py

@@ -1570,3 +1570,14 @@ GX_AROMA_PAYLOAD = {
     "8": "b9fff500ab46ff",
     "9": 0,
 }
+
+MOEBOT_PAYLOAD = {
+    "6": 41,
+    "101": "MOWING",
+    "102": 0,
+    "103": "MOWER_LEAN",
+    "104": True,
+    "105": 8,
+    "106": 1343,
+    "114": "AutoMode",
+}

+ 68 - 0
tests/devices/test_moebot.py

@@ -0,0 +1,68 @@
+"""
+Test MoeBot S mower.
+Primarily for testing the STOP command which this device is the first to use.
+"""
+from homeassistant.components.vacuum import VacuumEntityFeature
+
+from ..const import MOEBOT_PAYLOAD
+from ..helpers import assert_device_properties_set
+from .base_device_tests import TuyaDeviceTestCase
+
+BATTERY_DP = "6"
+STATUS_DP = "101"
+ERROR_DP = "102"
+PROBLEM_DP = "103"
+RAINMODE_DP = "104"
+RUNTIME_DP = "105"
+PASSWD_DP = "106"
+CLEARSCHED_DP = "107"
+QUERYSCHED_DP = "108"
+QUERYZONE_DP = "109"
+SCHEDULE_DP = "110"
+ERRLOG_DP = "111"
+WORKLOG_DP = "112"
+ZONES_DP = "113"
+AUTOMODE_DP = "114"
+COMMAND_DP = "115"
+
+
+class TestMoebot(TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig("moebot_s_mower.yaml", MOEBOT_PAYLOAD)
+        self.subject = self.entities.get("vacuum")
+        self.mark_secondary(
+            [
+                "binary_sensor_error",
+                "sensor_problem",
+                "switch_rain_mode",
+                "number_running_time",
+                "button_clear_schedule",
+                "button_query_schedule",
+                "button_query_zones",
+            ]
+        )
+
+    def test_supported_features(self):
+        self.assertEqual(
+            self.subject.supported_features,
+            (
+                VacuumEntityFeature.BATTERY
+                | VacuumEntityFeature.CLEAN_SPOT
+                | VacuumEntityFeature.PAUSE
+                | VacuumEntityFeature.RETURN_HOME
+                | VacuumEntityFeature.SEND_COMMAND
+                | VacuumEntityFeature.START
+                | VacuumEntityFeature.STATE
+                | VacuumEntityFeature.STATUS
+                | VacuumEntityFeature.STOP
+            ),
+        )
+
+    async def test_async_stop(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {COMMAND_DP: "CancelWork"},
+        ):
+            await self.subject.async_stop()

+ 3 - 0
tests/devices/test_owon_pct513_thermostat.py

@@ -79,6 +79,9 @@ class TestOwonPCT513Thermostat(
         self.dps[UNIT_DPS] = "f"
         self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.FAHRENHEIT)
 
+    def test_precision(self):
+        self.assertAlmostEqual(self.subject.precision, 0.01, 2)
+
     def test_current_temperature(self):
         self.dps[UNIT_DPS] = "c"
         self.dps[CURRENTTEMP_DPS] = 2100