From eeb0ae8939d0c52169137f9506e3e82ec0ebb252 Mon Sep 17 00:00:00 2001 From: Paul-VW <81295916+Paul-VW@users.noreply.github.com> Date: Sun, 19 Nov 2023 22:10:58 +0100 Subject: [PATCH] [script.domoticz.scenes] 0.0.22 (#2533) * [script.domoticz.scenes] 0.0.20 ### Description Update to connect to Domoticz version 2023.2 ### Checklist: - [X] My code follows the [add-on rules](http://kodi.wiki/view/Add-on_rules) and [piracy stance](http://kodi.wiki/view/Official:Forum_rules#Piracy_Policy) of this project. - [X] I have read the [CONTRIBUTING](https://github.com/xbmc/repo-scripts/blob/master/CONTRIBUTING.md) document - [X] Each add-on submission should be a single commit with using the following style: [script.foo.bar] 1.0.0 * Update script.py * [script.domoticz.scenes] 0.0.21 Fixed authentication issues * [script.domoticz.scenes] 0.0.22 * Add files via upload * [scrit.domoticz.scenes] 0.0.22 BasicAuth fixed --- script.domoticz.scenes/addon.xml | 30 ++- .../resource.language.en_gb/strings.po | 8 +- .../resource.language.en_us/strings.po | 8 +- .../resource.language.nl_nl/strings.po | 9 +- .../resources/lib/script.py | 236 +++++++++++------- script.domoticz.scenes/resources/settings.xml | 3 +- 6 files changed, 180 insertions(+), 114 deletions(-) diff --git a/script.domoticz.scenes/addon.xml b/script.domoticz.scenes/addon.xml index 3ef76abdc3..45d37484eb 100644 --- a/script.domoticz.scenes/addon.xml +++ b/script.domoticz.scenes/addon.xml @@ -1,5 +1,5 @@ - + @@ -18,15 +18,29 @@ https://github.com/Paul-VW/script.domoticz.scenes paulvw@live.com https://github.com/Paul-VW/script.domoticz.scenes - v0.0.1 (22/03/2021) -[new] beta Release + + v0.0.22 (02/11/2023) + [fix] End of list selected when cancel resolved + + v0.0.21 (31/10/2023) + [fix] Authentication issues -v0.0.8 (24/03/2021) -[new] Support for scenes, switches and favorites + v0.0.20 (26/10/2023) + [new] Domoticz 2023.2 support + [new] Ignore SSL Certificate error + [fix] HTTPS connection to domoticz + [fix] Toggle groups and start scenes + [fix] End of list implementation resolved -v0.0.10 (01/04/2021) -[fix] code cleanup -[fix] Domoticz authentication + v0.0.10 (01/04/2021) + [fix] code cleanup + [fix] Domoticz authentication + + v0.0.8 (24/03/2021) + [new] Support for scenes, switches and favorites + + v0.0.1 (22/03/2021) + [new] beta Release resources/icon.png diff --git a/script.domoticz.scenes/resources/language/resource.language.en_gb/strings.po b/script.domoticz.scenes/resources/language/resource.language.en_gb/strings.po index 9d343ef572..9fd35b2ccb 100644 --- a/script.domoticz.scenes/resources/language/resource.language.en_gb/strings.po +++ b/script.domoticz.scenes/resources/language/resource.language.en_gb/strings.po @@ -52,10 +52,10 @@ msgctxt "#30407" msgid "Favorites" msgstr "Favorites" +msgctxt "#30408" +msgid "Ignore Certificate" +msgstr "Negeer certificaat" + msgctxt "#30498" msgid "Domoticz in Kodi" msgstr "Domoticz in Kodi" - -msgctxt "#30499" -msgid "------End of list------" -msgstr "------End of list------" diff --git a/script.domoticz.scenes/resources/language/resource.language.en_us/strings.po b/script.domoticz.scenes/resources/language/resource.language.en_us/strings.po index 9d343ef572..9fd35b2ccb 100644 --- a/script.domoticz.scenes/resources/language/resource.language.en_us/strings.po +++ b/script.domoticz.scenes/resources/language/resource.language.en_us/strings.po @@ -52,10 +52,10 @@ msgctxt "#30407" msgid "Favorites" msgstr "Favorites" +msgctxt "#30408" +msgid "Ignore Certificate" +msgstr "Negeer certificaat" + msgctxt "#30498" msgid "Domoticz in Kodi" msgstr "Domoticz in Kodi" - -msgctxt "#30499" -msgid "------End of list------" -msgstr "------End of list------" diff --git a/script.domoticz.scenes/resources/language/resource.language.nl_nl/strings.po b/script.domoticz.scenes/resources/language/resource.language.nl_nl/strings.po index 37d6d8d35e..99c48fc728 100644 --- a/script.domoticz.scenes/resources/language/resource.language.nl_nl/strings.po +++ b/script.domoticz.scenes/resources/language/resource.language.nl_nl/strings.po @@ -48,11 +48,10 @@ msgctxt "#30407" msgid "Favorites" msgstr "Favorieten" +msgctxt "#30408" +msgid "Ignore Certificate" +msgstr "Negeer certificaat" + msgctxt "#30498" msgid "Domoticz in Kodi" msgstr "Domoticz in Kodi" - -msgctxt "#30499" -msgid "------End of list------" -msgstr "------Einde------" - diff --git a/script.domoticz.scenes/resources/lib/script.py b/script.domoticz.scenes/resources/lib/script.py index 97a21e821a..8b085325db 100644 --- a/script.domoticz.scenes/resources/lib/script.py +++ b/script.domoticz.scenes/resources/lib/script.py @@ -4,15 +4,14 @@ import xbmcaddon import sys import requests +from requests.auth import HTTPBasicAuth import json addon_handle = int(sys.argv[1]) xbmcplugin.setContent(addon_handle, 'videos') addonID = 'script.domoticz.scenes' -addonVersion = '0.0.10' -addonDate = "4/1/2021" - - +addonVersion = '0.0.21' +addonDate = "26/10/2023" __addon__ = xbmcaddon.Addon() __addonname__ = __addon__.getAddonInfo('name') @@ -30,124 +29,137 @@ domoticz_user = xbmcaddon.Addon(id=addonID).getSetting('domoticz_user') domoticz_pass = xbmcaddon.Addon(id=addonID).getSetting('domoticz_pass') domoticz_port = xbmcaddon.Addon(id=addonID).getSetting('domoticz_port') +domoticz_ssl = xbmcaddon.Addon(id=addonID).getSetting('SSL') +domoticz_ignore_ssl = xbmcaddon.Addon(id=addonID).getSetting('ignore_SSL') domoticz_group = xbmcaddon.Addon(id=addonID).getSetting('group') -def get_base_url(host, port, useSsl, username=None, password=None): - if useSsl is True: - base_url = "https://" + host + ":" + str(port) - else: - base_url = "http://" + host + ":" + str(port) +def domoticz_submit(query): + server = domoticz_host + port = domoticz_port + usr = domoticz_user + pwd = domoticz_pass + ssl = domoticz_ssl + server = server.replace("http://", "") + server = server.replace("https://", "") - if username is not None: - setcreds = 'username=' + username + '&password=' + password + '&' + if ssl == "true": + protocol = "https://" else: - setcreds = '' + protocol = "http://" - url = base_url + "/json.htm?" + setcreds - return url + url = protocol + server + ":" + str(port) + "/json.htm?" + query + + if domoticz_ignore_ssl == "true": + requests.packages.urllib3.disable_warnings() + if not usr and not pwd: + r = requests.get(url=url, verify=False) + else: + r = requests.get(url=url, auth=HTTPBasicAuth(usr, pwd), verify=False) + else: + if not usr and not pwd: + r = requests.get(url=url, verify=True) + else: + r = requests.get(url=url, auth=HTTPBasicAuth(usr, pwd), verify=False) + if r.status_code == 200: + result = r.text + data = json.loads(result) + return data -def get_scenes(base_url): - url = base_url + 'type=scenes' - try: - result = requests.get(url) - except: - return -1 - answer = result.content - jsonResult = json.loads(answer) - deviceResult = jsonResult['result'] - return(deviceResult) +def domoticz_get_version(): + query = "type=command¶m=getversion" + r = domoticz_submit(query=query) + return r -def get_favorite_devices_dict(base_url): - url = base_url + 'type=devices&used=true&filter=all&favorite=1' - try: - result = requests.get(url) - except: - return -1 +def domoticz_scenes_and_groups(): + domoticz_version = domoticz_get_version() + if domoticz_version['Revision'] > 15453 or domoticz_version['version'] == "2023.2 (build 15457)": + query = "type=command¶m=getscenes" + else: + query = 'type=scenes' - answer = result.content + r = domoticz_submit(query=query) - jsonResult = json.loads(answer) - deviceResult = jsonResult['result'] - return(deviceResult) + devices = r['result'] + scenes_and_groups = [] + groups_list = [] + scenes_list = [] + for dev in devices: + scenes_and_groups.append(dev) + if dev['Type'] == "Group": + groups_list.append(dev) + elif dev['Type'] == "Scene": + scenes_list.append(dev) + data = {"Groups": {"result": groups_list}, "Scenes": {"result": scenes_list}, "Groups and Scenes": {"result": scenes_and_groups}} + return data -def get_all_switches(base_url): - url = base_url + 'type=devices&filter=light&used=true&order=Name' - try: - result = requests.get(url) - except: - return -1 - answer = result.content +def domoticz_favorites(): + domoticz_version = domoticz_get_version() + if domoticz_version['Revision'] > 15453 or domoticz_version['version'] == "2023.2 (build 15457)": + query = "type=command¶m=getdevices&used=true&filter=all&favorite=1" + else: + query = 'type=devices&used=true&filter=all&favorite=1' + r = domoticz_submit(query=query) + return r - jsonResult = json.loads(answer) - deviceResult = jsonResult['result'] - return(deviceResult) +def domoticz_light_switches(): + domoticz_version = domoticz_get_version() + if domoticz_version['Revision'] > 15453 or domoticz_version['version'] == "2023.2 (build 15457)": + query = "type=command¶m=getdevices&filter=light&used=true&order=Name" + else: + query = 'type=devices&filter=light&used=true&order=Name' + r = domoticz_submit(query=query) + return r -def switch_scene(base_url, idx): - url = base_url + "type=command¶m=switchscene&idx=" + str(idx) + "&switchcmd=On" - requests.get(url=url) +def domoticz_start_scene(idx): + query = "type=command¶m=switchscene&idx=" + str(idx) + "&switchcmd=On" + r = domoticz_submit(query=query) + return r -def switch_switch(base_url, idx): - url = base_url + "type=command¶m=switchlight&idx=" + str(idx) + "&switchcmd=Toggle" - requests.get(url=url) +def domoticz_toggle_group(idx): + query = "type=command¶m=switchscene&idx=" + str(idx) + "&switchcmd=Toggle" + r = domoticz_submit(query=query) + return r -def switch_dimmer(base_url, idx, state): - url = base_url + "type=command¶m=switchlight&idx=" + str(idx) + "&switchcmd=Set%20Level&level=" + state - requests.get(url=url) +def domoticz_toggle_switch(idx): + query = "type=command¶m=switchlight&idx=" + str(idx) + "&switchcmd=Toggle" + r = domoticz_submit(query=query) + return r -def get_list(optionsDict): - end_list = __addon__.getLocalizedString(30499) +def create_optionsList(optionsDict): optionsList = [] for line in optionsDict: optionsList.append(line['Name']) - optionsList.append(end_list) return optionsList -base_url = get_base_url(host=domoticz_host, port=domoticz_port, useSsl=False, username=domoticz_user, password=domoticz_pass) - -if str(domoticz_group) == '0': - optionsDict = get_scenes(base_url=base_url) - optionsList = get_list(optionsDict=optionsDict) - -elif str(domoticz_group) == '1': - optionsDict = get_all_switches(base_url=base_url) - optionsList = get_list(optionsDict=optionsDict) - -elif str(domoticz_group) == '2': - optionsDict = get_favorite_devices_dict(base_url=base_url) - optionsList = get_list(optionsDict=optionsDict) - -else: - optionsDict = get_all_switches(base_url=base_url) - optionsList = get_list(optionsDict=optionsDict) - -title = __addon__.getLocalizedString(30498) - -answer = xbmcgui.Dialog().select(heading=title, list=optionsList) -action = optionsList[answer] - - def get_idx(optionsDict, action): - for line in optionsDict: + for line in optionsDict['result']: Name = line['Name'] if Name == action: idx = line['idx'] return idx +def get_group_scene_idx_type(optionsDict, action): + for dev in optionsDict['result']: + if dev['Name'] == action: + if "Type" in dev: + return dev['idx'], dev['Type'] + + def get_favorites_idx(optionsDict, action): - for line in optionsDict: + for line in optionsDict['result']: Name = line['Name'] if Name == action: idx = line['idx'] @@ -155,24 +167,64 @@ def get_favorites_idx(optionsDict, action): return idx, type -def run(): - end_list = __addon__.getLocalizedString(30499) +def create_optionsDict(): + if str(domoticz_group) == '0': + data = domoticz_scenes_and_groups() + optionsDict = data["Groups and Scenes"] + optionsList = create_optionsList(optionsDict=optionsDict['result']) + + elif str(domoticz_group) == '1': + optionsDict = domoticz_light_switches() + optionsList = create_optionsList(optionsDict=optionsDict['result']) + + elif str(domoticz_group) == '2': + optionsDict = domoticz_favorites() + optionsList = create_optionsList(optionsDict=optionsDict['result']) + + else: + optionsDict = domoticz_light_switches() + optionsList = create_optionsList(optionsDict=optionsDict['result']) + + return optionsDict, optionsList + + +title = __addon__.getLocalizedString(30498) - if action != end_list: +domoticz_version = domoticz_get_version() +optionsDict, optionsList = create_optionsDict() + +answer = xbmcgui.Dialog().select(heading=title, list=optionsList) +if answer == -1: + action = None +else: + action = optionsList[answer] + + +def run(): + if action and action in optionsList: if str(domoticz_group) == '0': - idx = get_idx(optionsDict=optionsDict, action=action) - switch_scene(base_url=base_url, idx=idx) + idx, groupType = get_group_scene_idx_type(optionsDict=optionsDict, action=action) + if groupType == "Scene": + domoticz_start_scene(idx=idx) + if groupType == "Group": + domoticz_toggle_group(idx=idx) elif str(domoticz_group) == '1': idx = get_idx(optionsDict=optionsDict, action=action) - switch_switch(base_url=base_url, idx=idx) + domoticz_toggle_switch(idx=idx) elif str(domoticz_group) == '2': idx, type = get_favorites_idx(optionsDict=optionsDict, action=action) if type == 'Scene': - switch_scene(base_url=base_url, idx=idx) + domoticz_start_scene(idx=idx) + if type == 'Group': + domoticz_toggle_group(idx=idx) if type == 'Light/Switch': - switch_switch(base_url=base_url, idx=idx) + domoticz_toggle_switch(idx=idx) if type == 'Color Switch': - switch_switch(base_url=base_url, idx=idx) + domoticz_toggle_switch(idx=idx) else: idx = get_idx(optionsDict=optionsDict, action=action) - switch_switch(base_url=base_url, idx=idx) + domoticz_toggle_switch(idx=idx) + + + + diff --git a/script.domoticz.scenes/resources/settings.xml b/script.domoticz.scenes/resources/settings.xml index c0efb762be..7d0f7d12f7 100644 --- a/script.domoticz.scenes/resources/settings.xml +++ b/script.domoticz.scenes/resources/settings.xml @@ -2,8 +2,9 @@ - + +