mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Fix TOD component incorrectly determining the state between sunrise and sunset (#30199)
* TOD fix * Comment added * Review * Review * Review
This commit is contained in:
parent
3a3d448f17
commit
f878fabd09
@ -174,6 +174,20 @@ class TodSensor(BinarySensorDevice):
|
||||
|
||||
self._time_before = before_event_date
|
||||
|
||||
# We are calculating the _time_after value assuming that it will happen today
|
||||
# But that is not always true, e.g. after 23:00, before 12:00 and now is 10:00
|
||||
# If _time_before and _time_after are ahead of current_datetime:
|
||||
# _time_before is set to 12:00 next day
|
||||
# _time_after is set to 23:00 today
|
||||
# current_datetime is set to 10:00 today
|
||||
if (
|
||||
self._time_after > self.current_datetime
|
||||
and self._time_before > self.current_datetime + timedelta(days=1)
|
||||
):
|
||||
# remove one day from _time_before and _time_after
|
||||
self._time_after -= timedelta(days=1)
|
||||
self._time_before -= timedelta(days=1)
|
||||
|
||||
# Add offset to utc boundaries according to the configuration
|
||||
self._time_after += self._after_offset
|
||||
self._time_before += self._before_offset
|
||||
|
Loading…
x
Reference in New Issue
Block a user