Add retry at startup (#34656)

This commit is contained in:
Joakim Sørensen 2020-04-26 00:40:44 +02:00 committed by GitHub
parent 147dfa06af
commit 5760fb94fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 8 deletions

View File

@ -28,6 +28,7 @@ from homeassistant.const import (
)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.event import async_call_later
from .const import ATTR_SOUND_OUTPUT
@ -138,15 +139,30 @@ async def async_setup_tv_finalize(hass, config, conf, client):
client.clear_state_update_callbacks()
await client.disconnect()
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_on_stop)
async def async_load_platforms(_):
"""Load platforms and event listener."""
await async_connect(client)
await async_connect(client)
hass.async_create_task(
hass.helpers.discovery.async_load_platform("media_player", DOMAIN, conf, config)
)
hass.async_create_task(
hass.helpers.discovery.async_load_platform("notify", DOMAIN, conf, config)
)
if client.connection is None:
async_call_later(hass, 60, async_load_platforms)
_LOGGER.warning(
"No connection could be made with host %s, retrying in 60 seconds",
conf.get(CONF_HOST),
)
return
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_on_stop)
hass.async_create_task(
hass.helpers.discovery.async_load_platform(
"media_player", DOMAIN, conf, config
)
)
hass.async_create_task(
hass.helpers.discovery.async_load_platform("notify", DOMAIN, conf, config)
)
await async_load_platforms(None)
async def async_request_configuration(hass, config, conf, client):

View File

@ -41,6 +41,7 @@ def client_fixture():
"homeassistant.components.webostv.WebOsClient", autospec=True
) as mock_client_class:
client = mock_client_class.return_value
client.connection = True
client.software_info = {"device_id": "a1:b1:c1:d1:e1:f1"}
yield client