mirror of
https://github.com/Andre0512/hon.git
synced 2024-11-24 07:10:15 +01:00
Safe refresh token
This commit is contained in:
parent
8694882c45
commit
d175e19c3b
@ -29,16 +29,22 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
|||||||
session = aiohttp_client.async_get_clientsession(hass)
|
session = aiohttp_client.async_get_clientsession(hass)
|
||||||
if (config_dir := hass.config.config_dir) is None:
|
if (config_dir := hass.config.config_dir) is None:
|
||||||
raise ValueError("Missing Config Dir")
|
raise ValueError("Missing Config Dir")
|
||||||
hon = await Hon(
|
kwargs = {
|
||||||
entry.data[CONF_EMAIL],
|
"email": entry.data[CONF_EMAIL],
|
||||||
entry.data[CONF_PASSWORD],
|
"password": entry.data[CONF_PASSWORD],
|
||||||
mobile_id=MOBILE_ID,
|
"mobile_id": MOBILE_ID,
|
||||||
session=session,
|
"session": session,
|
||||||
refresh_token=entry.data[CONF_REFRESH_TOKEN],
|
"test_data_path": Path(config_dir),
|
||||||
test_data_path=Path(config_dir),
|
}
|
||||||
).create()
|
if refresh_token := entry.data.get(CONF_REFRESH_TOKEN):
|
||||||
|
kwargs["refresh_token"] = refresh_token
|
||||||
|
hon = await Hon(**kwargs).create()
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.unique_id] = hon
|
hass.data[DOMAIN][entry.unique_id] = hon
|
||||||
|
|
||||||
|
hass.config_entries.async_update_entry(
|
||||||
|
entry, data={**entry.data, CONF_REFRESH_TOKEN: hon.api.auth.refresh_token}
|
||||||
|
)
|
||||||
hass.data[DOMAIN]["coordinators"] = {}
|
hass.data[DOMAIN]["coordinators"] = {}
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
for platform in PLATFORMS:
|
||||||
@ -49,7 +55,11 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
|||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
|
||||||
entry.data[CONF_REFRESH_TOKEN] = hass.data[DOMAIN][entry.unique_id].api.auth.refresh_token
|
refresh_token = hass.data[DOMAIN][entry.unique_id].api.auth.refresh_token
|
||||||
|
|
||||||
|
hass.config_entries.async_update_entry(
|
||||||
|
entry, data={**entry.data, CONF_REFRESH_TOKEN: refresh_token}
|
||||||
|
)
|
||||||
unload = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
unload = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
if unload:
|
if unload:
|
||||||
if not hass.data[DOMAIN]:
|
if not hass.data[DOMAIN]:
|
||||||
|
Loading…
Reference in New Issue
Block a user