Freeze config entry data (#32615)

* Freeze config entry data

* Fix mutating entry.data

* Fix config entry options tests
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-03-09 14:07:50 -07:00
1 parent 3318e65948
commit d4615fd432
16 files changed
+71 -45

No files matched your search

@@ -109,8 +109,9 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
entry.data[CONF_OAUTH_CLIENT_SECRET],
entry.data[CONF_REFRESH_TOKEN],
)
entry.data[CONF_REFRESH_TOKEN] = token.refresh_token
hass.config_entries.async_update_entry(entry)
hass.config_entries.async_update_entry(
entry, data={**entry.data, CONF_REFRESH_TOKEN: token.refresh_token}
)
# Get devices and their current status
devices = await api.devices(location_ids=[installed_app.location_id])
@@ -304,8 +305,13 @@ class DeviceBroker:
self._entry.data[CONF_OAUTH_CLIENT_ID],
self._entry.data[CONF_OAUTH_CLIENT_SECRET],
)
self._entry.data[CONF_REFRESH_TOKEN] = self._token.refresh_token
self._hass.config_entries.async_update_entry(self._entry)
self._hass.config_entries.async_update_entry(
self._entry,
data={
**self._entry.data,
CONF_REFRESH_TOKEN: self._token.refresh_token,
},
)
_LOGGER.debug(
"Regenerated refresh token for installed app: %s",
self._installed_app_id,
@@ -428,8 +428,9 @@ async def smartapp_update(hass: HomeAssistantType, req, resp, app):
None,
)
if entry:
entry.data[CONF_REFRESH_TOKEN] = req.refresh_token
hass.config_entries.async_update_entry(entry)
hass.config_entries.async_update_entry(
entry, data={**entry.data, CONF_REFRESH_TOKEN: req.refresh_token}
)
_LOGGER.debug(
"Updated SmartApp '%s' under parent app '%s'", req.installed_app_id, app.app_id