From 332e06136d9929eedf66c5f3bbc4d4030a3a5da8 Mon Sep 17 00:00:00 2001 From: Clayton Nummer Date: Fri, 16 Sep 2022 20:25:54 -0400 Subject: [PATCH 1/2] Update manifest.json version bump --- custom_components/circadian_lighting/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/circadian_lighting/manifest.json b/custom_components/circadian_lighting/manifest.json index 16b4654..94fe6d4 100644 --- a/custom_components/circadian_lighting/manifest.json +++ b/custom_components/circadian_lighting/manifest.json @@ -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"], From 58ee84e4b2b154ec000f63d6c743149c79e5a322 Mon Sep 17 00:00:00 2001 From: Collin Read Date: Wed, 22 Mar 2023 13:38:04 -0600 Subject: [PATCH 2/2] Fix noon & midnight calculations for some configs This commit fixes an issue with the calculated solar noon and midnight. Incorrect values are calculated in configurations where sunset is before sunrise in the day (e.g. day from 14:00 to 02:00 UTC). This is more normal in timezones further from UTC. --- custom_components/circadian_lighting/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/custom_components/circadian_lighting/__init__.py b/custom_components/circadian_lighting/__init__.py index 2232050..7925e43 100644 --- a/custom_components/circadian_lighting/__init__.py +++ b/custom_components/circadian_lighting/__init__.py @@ -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):