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):
"""Initialize."""
self._config_entry = config_entry
self._entry_setup_complete = False
self._hass = hass
self._watchdog_listener = None
self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY
@ -362,10 +363,16 @@ class AmbientStation:
'name', station['macAddress']),
}
# If the websocket disconnects and reconnects, the on_subscribed
# hanlder will get called again; in that case, we don't want to
# attempt forward setup of the config entry (because it will have
# 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