Skip to content

Commit

Permalink
Improve startup speed and 1st update detection
Browse files Browse the repository at this point in the history
  • Loading branch information
monty68 committed Dec 7, 2023
1 parent ae44473 commit 195ead1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 5 additions & 3 deletions custom_components/uniled/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ async def _async_update(self) -> None:
ConfigEntryState.SETUP_RETRY,
)

_LOGGER.debug("%s: Update entry state: %s", self.device.name, self.entry.state)

if self.entry.state not in valid_states:
if self.device.available:
_LOGGER.debug("%s: Forcing stop", self.device.name)
await self.device.stop()
raise UpdateFailed(f"{self.device.name}: Invalid entry state!")
raise UpdateFailed("Invalid entry state: %s", self.entry.state)

success = False
async with self.lock:
try:
success = await self.device.update()
retry = None if self.entry.state == ConfigEntryState.LOADED else 0
success = await self.device.update(retry)
except Exception as ex:
raise ConfigEntryError(str(ex)) from ex
finally:
Expand Down
4 changes: 1 addition & 3 deletions custom_components/uniled/lib/ble/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,8 @@ async def update(self, retry: int | None = None) -> bool:
if not (query := self.model.build_state_query(self)):
raise Exception("Update - Failed, no state query command available!")

_LOGGER.debug("%s: Update - Send State Query... (%s)", self.name, len(self._callbacks))
_LOGGER.debug("%s: Update - Send State Query... (retrys=%s)", self.name, retry)
self._notification_event.clear()
if len(self._callbacks) == 1 and retry == None:
retry = 0
if not await self.send(query, retry):
return False

Expand Down

0 comments on commit 195ead1

Please sign in to comment.