mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix handling of connection error during Synology DSM setup (#73248)
* dont reload on conection error during setup * also fetch API errors during update
This commit is contained in:
parent
8f8c1348ba
commit
8b735ffabe
@ -2,7 +2,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from datetime import timedelta
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from synology_dsm import SynologyDSM
|
from synology_dsm import SynologyDSM
|
||||||
@ -98,7 +97,7 @@ class SynoApi:
|
|||||||
self._async_setup_api_requests()
|
self._async_setup_api_requests()
|
||||||
|
|
||||||
await self._hass.async_add_executor_job(self._fetch_device_configuration)
|
await self._hass.async_add_executor_job(self._fetch_device_configuration)
|
||||||
await self.async_update()
|
await self.async_update(first_setup=True)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def subscribe(self, api_key: str, unique_id: str) -> Callable[[], None]:
|
def subscribe(self, api_key: str, unique_id: str) -> Callable[[], None]:
|
||||||
@ -251,7 +250,7 @@ class SynoApi:
|
|||||||
# ignore API errors during logout
|
# ignore API errors during logout
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def async_update(self, now: timedelta | None = None) -> None:
|
async def async_update(self, first_setup: bool = False) -> None:
|
||||||
"""Update function for updating API information."""
|
"""Update function for updating API information."""
|
||||||
LOGGER.debug("Start data update for '%s'", self._entry.unique_id)
|
LOGGER.debug("Start data update for '%s'", self._entry.unique_id)
|
||||||
self._async_setup_api_requests()
|
self._async_setup_api_requests()
|
||||||
@ -259,14 +258,22 @@ class SynoApi:
|
|||||||
await self._hass.async_add_executor_job(
|
await self._hass.async_add_executor_job(
|
||||||
self.dsm.update, self._with_information
|
self.dsm.update, self._with_information
|
||||||
)
|
)
|
||||||
except (SynologyDSMLoginFailedException, SynologyDSMRequestException) as err:
|
except (
|
||||||
LOGGER.warning(
|
SynologyDSMLoginFailedException,
|
||||||
"Connection error during update, fallback by reloading the entry"
|
SynologyDSMRequestException,
|
||||||
)
|
SynologyDSMAPIErrorException,
|
||||||
|
) as err:
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"Connection error during update of '%s' with exception: %s",
|
"Connection error during update of '%s' with exception: %s",
|
||||||
self._entry.unique_id,
|
self._entry.unique_id,
|
||||||
err,
|
err,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if first_setup:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
LOGGER.warning(
|
||||||
|
"Connection error during update, fallback by reloading the entry"
|
||||||
|
)
|
||||||
await self._hass.config_entries.async_reload(self._entry.entry_id)
|
await self._hass.config_entries.async_reload(self._entry.entry_id)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user