Skip to content

Commit

Permalink
Fix timer failing at sunset
Browse files Browse the repository at this point in the history
  • Loading branch information
zim514 committed Jan 8, 2024
1 parent e21fe96 commit 27db89b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
6 changes: 4 additions & 2 deletions script.service.hue/addon.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<addon id="script.service.hue" name="Hue Service" provider-name="zim514" version="1.5.6">
<addon id="script.service.hue" name="Hue Service" provider-name="zim514" version="1.5.7">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests" version="2.27.1"/>
Expand All @@ -20,7 +20,9 @@
</assets>
<source>https://github.com/zim514/script.service.hue</source>
<forum>https://forum.kodi.tv/showthread.php?tid=344886</forum>
<news>
<news>v1.5.7
- Fix morning / sunset timers

v1.5.6
- Translations updates from Weblate
- Various bug fixes
Expand Down
25 changes: 12 additions & 13 deletions script.service.hue/resources/lib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def _run_sunset(self):
def _set_daytime(self):
now = datetime.now()

if self.morning_time <= now.time() <= self.bridge.sunset:
if self.morning_time <= now.time() < self.bridge.sunset:
cache_set("daytime", True)
else:
cache_set("daytime", False)
Expand All @@ -249,26 +249,25 @@ def _task_loop(self):
while not self.monitor.abortRequested() and not self.stop_timers.is_set():

now = datetime.now()
self.morning_time = convert_time(ADDON.getSettingString("morningTime")) # Update morning time in case it has changed
self.morning_time = convert_time(ADDON.getSettingString("morningTime")) # Update morning time in case it has changed

Check notice on line 252 in script.service.hue/resources/lib/core.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (129 \> 120 characters)

Check notice on line 252 in script.service.hue/resources/lib/core.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (129 \> 120 characters)

time_to_sunset = self._time_until(now, self.bridge.sunset)
time_to_morning = self._time_until(now, self.morning_time)

if time_to_sunset < time_to_morning:
# Sunset is next
wait_time = time_to_sunset
xbmc.log(f"[script.service.hue] Timers: Sunset is next. wait_time: {wait_time}")
if self.monitor.waitForAbort(wait_time):
break
self._run_sunset()
if time_to_sunset <= 0 or time_to_sunset > time_to_morning:

else:
# Morning is next
wait_time = time_to_morning
xbmc.log(f"[script.service.hue] Timers: Morning is next. wait_time: {wait_time}")
if self.monitor.waitForAbort(wait_time):
xbmc.log(f"[script.service.hue] Timers: Morning is next. wait_time: {time_to_morning}")
if self.monitor.waitForAbort(time_to_morning):
break
self._run_morning()

else:
# Sunset is next
xbmc.log(f"[script.service.hue] Timers: Sunset is next. wait_time: {time_to_sunset}")
if self.monitor.waitForAbort(time_to_sunset):
break
self._run_sunset()
xbmc.log("[script.service.hue] Timers stopped")

@staticmethod
Expand Down

0 comments on commit 27db89b

Please sign in to comment.