Fix workday timezone (#119148)

This commit is contained in:
Tom Brien 2024-06-08 16:53:20 +01:00 committed by GitHub
parent a64d6e548c
commit fff2c1115d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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: def _update_state_and_setup_listener(self) -> None:
"""Update state and setup listener for next interval.""" """Update state and setup listener for next interval."""
now = dt_util.utcnow() now = dt_util.now()
self.update_data(now) self.update_data(now)
self.unsub = async_track_point_in_utc_time( self.unsub = async_track_point_in_utc_time(
self.hass, self.point_in_time_listener, self.get_next_interval(now) 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.""" """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 typing import Any
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
@ -68,7 +68,9 @@ async def test_setup(
freezer: FrozenDateTimeFactory, freezer: FrozenDateTimeFactory,
) -> None: ) -> None:
"""Test setup from various configs.""" """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) await init_integration(hass, config)
state = hass.states.get("binary_sensor.workday_sensor") state = hass.states.get("binary_sensor.workday_sensor")