From 3bf3c5f541b8bf8023678db5f2707a0b1f12ff06 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 9 Sep 2020 23:26:30 +0200 Subject: [PATCH] fix the today['sunset'] is not set before used in comparison --- custom_components/circadian_lighting/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/circadian_lighting/__init__.py b/custom_components/circadian_lighting/__init__.py index 97d9095..24b4fcb 100755 --- a/custom_components/circadian_lighting/__init__.py +++ b/custom_components/circadian_lighting/__init__.py @@ -244,24 +244,24 @@ def calc_percent(self): # It's before sunrise (after midnight), because it's before # sunrise (and after midnight) sunset must have happend yesterday. yesterday = self.get_sunrise_sunset(now - timedelta(days=1)) - today[SUN_EVENT_SUNSET] = yesterday[SUN_EVENT_SUNSET] if ( today[SUN_EVENT_MIDNIGHT] > today[SUN_EVENT_SUNSET] and yesterday[SUN_EVENT_MIDNIGHT] > yesterday[SUN_EVENT_SUNSET] ): # Solar midnight is after sunset so use yesterdays's time today[SUN_EVENT_MIDNIGHT] = yesterday[SUN_EVENT_MIDNIGHT] + today[SUN_EVENT_SUNSET] = yesterday[SUN_EVENT_SUNSET] elif now_ts > today[SUN_EVENT_SUNSET]: # It's after sunset (before midnight), because it's after sunset # (and before midnight) sunrise should happen tomorrow. tomorrow = self.get_sunrise_sunset(now + timedelta(days=1)) - today[SUN_EVENT_SUNRISE] = tomorrow[SUN_EVENT_SUNRISE] if ( today[SUN_EVENT_MIDNIGHT] < today[SUN_EVENT_SUNRISE] and tomorrow[SUN_EVENT_MIDNIGHT] < tomorrow[SUN_EVENT_SUNRISE] ): # Solar midnight is before sunrise so use tomorrow's time today[SUN_EVENT_MIDNIGHT] = tomorrow[SUN_EVENT_MIDNIGHT] + today[SUN_EVENT_SUNRISE] = tomorrow[SUN_EVENT_SUNRISE] # Figure out where we are in time so we know which half of the # parabola to calculate. We're generating a different