mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Fix time_date timestamp offsets (#43165)
This commit is contained in:
parent
8dbd54bed1
commit
87d86026ed
@ -100,10 +100,13 @@ class TimeDateSensor(Entity):
|
||||
return now + timedelta(seconds=86400)
|
||||
|
||||
if self.type == "beat":
|
||||
# Add 1 hour because @0 beats is at 23:00:00 UTC.
|
||||
timestamp = dt_util.as_timestamp(now + timedelta(hours=1))
|
||||
interval = 86.4
|
||||
else:
|
||||
timestamp = dt_util.as_timestamp(now)
|
||||
interval = 60
|
||||
timestamp = int(dt_util.as_timestamp(now))
|
||||
|
||||
delta = interval - (timestamp % interval)
|
||||
next_interval = now + timedelta(seconds=delta)
|
||||
_LOGGER.debug("%s + %s -> %s (%s)", now, delta, next_interval, self.type)
|
||||
|
@ -20,16 +20,16 @@ def restore_ts():
|
||||
async def test_intervals(hass):
|
||||
"""Test timing intervals of sensors."""
|
||||
device = time_date.TimeDateSensor(hass, "time")
|
||||
now = dt_util.utc_from_timestamp(45)
|
||||
now = dt_util.utc_from_timestamp(45.5)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
next_time = device.get_next_interval()
|
||||
assert next_time == dt_util.utc_from_timestamp(60)
|
||||
|
||||
device = time_date.TimeDateSensor(hass, "beat")
|
||||
now = dt_util.utc_from_timestamp(29)
|
||||
now = dt_util.parse_datetime("2020-11-13 00:00:29+01:00")
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
next_time = device.get_next_interval()
|
||||
assert next_time == dt_util.utc_from_timestamp(86.4)
|
||||
assert next_time == dt_util.parse_datetime("2020-11-13 00:01:26.4+01:00")
|
||||
|
||||
device = time_date.TimeDateSensor(hass, "date_time")
|
||||
now = dt_util.utc_from_timestamp(1495068899)
|
||||
|
Loading…
x
Reference in New Issue
Block a user