Fix SimpliSafe re-auth flow (#41805)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Aaron Bach 2020-10-15 02:15:32 -06:00 committed by GitHub
parent 5f3fc6a9e3
commit 690024b34a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,7 +16,7 @@ from simplipy.websocket import (
)
import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_REAUTH
from homeassistant.const import (
ATTR_CODE,
CONF_CODE,
@ -374,8 +374,7 @@ async def async_unload_entry(hass, entry):
async def async_update_options(hass, config_entry):
"""Handle an options update."""
simplisafe = hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id]
simplisafe.options = config_entry.options
await hass.config_entries.async_reload(config_entry.entry_id)
class SimpliSafeWebsocket:
@ -539,17 +538,26 @@ class SimpliSafe:
for result in results:
if isinstance(result, InvalidCredentialsError):
if self._emergency_refresh_token_used:
LOGGER.error(
"Token disconnected or invalid. Please re-auth the "
"SimpliSafe integration in HASS"
)
self._hass.async_create_task(
self._hass.config_entries.flow.async_init(
DOMAIN,
context={"source": "reauth"},
data=self._config_entry.data,
matching_flows = [
flow
for flow in self._hass.config_entries.flow.async_progress()
if flow["context"].get("source") == SOURCE_REAUTH
and flow["context"].get("unique_id")
== self._config_entry.unique_id
]
if not matching_flows:
self._hass.async_create_task(
self._hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": SOURCE_REAUTH,
"unique_id": self._config_entry.unique_id,
},
data=self._config_entry.data,
)
)
)
return
LOGGER.warning("SimpliSafe cloud error; trying stored refresh token")