Skip to content
Merged
Changes from 1 commit
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
33 changes: 25 additions & 8 deletions homeassistant/components/webostv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
)
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

Expand Down Expand Up @@ -138,15 +140,30 @@ async def async_on_stop(event):
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be nice to use a back off mechanism like this:

await async_setup(hass, config, retry_delay=min(2 * retry_delay, 900))

@wolph wolph Apr 29, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally would be against a back-off mechanism with a max of 15 minutes because I use it to monitor how much TV my kid has watched. Having an offset of up to 15 minutes is not much use if they're allowed 30 minutes in total ;)

_LOGGER.warning(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be another level, if logged at all?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely :P
I would say ideally warning only the firs time and debug after. While the fix appears to work, it's awfully spammy right now

"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):
Expand Down