Преглед изворни кода

vacuum: support new activity property and VacuumActivity enum

New way to return vacuum state introduced in HA 2025.1
This change should avoid the deprecation warnings for the old direct
state returning using constants, which will be removed in 2026.1

Issue #2647
Jason Rumney пре 1 година
родитељ
комит
1320183b69

+ 1 - 1
custom_components/tuya_local/manifest.json

@@ -15,5 +15,5 @@
         "tinytuya==1.16.0",
         "tinytuya==1.16.0",
         "tuya-device-sharing-sdk~=0.2.1"
         "tuya-device-sharing-sdk~=0.2.1"
     ],
     ],
-    "version": "2025.1.0"
+    "version": "2025.1.1"
 }
 }

+ 10 - 15
custom_components/tuya_local/vacuum.py

@@ -6,13 +6,8 @@ from homeassistant.components.vacuum import (
     SERVICE_CLEAN_SPOT,
     SERVICE_CLEAN_SPOT,
     SERVICE_RETURN_TO_BASE,
     SERVICE_RETURN_TO_BASE,
     SERVICE_STOP,
     SERVICE_STOP,
-    STATE_CLEANING,
-    STATE_DOCKED,
-    STATE_ERROR,
-    STATE_IDLE,
-    STATE_PAUSED,
-    STATE_RETURNING,
     StateVacuumEntity,
     StateVacuumEntity,
+    VacuumActivity,
     VacuumEntityFeature,
     VacuumEntityFeature,
 )
 )
 
 
@@ -98,25 +93,25 @@ class TuyaLocalVacuum(TuyaLocalEntity, StateVacuumEntity):
         return self._status_dps.get_value(self._device)
         return self._status_dps.get_value(self._device)
 
 
     @property
     @property
-    def state(self):
+    def activity(self):
         """Return the state of the vacuum cleaner."""
         """Return the state of the vacuum cleaner."""
         status = self.status
         status = self.status
         if self._error_dps and self._error_dps.get_value(self._device):
         if self._error_dps and self._error_dps.get_value(self._device):
-            return STATE_ERROR
+            return VacuumActivity.ERROR
         elif status in [SERVICE_RETURN_TO_BASE, "returning"]:
         elif status in [SERVICE_RETURN_TO_BASE, "returning"]:
-            return STATE_RETURNING
+            return VacuumActivity.RETURNING
         elif status in ["standby", "sleep"]:
         elif status in ["standby", "sleep"]:
-            return STATE_IDLE
+            return VacuumActivity.IDLE
         elif status == "paused":
         elif status == "paused":
-            return STATE_PAUSED
+            return VacuumActivity.PAUSED
         elif status in ["charging", "charged"]:
         elif status in ["charging", "charged"]:
-            return STATE_DOCKED
+            return VacuumActivity.DOCKED
         elif self._power_dps and self._power_dps.get_value(self._device) is False:
         elif self._power_dps and self._power_dps.get_value(self._device) is False:
-            return STATE_IDLE
+            return VacuumActivity.IDLE
         elif self._activate_dps and self._activate_dps.get_value(self._device) is False:
         elif self._activate_dps and self._activate_dps.get_value(self._device) is False:
-            return STATE_PAUSED
+            return VacuumActivity.PAUSED
         else:
         else:
-            return STATE_CLEANING
+            return VacuumActivity.CLEANING
 
 
     async def async_turn_on(self, **kwargs):
     async def async_turn_on(self, **kwargs):
         """Turn on the vacuum cleaner."""
         """Turn on the vacuum cleaner."""

+ 1 - 1
hacs.json

@@ -1,5 +1,5 @@
 {
 {
     "name": "Tuya Local",
     "name": "Tuya Local",
-    "homeassistant": "2024.12.0",
+    "homeassistant": "2025.1.0",
     "hacs": "2.0.0"
     "hacs": "2.0.0"
 }
 }

+ 1 - 1
requirements-dev.txt

@@ -1,6 +1,6 @@
 fuzzywuzzy
 fuzzywuzzy
 levenshtein
 levenshtein
-pytest-homeassistant-custom-component>=0.13.190
+pytest-homeassistant-custom-component>=0.13.201
 pytest
 pytest
 pytest-asyncio
 pytest-asyncio
 pytest-cov
 pytest-cov

+ 8 - 12
tests/devices/test_kyvol_e30_vacuum.py

@@ -1,11 +1,7 @@
 from homeassistant.components.button import ButtonDeviceClass
 from homeassistant.components.button import ButtonDeviceClass
 from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
 from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
 from homeassistant.components.vacuum import (
 from homeassistant.components.vacuum import (
-    STATE_CLEANING,
-    STATE_ERROR,
-    STATE_IDLE,
-    STATE_PAUSED,
-    STATE_RETURNING,
+    VacuumActivity,
     VacuumEntityFeature,
     VacuumEntityFeature,
 )
 )
 from homeassistant.const import PERCENTAGE, UnitOfArea, UnitOfTime
 from homeassistant.const import PERCENTAGE, UnitOfArea, UnitOfTime
@@ -154,23 +150,23 @@ class TestKyvolE30Vacuum(MultiButtonTests, MultiSensorTests, TuyaDeviceTestCase)
         self.dps[COMMAND_DPS] = "spiral"
         self.dps[COMMAND_DPS] = "spiral"
         self.assertEqual(self.subject.status, "clean_spot")
         self.assertEqual(self.subject.status, "clean_spot")
 
 
-    def test_state(self):
+    def test_activity(self):
         self.dps[POWER_DPS] = True
         self.dps[POWER_DPS] = True
         self.dps[SWITCH_DPS] = True
         self.dps[SWITCH_DPS] = True
         self.dps[ERROR_DPS] = 0
         self.dps[ERROR_DPS] = 0
         self.dps[COMMAND_DPS] = "return_to_base"
         self.dps[COMMAND_DPS] = "return_to_base"
-        self.assertEqual(self.subject.state, STATE_RETURNING)
+        self.assertEqual(self.subject.activity, VacuumActivity.RETURNING)
         self.dps[COMMAND_DPS] = "standby"
         self.dps[COMMAND_DPS] = "standby"
-        self.assertEqual(self.subject.state, STATE_IDLE)
+        self.assertEqual(self.subject.activity, VacuumActivity.IDLE)
         self.dps[COMMAND_DPS] = "random"
         self.dps[COMMAND_DPS] = "random"
-        self.assertEqual(self.subject.state, STATE_CLEANING)
+        self.assertEqual(self.subject.activity, VacuumActivity.CLEANING)
         self.dps[POWER_DPS] = False
         self.dps[POWER_DPS] = False
-        self.assertEqual(self.subject.state, STATE_IDLE)
+        self.assertEqual(self.subject.activity, VacuumActivity.IDLE)
         self.dps[POWER_DPS] = True
         self.dps[POWER_DPS] = True
         self.dps[SWITCH_DPS] = False
         self.dps[SWITCH_DPS] = False
-        self.assertEqual(self.subject.state, STATE_PAUSED)
+        self.assertEqual(self.subject.activity, VacuumActivity.PAUSED)
         self.dps[ERROR_DPS] = 1
         self.dps[ERROR_DPS] = 1
-        self.assertEqual(self.subject.state, STATE_ERROR)
+        self.assertEqual(self.subject.activity, VacuumActivity.ERROR)
 
 
     async def test_async_turn_on(self):
     async def test_async_turn_on(self):
         async with assert_device_properties_set(
         async with assert_device_properties_set(

+ 8 - 12
tests/devices/test_lefant_m213_vacuum.py

@@ -1,10 +1,6 @@
 from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
 from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
 from homeassistant.components.vacuum import (
 from homeassistant.components.vacuum import (
-    STATE_CLEANING,
-    STATE_ERROR,
-    STATE_IDLE,
-    STATE_PAUSED,
-    STATE_RETURNING,
+    VacuumActivity,
     VacuumEntityFeature,
     VacuumEntityFeature,
 )
 )
 from homeassistant.const import PERCENTAGE, UnitOfArea, UnitOfTime
 from homeassistant.const import PERCENTAGE, UnitOfArea, UnitOfTime
@@ -110,23 +106,23 @@ class TestLefantM213Vacuum(MultiSensorTests, TuyaDeviceTestCase):
         self.dps[STATUS_DPS] = "7"
         self.dps[STATUS_DPS] = "7"
         self.assertEqual(self.subject.status, "standby")
         self.assertEqual(self.subject.status, "standby")
 
 
-    def test_state(self):
+    def test_activity(self):
         self.dps[POWER_DPS] = True
         self.dps[POWER_DPS] = True
         self.dps[SWITCH_DPS] = True
         self.dps[SWITCH_DPS] = True
         self.dps[ERROR_DPS] = 0
         self.dps[ERROR_DPS] = 0
         self.dps[STATUS_DPS] = "4"
         self.dps[STATUS_DPS] = "4"
-        self.assertEqual(self.subject.state, STATE_RETURNING)
+        self.assertEqual(self.subject.activity, VacuumActivity.RETURNING)
         self.dps[STATUS_DPS] = "7"
         self.dps[STATUS_DPS] = "7"
-        self.assertEqual(self.subject.state, STATE_IDLE)
+        self.assertEqual(self.subject.activity, VacuumActivity.IDLE)
         self.dps[STATUS_DPS] = "6"
         self.dps[STATUS_DPS] = "6"
-        self.assertEqual(self.subject.state, STATE_CLEANING)
+        self.assertEqual(self.subject.activity, VacuumActivity.CLEANING)
         self.dps[POWER_DPS] = False
         self.dps[POWER_DPS] = False
-        self.assertEqual(self.subject.state, STATE_IDLE)
+        self.assertEqual(self.subject.activity, VacuumActivity.IDLE)
         self.dps[POWER_DPS] = True
         self.dps[POWER_DPS] = True
         self.dps[SWITCH_DPS] = False
         self.dps[SWITCH_DPS] = False
-        self.assertEqual(self.subject.state, STATE_PAUSED)
+        self.assertEqual(self.subject.activity, VacuumActivity.PAUSED)
         self.dps[ERROR_DPS] = 1
         self.dps[ERROR_DPS] = 1
-        self.assertEqual(self.subject.state, STATE_ERROR)
+        self.assertEqual(self.subject.activity, VacuumActivity.ERROR)
 
 
     async def test_async_turn_on(self):
     async def test_async_turn_on(self):
         async with assert_device_properties_set(
         async with assert_device_properties_set(