Fix fibaro cover state is not always correct (#131206)

This commit is contained in:
rappenze 2024-11-21 21:16:37 +01:00 committed by GitHub
parent 7e752c051f
commit c6c7e86548
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -69,37 +69,29 @@ class FibaroCover(FibaroEntity, CoverEntity):
# so if it is missing we have a device which supports open / close only # so if it is missing we have a device which supports open / close only
return not self.fibaro_device.value.has_value return not self.fibaro_device.value.has_value
@property def update(self) -> None:
def current_cover_position(self) -> int | None: """Update the state."""
"""Return current position of cover. 0 is closed, 100 is open.""" super().update()
return self.bound(self.level)
@property self._attr_current_cover_position = self.bound(self.level)
def current_cover_tilt_position(self) -> int | None: self._attr_current_cover_tilt_position = self.bound(self.level2)
"""Return the current tilt position for venetian blinds."""
return self.bound(self.level2)
@property device_state = self.fibaro_device.state
def is_opening(self) -> bool | None:
"""Return if the cover is opening or not.
Be aware that this property is only available for some modern devices. # Be aware that opening and closing is only available for some modern
For example the Fibaro Roller Shutter 4 reports this correctly. # devices.
""" # For example the Fibaro Roller Shutter 4 reports this correctly.
if self.fibaro_device.state.has_value: if device_state.has_value:
return self.fibaro_device.state.str_value().lower() == "opening" self._attr_is_opening = device_state.str_value().lower() == "opening"
return None self._attr_is_closing = device_state.str_value().lower() == "closing"
@property closed: bool | None = None
def is_closing(self) -> bool | None: if self._is_open_close_only():
"""Return if the cover is closing or not. if device_state.has_value and device_state.str_value().lower() != "unknown":
closed = device_state.str_value().lower() == "closed"
Be aware that this property is only available for some modern devices. elif self.current_cover_position is not None:
For example the Fibaro Roller Shutter 4 reports this correctly. closed = self.current_cover_position == 0
""" self._attr_is_closed = closed
if self.fibaro_device.state.has_value:
return self.fibaro_device.state.str_value().lower() == "closing"
return None
def set_cover_position(self, **kwargs: Any) -> None: def set_cover_position(self, **kwargs: Any) -> None:
"""Move the cover to a specific position.""" """Move the cover to a specific position."""
@ -109,19 +101,6 @@ class FibaroCover(FibaroEntity, CoverEntity):
"""Move the cover to a specific position.""" """Move the cover to a specific position."""
self.set_level2(cast(int, kwargs.get(ATTR_TILT_POSITION))) self.set_level2(cast(int, kwargs.get(ATTR_TILT_POSITION)))
@property
def is_closed(self) -> bool | None:
"""Return if the cover is closed."""
if self._is_open_close_only():
state = self.fibaro_device.state
if not state.has_value or state.str_value().lower() == "unknown":
return None
return state.str_value().lower() == "closed"
if self.current_cover_position is None:
return None
return self.current_cover_position == 0
def open_cover(self, **kwargs: Any) -> None: def open_cover(self, **kwargs: Any) -> None:
"""Open the cover.""" """Open the cover."""
self.action("open") self.action("open")