Просмотр исходного кода

Implement hidden and readonly dps options.

Hidden is used only for the eco_temperature for GPPH heater, as that will be redirected when the preset is ECO.
Readonly is tagged on a number of dps, but probably none that have methods to set them.
Jason Rumney 4 лет назад
Родитель
Сommit
63e12fb12b

+ 1 - 1
custom_components/tuya_local/generic/climate.py

@@ -80,7 +80,7 @@ class TuyaLocalClimate(ClimateEntity):
                 self._support_flags |= SUPPORT_FAN_MODE
             elif d.name == "temperature_unit":
                 self._unit_dps = d
-            else:
+            elif not d.hidden:
                 self._attr_dps.append(d)
 
     @property

+ 1 - 1
custom_components/tuya_local/generic/light.py

@@ -25,7 +25,7 @@ class TuyaLocalLight(LightEntity):
         for d in config.dps():
             if d.name == "switch":
                 self._switch_dps = d
-            else:
+            elif not d.hidden:
                 self._attr_dps.append(d)
 
     @property

+ 1 - 1
custom_components/tuya_local/generic/lock.py

@@ -27,7 +27,7 @@ class TuyaLocalLock(LockEntity):
         for d in config.dps():
             if d.name == "lock":
                 self._lock_dps = d
-            else:
+            elif not d.hidden:
                 self._attr_dps.append(d)
 
     @property

+ 2 - 1
custom_components/tuya_local/generic/switch.py

@@ -34,7 +34,8 @@ class TuyaLocalSwitch(SwitchEntity):
             else:
                 if d.name == "current_power_w":
                     self._power_dps = d
-                self._attr_dps.append(d)
+                if not d.hidden:
+                    self._attr_dps.append(d)
 
     @property
     def should_poll(self):

+ 11 - 5
custom_components/tuya_local/helpers/device_config.py

@@ -175,11 +175,13 @@ class TuyaDpsConfig:
 
     def get_value(self, device):
         """Return the value of the dps from the given device."""
-        return self.map_from_dps(device.get_property(self.id), device)
+        return self._map_from_dps(device.get_property(self.id), device)
 
     async def async_set_value(self, device, value):
         """Set the value of the dps in the given device to given value."""
-        await device.async_set_property(self.id, self.map_to_dps(value, device))
+        if self.readonly:
+            raise TypeError(f"{self.name} is read only")
+        await device.async_set_property(self.id, self._map_to_dps(value, device))
 
     @property
     def values(self):
@@ -210,10 +212,14 @@ class TuyaDpsConfig:
             return None
 
     @property
-    def isreadonly(self):
+    def readonly(self):
         return "readonly" in self._config.keys() and self._config["readonly"] is True
 
-    def map_from_dps(self, value, device):
+    @property
+    def hidden(self):
+        return "hidden" in self._config.keys() and self._config["hidden"] is True
+
+    def _map_from_dps(self, value, device):
         result = value
         replaced = False
         default_value = None
@@ -262,7 +268,7 @@ class TuyaDpsConfig:
 
         return result
 
-    def map_to_dps(self, value, device):
+    def _map_to_dps(self, value, device):
         result = value
         replaced = False
         scale = 1

+ 0 - 1
tests/devices/test_goldair_dehumidifier.py

@@ -401,7 +401,6 @@ class TestGoldairDehumidifier(IsolatedAsyncioTestCase):
 
         self.assertEqual(self.subject.fan_mode, FAN_LOW)
 
-    @skip("Conditions not supported yet")
     def test_fan_mode_reflects_dps_mode_in_normal_preset(self):
         self.dps[PRESET_DPS] = PRESET_NORMAL
         self.dps[FANMODE_DPS] = "1"

+ 0 - 1
tests/devices/test_goldair_gpph_heater.py

@@ -362,7 +362,6 @@ class TestGoldairHeater(IsolatedAsyncioTestCase):
         with self.assertRaisesRegex(ValueError, "Invalid power level: unknown"):
             await self.subject.async_set_swing_mode("unknown")
 
-    @skip("Hidden dps not supported yet")
     def test_device_state_attributes(self):
         self.dps[ERROR_DPS] = "something"
         self.dps[TIMER_DPS] = 5