Skip to content

Commit

Permalink
fix boot sequence (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
prvakt authored Jan 5, 2025
1 parent a194f16 commit 0d49508
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions custom_components/myskoda/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,35 +158,39 @@ async def _async_update_data(self) -> State:
operations = self.operations

if self.entry.state == ConfigEntryState.SETUP_IN_PROGRESS:
if getattr(self, "_startup_called", False):
return self.data # Prevent duplicate execution
_LOGGER.debug("Performing initial data fetch for vin %s", self.vin)
try:
user = await self.myskoda.get_user()
vehicle = await self._async_get_minimal_data()
self._startup_called = True # Prevent duplicate execution
except ClientResponseError as err:
handle_aiohttp_error(
"setup user and vehicle", err, self.hass, self.entry
)
raise UpdateFailed("Failed to retrieve initial data during setup")

def _async_finish_startup(hass, config, vin) -> None:
async def _async_finish_startup(hass: HomeAssistant) -> None:
"""Tasks to execute when we have finished starting up."""
_LOGGER.debug(
"MySkoda has finished starting up. Scheduling post-start tasks for vin %s.",
vin,
self.vin,
)
try:
coord = hass.data[DOMAIN][config.entry_id][COORDINATORS][vin]
coord = hass.data[DOMAIN][self.entry.entry_id][COORDINATORS][
self.vin
]
if not coord.myskoda.mqtt and not coord._mqtt_connecting:
config.async_create_background_task(
self.entry.async_create_background_task(
self.hass, coord._mqtt_connect(), "mqtt"
)
except KeyError:
_LOGGER.debug("Could not connect to MQTT. Waiting for regular poll")
pass

async_at_started(
hass=self.hass,
at_start_cb=_async_finish_startup(self.hass, self.entry, self.vin), # pyright: ignore[reportArgumentType]
hass=self.hass, at_start_cb=_async_finish_startup
) # Schedule post-setup tasks
return State(vehicle, user, config, operations)

Expand Down

0 comments on commit 0d49508

Please sign in to comment.