Make sure Notion saves new refresh token upon startup (#112676)

* Make sure Notion saves new refresh token upon startup

* Code review

* Typing

* Smoother syntax

* Fix tests

* Fix tests for real
This commit is contained in:
Aaron Bach 2024-03-08 20:27:56 -07:00 committed by GitHub
parent 5b2a24b1bb
commit 3405bda835
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 7 deletions

View file

@ -181,6 +181,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# Create a callback to save the refresh token when it changes:
entry.async_on_unload(client.add_refresh_token_callback(async_save_refresh_token))
# Save the client's refresh token if it's different than what we already have:
if (token := client.refresh_token) and token != entry.data[CONF_REFRESH_TOKEN]:
async_save_refresh_token(token)
hass.config_entries.async_update_entry(entry, **entry_updates)
async def async_update() -> NotionData: