Przeglądaj źródła

cover: remove special handling of reversed dp.

When this was added, I thought that this dp would indicate when the position
should be flipped.  But now that a few more covers have been implemented, it
is clear that Tuya's idea of position is always the reverse of HA's, and this
is just a switch for the motor direction which doesn't affect position
reporting.

Update configs that used this to always invert positions.
Jason Rumney 2 lat temu
rodzic
commit
4d509758ab

+ 4 - 14
custom_components/tuya_local/cover.py

@@ -43,7 +43,6 @@ class TuyaLocalCover(TuyaLocalEntity, CoverEntity):
         self._control_dp = dps_map.pop("control", None)
         self._action_dp = dps_map.pop("action", None)
         self._open_dp = dps_map.pop("open", None)
-        self._reversed_dp = dps_map.pop("reversed", None)
         self._init_end(dps_map)
 
         self._support_flags = 0
@@ -58,14 +57,6 @@ class TuyaLocalCover(TuyaLocalEntity, CoverEntity):
                 self._support_flags |= CoverEntityFeature.CLOSE
         # Tilt not yet supported, as no test devices known
 
-    @property
-    def _is_reversed(self):
-        return self._reversed_dp and self._reversed_dp.get_value(self._device)
-
-    def _maybe_reverse(self, percent):
-        """Reverse the percentage if it should be, otherwise leave it alone"""
-        return 100 - percent if self._is_reversed else percent
-
     @property
     def device_class(self):
         """Return the class of ths device"""
@@ -97,11 +88,11 @@ class TuyaLocalCover(TuyaLocalEntity, CoverEntity):
         if self._currentpos_dp:
             pos = self._currentpos_dp.get_value(self._device)
             if pos is not None:
-                return self._maybe_reverse(pos)
+                return pos
 
         if self._position_dp:
             pos = self._position_dp.get_value(self._device)
-            return self._maybe_reverse(pos)
+            return pos
 
         if self._open_dp:
             state = self._open_dp.get_value(self._device)
@@ -160,7 +151,7 @@ class TuyaLocalCover(TuyaLocalEntity, CoverEntity):
         if self._control_dp and "open" in self._control_dp.values(self._device):
             await self._control_dp.async_set_value(self._device, "open")
         elif self._position_dp:
-            pos = self._maybe_reverse(100)
+            pos = 100
             await self._position_dp.async_set_value(self._device, pos)
         else:
             raise NotImplementedError()
@@ -170,7 +161,7 @@ class TuyaLocalCover(TuyaLocalEntity, CoverEntity):
         if self._control_dp and "close" in self._control_dp.values(self._device):
             await self._control_dp.async_set_value(self._device, "close")
         elif self._position_dp:
-            pos = self._maybe_reverse(0)
+            pos = 0
             await self._position_dp.async_set_value(self._device, pos)
         else:
             raise NotImplementedError()
@@ -180,7 +171,6 @@ class TuyaLocalCover(TuyaLocalEntity, CoverEntity):
         if position is None:
             raise AttributeError()
         if self._position_dp:
-            position = self._maybe_reverse(position)
             await self._position_dp.async_set_value(self._device, position)
         else:
             raise NotImplementedError()

+ 1 - 3
custom_components/tuya_local/devices/benexmart_blind_motor.yaml

@@ -19,9 +19,7 @@ primary_entity:
       range:
         min: 0
         max: 100
-    - id: 5
-      type: boolean
-      name: reversed
+      invert: true
 secondary_entities:
     - entity: switch
       category: config

+ 5 - 13
custom_components/tuya_local/devices/wistar_roller_blind.yaml

@@ -21,14 +21,7 @@ primary_entity:
       range:
         min: 0
         max: 100
-    - id: 103
-      type: boolean
-      name: reversed
-      mapping:
-        - dps_val: true
-          value: false
-        - dps_val: false
-          value: true
+      invert: true
     - id: 105
       type: boolean
       name: curtain_hand
@@ -83,6 +76,10 @@ primary_entity:
     - id: 112
       type: integer
       name: current_position
+      range:
+        min: 0
+        max: 100
+      invert: true
 secondary_entities:
   - entity: select
     name: Border setting
@@ -144,8 +141,3 @@ secondary_entities:
       - id: 103
         type: boolean
         name: switch
-        mapping:
-          - dps_val: true
-            value: false
-          - dps_val: false
-            value: true

+ 1 - 13
custom_components/tuya_local/devices/wistar_roller_blind_nopos.yaml

@@ -21,14 +21,7 @@ primary_entity:
       range:
         min: 0
         max: 100
-    - id: 103
-      type: boolean
-      name: reversed
-      mapping:
-        - dps_val: true
-          value: false
-        - dps_val: false
-          value: true
+      invert: true
     - id: 105
       type: boolean
       name: curtain_hand
@@ -144,8 +137,3 @@ secondary_entities:
       - id: 103
         type: boolean
         name: switch
-        mapping:
-          - dps_val: true
-            value: false
-          - dps_val: false
-            value: true