From 6e18f35dc5db8a2b71278ff3e1f2908e0d6969ec Mon Sep 17 00:00:00 2001 From: zim514 Date: Tue, 1 Oct 2024 10:21:54 -0400 Subject: [PATCH] Use new infotag name for ambilight, fixes #297 Fix ambilight configuration reloading --- script.service.hue/addon.xml | 5 +- script.service.hue/resources/lib/ambigroup.py | 46 +++++++++++-------- script.service.hue/resources/lib/hue.py | 4 +- script.service.hue/resources/lib/settings.py | 4 +- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/script.service.hue/addon.xml b/script.service.hue/addon.xml index 377cbf22..3d54b2ec 100644 --- a/script.service.hue/addon.xml +++ b/script.service.hue/addon.xml @@ -1,4 +1,4 @@ - + @@ -20,10 +20,11 @@ https://github.com/zim514/script.service.hue https://forum.kodi.tv/showthread.php?tid=344886 - v2.0.11 + v2.0.12 - Fix schedule / activation checks - Fix Music support - Localisation updates from Weblate +- Fix Ambilight support Automatitza les llums Hue amb la reproducció de Kodi diff --git a/script.service.hue/resources/lib/ambigroup.py b/script.service.hue/resources/lib/ambigroup.py index 7d1cccab..b7d808a0 100644 --- a/script.service.hue/resources/lib/ambigroup.py +++ b/script.service.hue/resources/lib/ambigroup.py @@ -39,23 +39,9 @@ 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): @@ -63,20 +49,23 @@ def onAVStarted(self): 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}") - 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()}") 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") @@ -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) + 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}") \ No newline at end of file diff --git a/script.service.hue/resources/lib/hue.py b/script.service.hue/resources/lib/hue.py index 96a4a73e..455707dc 100644 --- a/script.service.hue/resources/lib/hue.py +++ b/script.service.hue/resources/lib/hue.py @@ -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}") self.connected = False return False diff --git a/script.service.hue/resources/lib/settings.py b/script.service.hue/resources/lib/settings.py index 516100bb..42f5c38d 100644 --- a/script.service.hue/resources/lib/settings.py +++ b/script.service.hue/resources/lib/settings.py @@ -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}") 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)