Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix boot sequence #525

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading