Lock Withings token refresh (#103688)

Lock Withings refresh
This commit is contained in:
Joost Lekkerkerker 2023-11-11 09:39:41 +01:00 committed by GitHub
parent 3f70437888
commit 667a453a35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -166,12 +166,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
implementation = await async_get_config_entry_implementation(hass, entry)
oauth_session = OAuth2Session(hass, entry, implementation)
refresh_lock = asyncio.Lock()
async def _refresh_token() -> str:
await oauth_session.async_ensure_token_valid()
token = oauth_session.token[CONF_ACCESS_TOKEN]
if TYPE_CHECKING:
assert isinstance(token, str)
return token
async with refresh_lock:
await oauth_session.async_ensure_token_valid()
token = oauth_session.token[CONF_ACCESS_TOKEN]
if TYPE_CHECKING:
assert isinstance(token, str)
return token
client.refresh_token_function = _refresh_token
withings_data = WithingsData(