mirror of
https://github.com/home-assistant/core.git
synced 2025-08-25 23:41:35 +02:00
second background task
This commit is contained in:
@@ -74,28 +74,13 @@ class AutomowerDataUpdateCoordinator(DataUpdateCoordinator[dict[str, MowerAttrib
|
||||
"Failed to connect to websocket. Trying to reconnect: %s", err
|
||||
)
|
||||
if not hass.is_stopping:
|
||||
# self.hass.async_create_background_task(
|
||||
# hass,
|
||||
# self.client_listen(hass, entry, automower_client),
|
||||
# "reconnect_task",
|
||||
# )
|
||||
reconnect_time = 2
|
||||
await asyncio.sleep(reconnect_time)
|
||||
reconnect_time = min(reconnect_time * 2, MAX_WS_RECONNECT_TIME)
|
||||
await self.client_listen(
|
||||
hass=hass,
|
||||
entry=entry,
|
||||
automower_client=automower_client,
|
||||
reconnect_time=reconnect_time,
|
||||
entry.async_create_background_task(
|
||||
hass,
|
||||
self.client_listen(hass, entry, automower_client),
|
||||
"reconnect_task",
|
||||
)
|
||||
else:
|
||||
await automower_client.start_listening()
|
||||
|
||||
async def try_reconnect(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
automower_client: AutomowerSession,
|
||||
reconnect_time: int = 2,
|
||||
) -> None:
|
||||
"""Listen with the client."""
|
||||
|
@@ -141,12 +141,19 @@ async def test_websocket_not_available(
|
||||
reconnect_time = 2
|
||||
for count in range(1, 945):
|
||||
reconnect_time = min(reconnect_time * 2, MAX_WS_RECONNECT_TIME)
|
||||
print("reconnect_t", reconnect_time)
|
||||
freezer.tick(timedelta(seconds=reconnect_time))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_automower_client.auth.websocket_connect.call_count == count + 1
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
mock_automower_client.auth.websocket_connect.side_effect = None
|
||||
freezer.tick(timedelta(seconds=MAX_WS_RECONNECT_TIME))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_automower_client.start_listening.call_count == 1
|
||||
mock_automower_client.auth.websocket_connect.side_effect = (
|
||||
HusqvarnaWSServerHandshakeError("Boom")
|
||||
)
|
||||
|
||||
|
||||
async def test_device_info(
|
||||
|
Reference in New Issue
Block a user