Squashed commit of the following:

commit 1edaf1d7ed
Merge: 0e7e06e a888afd
Author: Benjamin Auquite <halomastar@gmail.com>
Date:   Mon Apr 10 12:57:30 2023 -0500

    Merge branch 'main' into unconventional_sunrise_sunset_times

commit 0e7e06e8a4
Merge: 8fa554a fe7bdd3
Author: Benjamin Auquite <halomastar@gmail.com>
Date:   Sat Apr 8 20:23:20 2023 -0500

    Merge branch 'main' into unconventional_sunrise_sunset_times

commit 8fa554a4e7
Merge: ec64eda 39e9d0e
Author: Benjamin Auquite <halomastar@gmail.com>
Date:   Sat Apr 8 00:50:16 2023 -0500

    merge

commit ec64eda6bf
Merge: 8353db5 744e43f
Author: Benjamin Auquite <halomastar@gmail.com>
Date:   Tue Apr 4 21:08:54 2023 -0500

    Merge branch 'main' into unconventional_sunrise_sunset_times

commit 8353db54cc
Author: Benjamin Auquite <halomastar@gmail.com>
Date:   Tue Apr 4 00:56:24 2023 -0500

    tests are unfinished

commit 6cb24116c0
Author: Benjamin Auquite <halomastar@gmail.com>
Date:   Mon Apr 3 21:17:01 2023 -0500

    Update switch.py
This commit is contained in:
Benjamin Auquite 2023-04-11 19:12:20 -05:00
commit 9bec45b63c
3 changed files with 172 additions and 5 deletions

View file

@ -1682,15 +1682,27 @@ class SunLightSettings:
def calculate_noon_and_midnight(
sunset: datetime.datetime, sunrise: datetime.datetime
) -> tuple[datetime.datetime, datetime.datetime]:
middle = abs(sunset - sunrise) / 2
total = abs(sunset - sunrise)
middle = total / 2
total = (
total.total_seconds() / 60 / 60 * (2 / 3)
) # about 12 hours normally.
_LOGGER.debug(
"Calculate noon/midnight. Total diff: %s, middle: %s", total, middle
)
if sunset > sunrise:
noon = sunrise + middle
midnight = noon + timedelta(hours=12) * (1 if noon.hour < 12 else -1)
midnight = noon + timedelta(hours=total) * (
1 if noon.hour < total else -1
)
else:
midnight = sunset + middle
noon = midnight + timedelta(hours=12) * (
1 if midnight.hour < 12 else -1
noon = midnight + timedelta(hours=total) * (
1 if midnight.hour < total else -1
)
_LOGGER.debug(
"Calculate noon/midnight. Noon: %s Midnight: %s", noon, midnight
)
return noon, midnight
location = self.astral_location