Fix config entry exception in Ambient PWS (#21836)

This commit is contained in:
Aaron Bach 2019-03-08 20:25:35 -07:00 committed by Andrew Sayre
parent 012c657a9c
commit 113db9afd4

View File

@ -296,6 +296,7 @@ class AmbientStation:
def __init__(self, hass, config_entry, client, monitored_conditions): def __init__(self, hass, config_entry, client, monitored_conditions):
"""Initialize.""" """Initialize."""
self._config_entry = config_entry self._config_entry = config_entry
self._entry_setup_complete = False
self._hass = hass self._hass = hass
self._watchdog_listener = None self._watchdog_listener = None
self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY
@ -362,12 +363,18 @@ class AmbientStation:
'name', station['macAddress']), 'name', station['macAddress']),
} }
for component in ('binary_sensor', 'sensor'): # If the websocket disconnects and reconnects, the on_subscribed
self._hass.async_create_task( # hanlder will get called again; in that case, we don't want to
self._hass.config_entries.async_forward_entry_setup( # attempt forward setup of the config entry (because it will have
self._config_entry, component)) # already been done):
if not self._entry_setup_complete:
for component in ('binary_sensor', 'sensor'):
self._hass.async_create_task(
self._hass.config_entries.async_forward_entry_setup(
self._config_entry, component))
self._entry_setup_complete = True
self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY
self.client.websocket.on_connect(on_connect) self.client.websocket.on_connect(on_connect)
self.client.websocket.on_data(on_data) self.client.websocket.on_data(on_data)