Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue with calculating solar noon and midnight in some configurations #220

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions custom_components/circadian_lighting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ async def _async_get_sun_events(self, date):
sunset = await self._async_replace_time(date, "sunset")
solar_noon = sunrise + (sunset - sunrise) / 2
solar_midnight = sunset + ((sunrise + timedelta(days=1)) - sunset) / 2

# The replacement algorithm above keeps the current day,
# but changes time to sunrise/sunset. Unfortunately, it
# does not account for timezones. For people who's sunset
# is after 23:59 UTC (i.e. 01:30), the two events are out
# of order in the day.

# Fortunately, the nature of the math means that, if
# sunrise and sunset are swapped, solar noon and solar
# midnight simply end up swapped as well. So we can
# simply swap them back if we need to.
if (sunset < sunrise): # Out-of-order sunrise check
solar_noon, solar_midnight = solar_midnight, solar_noon
else:
_loc = await self.hass.async_add_executor_job(get_astral_location, self.hass)
if isinstance(_loc, tuple):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/circadian_lighting/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "circadian_lighting",
"name": "Circadian Lighting",
"version": "2.1.3-beta",
"version": "2.1.3",
"documentation": "https://github.com/claytonjn/hass-circadian_lighting",
"issue_tracker": "https://github.com/claytonjn/hass-circadian_lighting/issues",
"dependencies": ["sensor","switch"],
Expand Down