mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Reduce startup time for System Bridge integration (#91171)
This commit is contained in:
parent
c601266f9c
commit
48df638f5d
@ -53,7 +53,10 @@ SERVICE_SEND_KEYPRESS = "send_keypress"
|
|||||||
SERVICE_SEND_TEXT = "send_text"
|
SERVICE_SEND_TEXT = "send_text"
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: ConfigEntry,
|
||||||
|
) -> bool:
|
||||||
"""Set up System Bridge from a config entry."""
|
"""Set up System Bridge from a config entry."""
|
||||||
|
|
||||||
# Check version before initialising
|
# Check version before initialising
|
||||||
@ -64,6 +67,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
session=async_get_clientsession(hass),
|
session=async_get_clientsession(hass),
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
async with async_timeout.timeout(10):
|
||||||
if not await version.check_supported():
|
if not await version.check_supported():
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
"You are not running a supported version of System Bridge. Please"
|
"You are not running a supported version of System Bridge. Please"
|
||||||
@ -87,7 +91,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
entry=entry,
|
entry=entry,
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
async with async_timeout.timeout(30):
|
async with async_timeout.timeout(10):
|
||||||
await coordinator.async_get_data(MODULES)
|
await coordinator.async_get_data(MODULES)
|
||||||
except AuthenticationException as exception:
|
except AuthenticationException as exception:
|
||||||
_LOGGER.error("Authentication failed for %s: %s", entry.title, exception)
|
_LOGGER.error("Authentication failed for %s: %s", entry.title, exception)
|
||||||
@ -105,8 +109,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# Wait for initial data
|
# Wait for initial data
|
||||||
async with async_timeout.timeout(30):
|
async with async_timeout.timeout(10):
|
||||||
while not coordinator.is_ready():
|
while not coordinator.is_ready:
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Waiting for initial data from %s (%s)",
|
"Waiting for initial data from %s (%s)",
|
||||||
entry.title,
|
entry.title,
|
||||||
|
@ -55,7 +55,7 @@ async def _validate_input(
|
|||||||
data[CONF_API_KEY],
|
data[CONF_API_KEY],
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
async with async_timeout.timeout(30):
|
async with async_timeout.timeout(15):
|
||||||
await websocket_client.connect(session=async_get_clientsession(hass))
|
await websocket_client.connect(session=async_get_clientsession(hass))
|
||||||
hass.async_create_task(websocket_client.listen())
|
hass.async_create_task(websocket_client.listen())
|
||||||
response = await websocket_client.get_data(GetData(modules=["system"]))
|
response = await websocket_client.get_data(GetData(modules=["system"]))
|
||||||
|
@ -82,6 +82,7 @@ class SystemBridgeDataUpdateCoordinator(
|
|||||||
hass, LOGGER, name=DOMAIN, update_interval=timedelta(seconds=30)
|
hass, LOGGER, name=DOMAIN, update_interval=timedelta(seconds=30)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
def is_ready(self) -> bool:
|
def is_ready(self) -> bool:
|
||||||
"""Return if the data is ready."""
|
"""Return if the data is ready."""
|
||||||
if self.data is None:
|
if self.data is None:
|
||||||
@ -157,7 +158,7 @@ class SystemBridgeDataUpdateCoordinator(
|
|||||||
self.last_update_success = False
|
self.last_update_success = False
|
||||||
self.async_update_listeners()
|
self.async_update_listeners()
|
||||||
except (ConnectionClosedException, ConnectionResetError) as exception:
|
except (ConnectionClosedException, ConnectionResetError) as exception:
|
||||||
self.logger.info(
|
self.logger.debug(
|
||||||
"Websocket connection closed for %s. Will retry: %s",
|
"Websocket connection closed for %s. Will retry: %s",
|
||||||
self.title,
|
self.title,
|
||||||
exception,
|
exception,
|
||||||
@ -168,7 +169,7 @@ class SystemBridgeDataUpdateCoordinator(
|
|||||||
self.last_update_success = False
|
self.last_update_success = False
|
||||||
self.async_update_listeners()
|
self.async_update_listeners()
|
||||||
except ConnectionErrorException as exception:
|
except ConnectionErrorException as exception:
|
||||||
self.logger.warning(
|
self.logger.debug(
|
||||||
"Connection error occurred for %s. Will retry: %s",
|
"Connection error occurred for %s. Will retry: %s",
|
||||||
self.title,
|
self.title,
|
||||||
exception,
|
exception,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user