def menu(): route = sys.argv[0] addon_handle = int(sys.argv[1]) base_url = sys.argv[0] command = sys.argv[2][1:] parsed = parse_qs(command) logger.debug( "Menu started. route: {}, handle: {}, command: {}, parsed: {}, Arguments: {}" .format(route, addon_handle, command, parsed, sys.argv)) if route == "plugin://script.service.hue/": if not command: build_menu(base_url, addon_handle) elif command == "settings": logger.debug("Opening settings") ADDON.openSettings() elif command == "toggle": if cache.get("script.service.hue.service_enabled" ) and get_status() != "Disabled by daylight": logger.info("Disable service") cache.set("script.service.hue.service_enabled", False) elif get_status() != "Disabled by daylight": logger.info("Enable service") cache.set("script.service.hue.service_enabled", True) else: logger.info("Disabled by daylight, ignoring") xbmc.executebuiltin('Container.Refresh') elif route == "plugin://script.service.hue/actions": action = parsed['action'][0] kgroupid = parsed['kgroupid'][0] logger.debug("Actions: {}, kgroupid: {}".format(action, kgroupid)) if action == "menu": items = [ (base_url + "?action=play&kgroupid=" + kgroupid, ListItem(_("Play"))), (base_url + "?action=pause&kgroupid=" + kgroupid, ListItem(_("Pause"))), (base_url + "?action=stop&kgroupid=" + kgroupid, ListItem(_("Stop"))), ] xbmcplugin.addDirectoryItems(addon_handle, items, len(items)) xbmcplugin.endOfDirectory(handle=addon_handle, cacheToDisc=True) else: cache.set("script.service.hue.action", (action, kgroupid), expiration=(timedelta(seconds=5))) else: logger.error( "Unknown command. Handle: {}, route: {}, Arguments: {}".format( addon_handle, route, sys.argv))
def configure_scene(self, group_id, action): scene = self.select_hue_scene() if scene is not None: # group0_startSceneID ADDON.setSettingString(f"group{group_id}_{action}SceneID", scene[0]) ADDON.setSettingString(f"group{group_id}_{action}SceneName", scene[1]) ADDON.openSettings()
def configure_ambilights(self, group_id): lights = self.select_hue_lights() light_names = [] color_lights = [] if lights is not None: for L in lights: light_names.append(self._get_light_name(L)) color_lights.append(L) ADDON.setSettingString(f"group{group_id}_Lights", ','.join(color_lights)) ADDON.setSettingString(f"group{group_id}_LightNames", ', '.join(light_names)) ADDON.setSettingBool(f"group{group_id}_enabled", True) ADDON.openSettings()
def menu(): route = sys.argv[0] addon_handle = int(sys.argv[1]) base_url = sys.argv[0] command = sys.argv[2][1:] parsed = parse_qs(command) if route == f"plugin://{ADDONID}/": if not command: build_menu(base_url, addon_handle) elif command == "settings": ADDON.openSettings() elif command == "toggle": if CACHE.get(f"{ADDONID}.service_enabled") and _get_status() != "Disabled by daylight": xbmc.log("[script.service.hue] Disable service") CACHE.set(f"{ADDONID}.service_enabled", False) elif _get_status() != "Disabled by daylight": xbmc.log("[script.service.hue] Enable service") CACHE.set(f"{ADDONID}.service_enabled", True) else: xbmc.log("[script.service.hue] Disabled by daylight, ignoring") xbmc.executebuiltin('Container.Refresh') elif route == f"plugin://{ADDONID}/actions": action = parsed['action'][0] light_group_id = parsed['light_group_id'][0] xbmc.log(f"[script.service.hue] Actions: {action}, light_group_id: {light_group_id}") if action == "menu": xbmcplugin.addDirectoryItem(addon_handle, base_url + "?action=play&light_group_id=" + light_group_id, ListItem(_("Play"))) xbmcplugin.addDirectoryItem(addon_handle, base_url + "?action=pause&light_group_id=" + light_group_id, ListItem(_("Pause"))) xbmcplugin.addDirectoryItem(addon_handle, base_url + "?action=stop&light_group_id=" + light_group_id, ListItem(_("Stop"))) xbmcplugin.endOfDirectory(handle=addon_handle, cacheToDisc=True) else: CACHE.set(f"{ADDONID}.action", (action, light_group_id), expiration=(timedelta(seconds=5))) else: xbmc.log(f"[script.service.hue] Unknown command. Handle: {addon_handle}, route: {route}, Arguments: {sys.argv}")
def _commands(monitor, command): xbmc.log(f"[script.service.hue] Started with {command}") if command == "discover": hue_connection = hueconnection.HueConnection(monitor, silent=True, discover=True) if hue_connection.connected: xbmc.log("[script.service.hue] Found bridge. Starting service.") ADDON.openSettings() _service(monitor) else: ADDON.openSettings() elif command == "createHueScene": hue_connection = hueconnection.HueConnection( monitor, silent=True, discover=False) # don't rediscover, proceed silently if hue_connection.connected: hue_connection.create_hue_scene() else: xbmc.log( "[script.service.hue] No bridge found. createHueScene cancelled." ) notification(_("Hue Service"), _("Check Hue Bridge configuration")) elif command == "deleteHueScene": hue_connection = hueconnection.HueConnection( monitor, silent=True, discover=False) # don't rediscover, proceed silently if hue_connection.connected: hue_connection.delete_hue_scene() else: xbmc.log( "[script.service.hue] No bridge found. deleteHueScene cancelled." ) notification(_("Hue Service"), _("Check Hue Bridge configuration")) elif command == "sceneSelect": # sceneSelect=light_group,action / sceneSelect=0,play light_group = sys.argv[2] action = sys.argv[3] # xbmc.log(f"[script.service.hue] sceneSelect: light_group: {light_group}, action: {action}") hue_connection = hueconnection.HueConnection( monitor, silent=True, discover=False) # don't rediscover, proceed silently if hue_connection.connected: hue_connection.configure_scene(light_group, action) else: xbmc.log( "[script.service.hue] No bridge found. sceneSelect cancelled.") notification(_("Hue Service"), _("Check Hue Bridge configuration")) elif command == "ambiLightSelect": # ambiLightSelect=light_group_id light_group = sys.argv[2] # xbmc.log(f"[script.service.hue] ambiLightSelect light_group_id: {light_group}") hue_connection = hueconnection.HueConnection( monitor, silent=True, discover=False ) # don't rediscover, proceed silently # don't rediscover, proceed silently if hue_connection.connected: hue_connection.configure_ambilights(light_group) else: xbmc.log( "[script.service.hue] No bridge found. Select ambi lights cancelled." ) notification(_("Hue Service"), _("Check Hue Bridge configuration")) else: xbmc.log(f"[script.service.hue] Unknown command: {command}") raise RuntimeError(f"Unknown Command: {command}")