Skip to content

Commit

Permalink
Fix behavior with invalid ambilight IDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
zim514 committed Dec 27, 2023
1 parent 972e4c6 commit 214763b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,4 @@ Audio Group: 1
## Includes code and contributions from:
- [Kodi Volunteer Translators](https://kodi.weblate.cloud), contribute [here](https://kodi.wiki/view/Translations)
- [ScreenBloom by Tyler Kershner](https://github.com/kershner/screenBloom)
- [Qhue by Quentin Stafford-Fraser](https://github.com/quentinsf/qhue)
- [hue-python-rgb-converter (rgbxy) by Benjamin Knight](https://github.com/benknight/hue-python-rgb-converter)
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ msgid "Disabled by daytime"
msgstr "Disabled by daytime"

msgctxt "#30064"
msgid "ERROR: Scene not found"
msgstr "ERROR: Scene not found"
msgid "ERROR: Scene not found, it may have been deleted"
msgstr "ERROR: Scene not found, it may have been deleted"

msgctxt "#30080"
msgid "The following error occurred:"
Expand Down Expand Up @@ -449,10 +449,6 @@ msgctxt "#30019"
msgid "Bridge outdated. Please update your bridge."
msgstr ""

msgctxt "#30003"
msgid "ERROR: Scene or Light not found, it may have changed or been deleted. Check your configuration."
msgstr ""

msgctxt "#30033"
msgid "Reconnected"
msgstr ""
Expand All @@ -477,3 +473,11 @@ msgstr ""
msgctxt "#30026"
msgid "Connection failed, retrying..."
msgstr ""

msgctxt "#30003"
msgid "Not selected"
msgstr ""

msgctxt "#30027"
msgid "ERROR: Light not found, it may have been deleted"
msgstr ""
19 changes: 14 additions & 5 deletions script.service.hue/resources/lib/ambigroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ def reload_settings(self):
if len(light_ids) > 0:
for L in light_ids:
gamut = self._get_light_gamut(self.bridge, L)
light = {L: {'gamut': gamut, 'prev_xy': (0, 0), "index": index}}
self.ambi_lights.update(light)
index = index + 1
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
xbmc.log(f"[script.service.hue] AmbiGroup[{self.light_group_id}] Lights: {self.ambi_lights}")
self.update_interval = ADDON.getSettingInt(f"group{self.light_group_id}_Interval") / 1000 # convert MS to seconds
if self.update_interval == 0:
Expand Down Expand Up @@ -210,7 +216,7 @@ def _update_hue_rgb(self, r, g, b, light, transition_time, bri):
elif response == 404:
xbmc.log(f"[script.service.hue] AmbiGroup[{self.light_group_id}] Not Found")
AMBI_RUNNING.clear()
notification(header=_("Hue Service"), message=_(f"ERROR: Scene or Light not found, it may have changed or been deleted. Check your configuration."), icon=xbmcgui.NOTIFICATION_ERROR)
notification(header=_("Hue Service"), message=_(f"ERROR: Light not found, it may have been deleted"), icon=xbmcgui.NOTIFICATION_ERROR)
AMBI_RUNNING.clear() # shut it down
else:
xbmc.log(f"[script.service.hue] AmbiGroup[{self.light_group_id}] RequestException Hue call fail")
Expand All @@ -231,7 +237,10 @@ def bridge_capacity_error(self):
def _get_light_gamut(bridge, light):
gamut = "C" # default
light_data = bridge.make_api_request("GET", f"light/{light}")
if light_data is not None and 'data' in light_data:
if light_data == 404:
xbmc.log(f"[script.service.hue] _get_light_gamut: Light[{light}] not found or ID invalid")
return 404
elif light_data is not None and 'data' in light_data:
for item in light_data['data']:
if 'color' in item and 'gamut_type' in item['color']:
gamut = item['color']['gamut_type']
Expand Down
5 changes: 3 additions & 2 deletions script.service.hue/resources/lib/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get_string(t):
_strings['hue status: '] = 30061
_strings['settings'] = 30062
_strings['disabled by daytime'] = 30063
_strings['error: scene not found'] = 30064
_strings['error: scene not found, it may have been deleted'] = 30064
_strings['the following error occurred:'] = 30080
_strings['automatically report this error?'] = 30081
_strings['no lights selected for ambilight.'] = 30069
Expand All @@ -133,10 +133,11 @@ def get_string(t):
_strings['bridge not found automatically. please make sure your bridge is up to date and has access to the internet. [cr]would you like to enter your bridge ip manually?'] = 30007
_strings['connecting...'] = 30009
_strings['bridge outdated. please update your bridge.'] = 30019
_strings['error: scene or light not found, it may have changed or been deleted. check your configuration.'] = 30003
_strings['reconnected'] = 30033
_strings['re-enable time'] = 31334
_strings['transition time (seconds):'] = 31335
_strings['bridge overloaded, stopping ambilight'] = 30002
_strings['bridge unauthorized, please reconfigure.'] = 30025
_strings['connection failed, retrying...'] = 30026
_strings['not selected'] = 30003
_strings['error: light not found, it may have been deleted'] = 30027
2 changes: 1 addition & 1 deletion script.service.hue/resources/lib/lightgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def run_action(self, action):
ADDON.setSettingString(f"group{self.light_group_id}_{action}SceneName", "Not Selected")
ADDON.setSettingString(f"group{self.light_group_id}_{action}SceneID", "-1")
xbmc.log(f"[script.service.hue] Scene {scene} not found - group{self.light_group_id}_{action}Behavior ")
notification(header=_("Hue Service"), message=_("ERROR: Scene not found"), icon=xbmcgui.NOTIFICATION_ERROR)
notification(header=_("Hue Service"), message=_("ERROR: Scene not found, it may have been deleted"), icon=xbmcgui.NOTIFICATION_ERROR)


else:
Expand Down

0 comments on commit 214763b

Please sign in to comment.