Fix SimpliSafe re-auth flow (#41805)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
5f3fc6a9e3
commit
690024b34a
1 changed files with 21 additions and 13 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue