From 2543f18e70d0707d85c662c25e8df748d763945e Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Mon, 11 Apr 2022 11:02:22 -0700 Subject: [PATCH] Fix google calendar timestamp out of range (#69863) --- homeassistant/components/google/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/google/__init__.py b/homeassistant/components/google/__init__.py index f6629cb3938..80c6ce2b811 100644 --- a/homeassistant/components/google/__init__.py +++ b/homeassistant/components/google/__init__.py @@ -193,9 +193,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation) # Force a token refresh to fix a bug where tokens were persisted with # expires_in (relative time delta) and expires_at (absolute time) swapped. - if session.token["expires_at"] >= datetime(2070, 1, 1).timestamp(): + # A google session token typically only lasts a few days between refresh. + now = datetime.now() + if session.token["expires_at"] >= (now + timedelta(days=365)).timestamp(): session.token["expires_in"] = 0 - session.token["expires_at"] = datetime.now().timestamp() + session.token["expires_at"] = now.timestamp() try: await session.async_ensure_token_valid() except aiohttp.ClientResponseError as err: