Skip to content

Commit

Permalink
fix: invalid any function call, make async call for check
Browse files Browse the repository at this point in the history
  • Loading branch information
duhow committed Jul 14, 2024
1 parent 964fed9 commit 4c1d9be
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions custom_components/cover_time_based/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ async def _handle_state_changed(self, event):

# Set unavailable if any of the switches becomes unavailable
self._attr_available = not any(
self._open_switch_state == STATE_UNAVAILABLE,
self._close_switch_state == STATE_UNAVAILABLE,
[
self._open_switch_state == STATE_UNAVAILABLE,
self._close_switch_state == STATE_UNAVAILABLE,
]
)

# Handle new status
Expand Down Expand Up @@ -246,19 +248,19 @@ def assumed_state(self):
"""Return True because covers can be stopped midway."""
return True

def check_availability(self) -> bool:
async def check_availability(self) -> None:
"""Check if any of the entities is unavailable and update status."""
for entity in [self._close_switch_entity_id, self._open_switch_entity_id]:
state = self.hass.states.get(entity).state
if state in [STATE_UNAVAILABLE, STATE_UNKNOWN]:
state = self.hass.states.get(entity)
if state.state in [STATE_UNAVAILABLE, STATE_UNKNOWN]:
self._attr_available = False
return
self._attr_available = True

async def async_set_cover_position(self, **kwargs):
"""Move the cover to a specific position."""
if ATTR_POSITION in kwargs:
self.check_availability()
await self.check_availability()
if not self.available:
return
position = kwargs[ATTR_POSITION]
Expand All @@ -268,7 +270,7 @@ async def async_set_cover_position(self, **kwargs):
async def async_close_cover(self, **kwargs):
"""Turn the device close."""
_LOGGER.debug("async_close_cover")
self.check_availability()
await self.check_availability()
if not self.available:
return
if kwargs.get("handle_command") is not False:
Expand All @@ -279,7 +281,7 @@ async def async_close_cover(self, **kwargs):
async def async_open_cover(self, **kwargs):
"""Turn the device open."""
_LOGGER.debug("async_open_cover")
self.check_availability()
await self.check_availability()
if not self.available:
return
if kwargs.get("handle_command") is not False:
Expand All @@ -290,7 +292,7 @@ async def async_open_cover(self, **kwargs):
async def async_stop_cover(self, **kwargs):
"""Turn the device stop."""
_LOGGER.debug("async_stop_cover")
self.check_availability()
await self.check_availability()
if not self.available:
return
await self._async_handle_command(SERVICE_STOP_COVER)
Expand Down

0 comments on commit 4c1d9be

Please sign in to comment.