Fix Google Calendar auth user code expire time comparison (#54893)

Fixes #51490.
pull/54961/head
Sebastian Lövdahl 2021-08-20 23:12:10 +03:00 committed by GitHub
parent 63f6a3b46b
commit 9633b9fe6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 5 deletions

View File

@ -1,5 +1,5 @@
"""Support for Google - Calendar Event Devices."""
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from enum import Enum
import logging
import os
@ -27,8 +27,8 @@ from homeassistant.const import (
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import generate_entity_id
from homeassistant.helpers.event import track_time_change
from homeassistant.util import convert, dt
from homeassistant.helpers.event import track_utc_time_change
from homeassistant.util import convert
_LOGGER = logging.getLogger(__name__)
@ -188,7 +188,12 @@ def do_authentication(hass, hass_config, config):
def step2_exchange(now):
"""Keep trying to validate the user_code until it expires."""
if now >= dt.as_local(dev_flow.user_code_expiry):
# For some reason, oauth.step1_get_device_and_user_codes() returns a datetime
# object without tzinfo. For the comparison below to work, it needs one.
user_code_expiry = dev_flow.user_code_expiry.replace(tzinfo=timezone.utc)
if now >= user_code_expiry:
hass.components.persistent_notification.create(
"Authentication code expired, please restart "
"Home-Assistant and try again",
@ -216,7 +221,7 @@ def do_authentication(hass, hass_config, config):
notification_id=NOTIFICATION_ID,
)
listener = track_time_change(
listener = track_utc_time_change(
hass, step2_exchange, second=range(0, 60, dev_flow.interval)
)