mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-10-07 18:07:08 +02:00
Squashed commit of the following:
commit1edaf1d7edMerge:0e7e06ea888afdAuthor: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 10 12:57:30 2023 -0500 Merge branch 'main' into unconventional_sunrise_sunset_times commit0e7e06e8a4Merge:8fa554afe7bdd3Author: Benjamin Auquite <halomastar@gmail.com> Date: Sat Apr 8 20:23:20 2023 -0500 Merge branch 'main' into unconventional_sunrise_sunset_times commit8fa554a4e7Merge:ec64eda39e9d0eAuthor: Benjamin Auquite <halomastar@gmail.com> Date: Sat Apr 8 00:50:16 2023 -0500 merge commitec64eda6bfMerge:8353db5744e43fAuthor: Benjamin Auquite <halomastar@gmail.com> Date: Tue Apr 4 21:08:54 2023 -0500 Merge branch 'main' into unconventional_sunrise_sunset_times commit8353db54ccAuthor: Benjamin Auquite <halomastar@gmail.com> Date: Tue Apr 4 00:56:24 2023 -0500 tests are unfinished commit6cb24116c0Author: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 3 21:17:01 2023 -0500 Update switch.py
This commit is contained in:
parent
ce4e04358e
commit
9bec45b63c
3 changed files with 172 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue