Fix workday timezone (#119148)

This commit is contained in:
Tom Brien 2024-06-08 16:53:20 +01:00 committed by Franck Nijhof
parent 4bb1ea1da1
commit 7912c9e95c
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 5 additions and 3 deletions

View File

@ -269,7 +269,7 @@ class IsWorkdaySensor(BinarySensorEntity):
def _update_state_and_setup_listener(self) -> None:
"""Update state and setup listener for next interval."""
now = dt_util.utcnow()
now = dt_util.now()
self.update_data(now)
self.unsub = async_track_point_in_utc_time(
self.hass, self.point_in_time_listener, self.get_next_interval(now)

View File

@ -1,6 +1,6 @@
"""Tests the Home Assistant workday binary sensor."""
from datetime import date, datetime, timedelta
from datetime import date, datetime, timedelta, timezone
from typing import Any
from freezegun.api import FrozenDateTimeFactory
@ -68,7 +68,9 @@ async def test_setup(
freezer: FrozenDateTimeFactory,
) -> None:
"""Test setup from various configs."""
freezer.move_to(datetime(2022, 4, 15, 12, tzinfo=UTC)) # Friday
# Start on a Friday
await hass.config.async_set_time_zone("Europe/Paris")
freezer.move_to(datetime(2022, 4, 15, 0, tzinfo=timezone(timedelta(hours=1))))
await init_integration(hass, config)
state = hass.states.get("binary_sensor.workday_sensor")