Skip to content

Commit

Permalink
Fix fibaro cover state is not always correct (#131206)
Browse files Browse the repository at this point in the history
  • Loading branch information
rappenze authored and frenck committed Nov 22, 2024
1 parent 44ad808 commit 2f05240
Showing 1 changed file with 23 additions and 44 deletions.
67 changes: 23 additions & 44 deletions homeassistant/components/fibaro/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,29 @@ def _is_open_close_only(self) -> bool:
# so if it is missing we have a device which supports open / close only
return not self.fibaro_device.value.has_value

@property
def current_cover_position(self) -> int | None:
"""Return current position of cover. 0 is closed, 100 is open."""
return self.bound(self.level)

@property
def current_cover_tilt_position(self) -> int | None:
"""Return the current tilt position for venetian blinds."""
return self.bound(self.level2)

@property
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.
For example the Fibaro Roller Shutter 4 reports this correctly.
"""
if self.fibaro_device.state.has_value:
return self.fibaro_device.state.str_value().lower() == "opening"
return None

@property
def is_closing(self) -> bool | None:
"""Return if the cover is closing or not.
Be aware that this property is only available for some modern devices.
For example the Fibaro Roller Shutter 4 reports this correctly.
"""
if self.fibaro_device.state.has_value:
return self.fibaro_device.state.str_value().lower() == "closing"
return None
def update(self) -> None:
"""Update the state."""
super().update()

self._attr_current_cover_position = self.bound(self.level)
self._attr_current_cover_tilt_position = self.bound(self.level2)

device_state = self.fibaro_device.state

# Be aware that opening and closing is only available for some modern
# devices.
# For example the Fibaro Roller Shutter 4 reports this correctly.
if device_state.has_value:
self._attr_is_opening = device_state.str_value().lower() == "opening"
self._attr_is_closing = device_state.str_value().lower() == "closing"

closed: bool | None = None
if self._is_open_close_only():
if device_state.has_value and device_state.str_value().lower() != "unknown":
closed = device_state.str_value().lower() == "closed"
elif self.current_cover_position is not None:
closed = self.current_cover_position == 0
self._attr_is_closed = closed

def set_cover_position(self, **kwargs: Any) -> None:
"""Move the cover to a specific position."""
Expand All @@ -109,19 +101,6 @@ def set_cover_tilt_position(self, **kwargs: Any) -> None:
"""Move the cover to a specific 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:
"""Open the cover."""
self.action("open")
Expand Down

0 comments on commit 2f05240

Please sign in to comment.