Skip to content

Commit

Permalink
Use new infotag name for ambilight, fixes #297
Browse files Browse the repository at this point in the history
Fix ambilight configuration reloading
  • Loading branch information
zim514 committed Oct 1, 2024
1 parent a1e85c4 commit 6e18f35
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
5 changes: 3 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="2.0.11">
<addon id="script.service.hue" name="Hue Service" provider-name="zim514" version="2.0.12">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests" version="2.31.0"/>
Expand All @@ -20,10 +20,11 @@
</assets>
<source>https://github.com/zim514/script.service.hue</source>
<forum>https://forum.kodi.tv/showthread.php?tid=344886</forum>
<news>v2.0.11
<news>v2.0.12
- Fix schedule / activation checks
- Fix Music support
- Localisation updates from Weblate
- Fix Ambilight support

</news>
<summary lang="ca_ES">Automatitza les llums Hue amb la reproducció de Kodi</summary>
Expand Down
46 changes: 26 additions & 20 deletions script.service.hue/resources/lib/ambigroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,33 @@ def __init__(self, light_group_id, settings_monitor, bridge):
self.converterC = Converter(GamutC)
self.helper = ColorHelper(GamutC) # Gamut doesn't matter for this usage

if getattr(self.settings_monitor, f"group{self.light_group_id}_enabled", False) and self.bridge.connected:

index = 0
lights = getattr(self.settings_monitor, f"group{self.light_group_id}_lights")
if len(lights) > 0:
for L in lights:
gamut = self._get_light_gamut(self.bridge, L)
if gamut == 404:
notification(header=_("Hue Service"), message=_(f"ERROR: Light not found, it may have been deleted"), icon=xbmcgui.NOTIFICATION_ERROR)
AMBI_RUNNING.clear()
ADDON.setSettingString(f"group{self.light_group_id}_Lights", "-1")
ADDON.setSettingString(f"group{self.light_group_id}_LightNames", _("Not selected"))
else:
light = {L: {'gamut': gamut, 'prev_xy': (0, 0), "index": index}}
self.ambi_lights.update(light)
index = index + 1
log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] Lights: {self.ambi_lights}")


# convert MS to seconds

def onAVStarted(self):
self.state = STATE_PLAYING
self.last_media_type = self._playback_type()
enabled = getattr(self.settings_monitor, f"group{self.light_group_id}_enabled", False)

if getattr(self.settings_monitor, f"group{self.light_group_id}_enabled", False) and self.bridge.connected:
self._get_lights()
else:
return

log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] onPlaybackStarted. Group enabled: {enabled}, Bridge connected: {self.bridge.connected}, mediaType: {self.media_type}")

Check warning on line 57 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)

if not enabled or not self.bridge.connected:
return

log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] onPlaybackStarted. media_type: {self.media_type} == playback_type: {self._playback_type()}")

Check warning on line 60 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)
if self.media_type == self._playback_type() and self._playback_type() == VIDEO:
try:
self.video_info_tag = self.getVideoInfoTag()
self.info_tag = self.getVideoInfoTag()
except (AttributeError, TypeError) as x:
log(f"[SCRIPT.SERVICE.HUE] AmbiGroup{self.light_group_id}: OnAV Started: Can't read infoTag")
reporting.process_exception(x)
else:
self.video_info_tag = None
self.info_tag = None

if self.activation_check.validate():
log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] Running Play action")
Expand Down Expand Up @@ -281,3 +270,20 @@ def _resume_all_light_states(self, states):
log(f"[SCRIPT.SERVICE.HUE] Light[{light_id}] state resumed successfully.")
else:
log(f"[SCRIPT.SERVICE.HUE] Failed to resume Light[{light_id}] state.")

def _get_lights(self):
index = 0
lights = getattr(self.settings_monitor, f"group{self.light_group_id}_lights")
if len(lights) > 0:
for L in lights:
gamut = self._get_light_gamut(self.bridge, L)
if gamut == 404:
notification(header=_("Hue Service"), message=_(f"ERROR: Light not found, it may have been deleted"), icon=xbmcgui.NOTIFICATION_ERROR)

Check warning on line 281 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)
AMBI_RUNNING.clear()
ADDON.setSettingString(f"group{self.light_group_id}_Lights", "-1")
ADDON.setSettingString(f"group{self.light_group_id}_LightNames", _("Not selected"))
else:
light = {L: {'gamut': gamut, 'prev_xy': (0, 0), "index": index}}
self.ambi_lights.update(light)
index = index + 1
log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] Lights: {self.ambi_lights}")
4 changes: 2 additions & 2 deletions script.service.hue/resources/lib/hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def connect(self):
self.session.headers.update({'hue-application-key': self.settings_monitor.key})

self.devices = self.make_api_request("GET", "device")
if self.devices is None:
log(f"[SCRIPT.SERVICE.HUE] v2 connect: Connection attempts failed. Setting connected to False")
if not isinstance(self.devices, dict):
log(f"[SCRIPT.SERVICE.HUE] v2 connect: Connection error. Setting connected to False. {type(self.devices)} : {self.devices}")

Check warning on line 135 in script.service.hue/resources/lib/hue.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)
self.connected = False
return False

Expand Down
4 changes: 2 additions & 2 deletions script.service.hue/resources/lib/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def reload_settings(self):
self._validate_ambilight()

def _validate_ambilight(self):
log(f"[SCRIPT.SERVICE.HUE] Validate ambilight config. Enabled: {self.group3_enabled}, Lights: {self.group3_lights}")
log(f"[SCRIPT.SERVICE.HUE] Validate ambilight config. Enabled: {self.group3_enabled}, Lights: {type(self.group3_lights)} : {self.group3_lights}")

Check warning on line 117 in script.service.hue/resources/lib/settings.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)
if self.group3_enabled:
if self.group3_lights == '-1':
if self.group3_lights == ["-1"]:
ADDON.setSettingBool('group3_enabled', False)
log('[SCRIPT.SERVICE.HUE] _validate_ambilights: No ambilights selected')
notification(_('Hue Service'), _('No lights selected for Ambilight.'), icon=xbmcgui.NOTIFICATION_ERROR)
Expand Down

0 comments on commit 6e18f35

Please sign in to comment.