diff --git a/homeassistant/components/time_date/sensor.py b/homeassistant/components/time_date/sensor.py index 86ff3531240..e8e7d38fe35 100644 --- a/homeassistant/components/time_date/sensor.py +++ b/homeassistant/components/time_date/sensor.py @@ -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) diff --git a/tests/components/time_date/test_sensor.py b/tests/components/time_date/test_sensor.py index bf55ea8075b..8b8695a2879 100644 --- a/tests/components/time_date/test_sensor.py +++ b/tests/components/time_date/test_sensor.py @@ -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)