Fix time_date interval for DST (#43166)

This commit is contained in:
Anders Melchiorsen 2020-11-13 13:32:56 +01:00 committed by GitHub
parent 0a717f313e
commit 55b214ec9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -96,8 +96,8 @@ class TimeDateSensor(Entity):
now = dt_util.utcnow()
if self.type == "date":
now = dt_util.start_of_local_day(dt_util.as_local(now))
return now + timedelta(seconds=86400)
tomorrow = dt_util.as_local(now) + timedelta(days=1)
return dt_util.start_of_local_day(tomorrow)
if self.type == "beat":
# Add 1 hour because @0 beats is at 23:00:00 UTC.

View File

@ -137,6 +137,32 @@ async def test_timezone_intervals(hass):
next_time = device.get_next_interval()
assert next_time.timestamp() == dt_util.as_timestamp("2017-11-14 00:00:00-07:00")
# Entering DST
new_tz = dt_util.get_time_zone("Europe/Prague")
assert new_tz is not None
dt_util.set_default_time_zone(new_tz)
now = dt_util.parse_datetime("2020-03-29 00:00+01:00")
with patch("homeassistant.util.dt.utcnow", return_value=now):
next_time = device.get_next_interval()
assert next_time.timestamp() == dt_util.as_timestamp("2020-03-30 00:00+02:00")
now = dt_util.parse_datetime("2020-03-29 03:00+02:00")
with patch("homeassistant.util.dt.utcnow", return_value=now):
next_time = device.get_next_interval()
assert next_time.timestamp() == dt_util.as_timestamp("2020-03-30 00:00+02:00")
# Leaving DST
now = dt_util.parse_datetime("2020-10-25 00:00+02:00")
with patch("homeassistant.util.dt.utcnow", return_value=now):
next_time = device.get_next_interval()
assert next_time.timestamp() == dt_util.as_timestamp("2020-10-26 00:00:00+01:00")
now = dt_util.parse_datetime("2020-10-25 23:59+01:00")
with patch("homeassistant.util.dt.utcnow", return_value=now):
next_time = device.get_next_interval()
assert next_time.timestamp() == dt_util.as_timestamp("2020-10-26 00:00:00+01:00")
@patch(
"homeassistant.util.dt.utcnow",