Explorar o código

cover: don't return False from is_closed when state unknown

When the dp is insuffient to determine whether the curtain is closed or not,
return None rather than False from is_closed.  Otherwise curtains get stuck
in an open state.
Jason Rumney %!s(int64=3) %!d(string=hai) anos
pai
achega
6790a71fae
Modificáronse 1 ficheiros con 7 adicións e 3 borrados
  1. 7 3
      custom_components/tuya_local/generic/cover.py

+ 7 - 3
custom_components/tuya_local/generic/cover.py

@@ -124,13 +124,17 @@ class TuyaLocalCover(TuyaLocalEntity, CoverEntity):
         if self._control_dp:
         if self._control_dp:
             return (
             return (
                 self._control_dp.get_value(self._device) == "close"
                 self._control_dp.get_value(self._device) == "close"
-                and not self.is_closed
+                and self.is_closed is False
             )
             )
 
 
     @property
     @property
     def is_closed(self):
     def is_closed(self):
-        """Return if the cover is closed or not."""
-        return self.current_cover_position == 0
+        """Return if the cover is closed or not, if it can be determined."""
+        # Only use position if it is reliable, otherwise curtain can become
+        # stuck in "open" state when we don't actually know what state it is.
+        pos = self.current_cover_position
+        if isinstance(pos, int):
+            return pos == 0
 
 
     async def async_open_cover(self, **kwargs):
     async def async_open_cover(self, **kwargs):
         """Open the cover."""
         """Open the cover."""