mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Fix Google Calendar auth user code expire time comparison (#54893)
Fixes #51490.
This commit is contained in:
parent
63f6a3b46b
commit
9633b9fe6e
@ -1,5 +1,5 @@
|
|||||||
"""Support for Google - Calendar Event Devices."""
|
"""Support for Google - Calendar Event Devices."""
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta, timezone
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -27,8 +27,8 @@ from homeassistant.const import (
|
|||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import generate_entity_id
|
from homeassistant.helpers.entity import generate_entity_id
|
||||||
from homeassistant.helpers.event import track_time_change
|
from homeassistant.helpers.event import track_utc_time_change
|
||||||
from homeassistant.util import convert, dt
|
from homeassistant.util import convert
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -188,7 +188,12 @@ def do_authentication(hass, hass_config, config):
|
|||||||
|
|
||||||
def step2_exchange(now):
|
def step2_exchange(now):
|
||||||
"""Keep trying to validate the user_code until it expires."""
|
"""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(
|
hass.components.persistent_notification.create(
|
||||||
"Authentication code expired, please restart "
|
"Authentication code expired, please restart "
|
||||||
"Home-Assistant and try again",
|
"Home-Assistant and try again",
|
||||||
@ -216,7 +221,7 @@ def do_authentication(hass, hass_config, config):
|
|||||||
notification_id=NOTIFICATION_ID,
|
notification_id=NOTIFICATION_ID,
|
||||||
)
|
)
|
||||||
|
|
||||||
listener = track_time_change(
|
listener = track_utc_time_change(
|
||||||
hass, step2_exchange, second=range(0, 60, dev_flow.interval)
|
hass, step2_exchange, second=range(0, 60, dev_flow.interval)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user