Skip to content

Commit eeb0ae8

Browse files
authored
[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
1 parent 3f93515 commit eeb0ae8

File tree

6 files changed

+180
-114
lines changed

6 files changed

+180
-114
lines changed

script.domoticz.scenes/addon.xml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="script.domoticz.scenes" name="Domoticz Scenes" version="0.0.10" provider-name="Paul VW">
2+
<addon id="script.domoticz.scenes" name="Domoticz Scenes" version="0.0.22" provider-name="Paul VW">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0"/>
55
<import addon="script.module.requests" version="1.0.0"/>
@@ -18,15 +18,29 @@
1818
<website>https://github.com/Paul-VW/script.domoticz.scenes</website> <!-- the url of the website that contains the videos (or the official website of your plugin). May be omitted. -->
1919
<email>[email protected]</email> <!-- may be omitted -->
2020
<source>https://github.com/Paul-VW/script.domoticz.scenes</source>
21-
<news>v0.0.1 (22/03/2021)
22-
[new] beta Release
21+
<news>
22+
v0.0.22 (02/11/2023)
23+
[fix] End of list selected when cancel resolved
24+
25+
v0.0.21 (31/10/2023)
26+
[fix] Authentication issues
2327

24-
v0.0.8 (24/03/2021)
25-
[new] Support for scenes, switches and favorites
28+
v0.0.20 (26/10/2023)
29+
[new] Domoticz 2023.2 support
30+
[new] Ignore SSL Certificate error
31+
[fix] HTTPS connection to domoticz
32+
[fix] Toggle groups and start scenes
33+
[fix] End of list implementation resolved
2634

27-
v0.0.10 (01/04/2021)
28-
[fix] code cleanup
29-
[fix] Domoticz authentication
35+
v0.0.10 (01/04/2021)
36+
[fix] code cleanup
37+
[fix] Domoticz authentication
38+
39+
v0.0.8 (24/03/2021)
40+
[new] Support for scenes, switches and favorites
41+
42+
v0.0.1 (22/03/2021)
43+
[new] beta Release
3044
</news>
3145
<assets>
3246
<icon>resources/icon.png</icon>

script.domoticz.scenes/resources/language/resource.language.en_gb/strings.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ msgctxt "#30407"
5252
msgid "Favorites"
5353
msgstr "Favorites"
5454

55+
msgctxt "#30408"
56+
msgid "Ignore Certificate"
57+
msgstr "Negeer certificaat"
58+
5559
msgctxt "#30498"
5660
msgid "Domoticz in Kodi"
5761
msgstr "Domoticz in Kodi"
58-
59-
msgctxt "#30499"
60-
msgid "------End of list------"
61-
msgstr "------End of list------"

script.domoticz.scenes/resources/language/resource.language.en_us/strings.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ msgctxt "#30407"
5252
msgid "Favorites"
5353
msgstr "Favorites"
5454

55+
msgctxt "#30408"
56+
msgid "Ignore Certificate"
57+
msgstr "Negeer certificaat"
58+
5559
msgctxt "#30498"
5660
msgid "Domoticz in Kodi"
5761
msgstr "Domoticz in Kodi"
58-
59-
msgctxt "#30499"
60-
msgid "------End of list------"
61-
msgstr "------End of list------"

script.domoticz.scenes/resources/language/resource.language.nl_nl/strings.po

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ msgctxt "#30407"
4848
msgid "Favorites"
4949
msgstr "Favorieten"
5050

51+
msgctxt "#30408"
52+
msgid "Ignore Certificate"
53+
msgstr "Negeer certificaat"
54+
5155
msgctxt "#30498"
5256
msgid "Domoticz in Kodi"
5357
msgstr "Domoticz in Kodi"
54-
55-
msgctxt "#30499"
56-
msgid "------End of list------"
57-
msgstr "------Einde------"
58-

script.domoticz.scenes/resources/lib/script.py

Lines changed: 144 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
import xbmcaddon
55
import sys
66
import requests
7+
from requests.auth import HTTPBasicAuth
78
import json
89

910
addon_handle = int(sys.argv[1])
1011
xbmcplugin.setContent(addon_handle, 'videos')
1112
addonID = 'script.domoticz.scenes'
12-
addonVersion = '0.0.10'
13-
addonDate = "4/1/2021"
14-
15-
13+
addonVersion = '0.0.21'
14+
addonDate = "26/10/2023"
1615

1716
__addon__ = xbmcaddon.Addon()
1817
__addonname__ = __addon__.getAddonInfo('name')
@@ -30,149 +29,202 @@
3029
domoticz_user = xbmcaddon.Addon(id=addonID).getSetting('domoticz_user')
3130
domoticz_pass = xbmcaddon.Addon(id=addonID).getSetting('domoticz_pass')
3231
domoticz_port = xbmcaddon.Addon(id=addonID).getSetting('domoticz_port')
32+
domoticz_ssl = xbmcaddon.Addon(id=addonID).getSetting('SSL')
33+
domoticz_ignore_ssl = xbmcaddon.Addon(id=addonID).getSetting('ignore_SSL')
3334
domoticz_group = xbmcaddon.Addon(id=addonID).getSetting('group')
3435

3536

36-
def get_base_url(host, port, useSsl, username=None, password=None):
37-
if useSsl is True:
38-
base_url = "https://" + host + ":" + str(port)
39-
else:
40-
base_url = "http://" + host + ":" + str(port)
37+
def domoticz_submit(query):
38+
server = domoticz_host
39+
port = domoticz_port
40+
usr = domoticz_user
41+
pwd = domoticz_pass
42+
ssl = domoticz_ssl
43+
server = server.replace("http://", "")
44+
server = server.replace("https://", "")
4145

42-
if username is not None:
43-
setcreds = 'username=' + username + '&password=' + password + '&'
46+
if ssl == "true":
47+
protocol = "https://"
4448
else:
45-
setcreds = ''
49+
protocol = "http://"
4650

47-
url = base_url + "/json.htm?" + setcreds
48-
return url
51+
url = protocol + server + ":" + str(port) + "/json.htm?" + query
52+
53+
if domoticz_ignore_ssl == "true":
54+
requests.packages.urllib3.disable_warnings()
55+
if not usr and not pwd:
56+
r = requests.get(url=url, verify=False)
57+
else:
58+
r = requests.get(url=url, auth=HTTPBasicAuth(usr, pwd), verify=False)
59+
else:
60+
if not usr and not pwd:
61+
r = requests.get(url=url, verify=True)
62+
else:
63+
r = requests.get(url=url, auth=HTTPBasicAuth(usr, pwd), verify=False)
4964

65+
if r.status_code == 200:
66+
result = r.text
67+
data = json.loads(result)
68+
return data
5069

51-
def get_scenes(base_url):
52-
url = base_url + 'type=scenes'
53-
try:
54-
result = requests.get(url)
55-
except:
56-
return -1
5770

58-
answer = result.content
59-
jsonResult = json.loads(answer)
60-
deviceResult = jsonResult['result']
61-
return(deviceResult)
71+
def domoticz_get_version():
72+
query = "type=command&param=getversion"
73+
r = domoticz_submit(query=query)
74+
return r
6275

6376

64-
def get_favorite_devices_dict(base_url):
65-
url = base_url + 'type=devices&used=true&filter=all&favorite=1'
66-
try:
67-
result = requests.get(url)
68-
except:
69-
return -1
77+
def domoticz_scenes_and_groups():
78+
domoticz_version = domoticz_get_version()
79+
if domoticz_version['Revision'] > 15453 or domoticz_version['version'] == "2023.2 (build 15457)":
80+
query = "type=command&param=getscenes"
81+
else:
82+
query = 'type=scenes'
7083

71-
answer = result.content
84+
r = domoticz_submit(query=query)
7285

73-
jsonResult = json.loads(answer)
74-
deviceResult = jsonResult['result']
75-
return(deviceResult)
86+
devices = r['result']
87+
scenes_and_groups = []
88+
groups_list = []
89+
scenes_list = []
90+
for dev in devices:
91+
scenes_and_groups.append(dev)
92+
if dev['Type'] == "Group":
93+
groups_list.append(dev)
94+
elif dev['Type'] == "Scene":
95+
scenes_list.append(dev)
7696

97+
data = {"Groups": {"result": groups_list}, "Scenes": {"result": scenes_list}, "Groups and Scenes": {"result": scenes_and_groups}}
98+
return data
7799

78-
def get_all_switches(base_url):
79-
url = base_url + 'type=devices&filter=light&used=true&order=Name'
80-
try:
81-
result = requests.get(url)
82-
except:
83-
return -1
84100

85-
answer = result.content
101+
def domoticz_favorites():
102+
domoticz_version = domoticz_get_version()
103+
if domoticz_version['Revision'] > 15453 or domoticz_version['version'] == "2023.2 (build 15457)":
104+
query = "type=command&param=getdevices&used=true&filter=all&favorite=1"
105+
else:
106+
query = 'type=devices&used=true&filter=all&favorite=1'
107+
r = domoticz_submit(query=query)
108+
return r
86109

87-
jsonResult = json.loads(answer)
88-
deviceResult = jsonResult['result']
89-
return(deviceResult)
90110

111+
def domoticz_light_switches():
112+
domoticz_version = domoticz_get_version()
113+
if domoticz_version['Revision'] > 15453 or domoticz_version['version'] == "2023.2 (build 15457)":
114+
query = "type=command&param=getdevices&filter=light&used=true&order=Name"
115+
else:
116+
query = 'type=devices&filter=light&used=true&order=Name'
117+
r = domoticz_submit(query=query)
118+
return r
91119

92-
def switch_scene(base_url, idx):
93-
url = base_url + "type=command&param=switchscene&idx=" + str(idx) + "&switchcmd=On"
94-
requests.get(url=url)
95120

121+
def domoticz_start_scene(idx):
122+
query = "type=command&param=switchscene&idx=" + str(idx) + "&switchcmd=On"
123+
r = domoticz_submit(query=query)
124+
return r
96125

97-
def switch_switch(base_url, idx):
98-
url = base_url + "type=command&param=switchlight&idx=" + str(idx) + "&switchcmd=Toggle"
99-
requests.get(url=url)
100126

127+
def domoticz_toggle_group(idx):
128+
query = "type=command&param=switchscene&idx=" + str(idx) + "&switchcmd=Toggle"
129+
r = domoticz_submit(query=query)
130+
return r
101131

102-
def switch_dimmer(base_url, idx, state):
103-
url = base_url + "type=command&param=switchlight&idx=" + str(idx) + "&switchcmd=Set%20Level&level=" + state
104-
requests.get(url=url)
105132

133+
def domoticz_toggle_switch(idx):
134+
query = "type=command&param=switchlight&idx=" + str(idx) + "&switchcmd=Toggle"
135+
r = domoticz_submit(query=query)
136+
return r
106137

107-
def get_list(optionsDict):
108-
end_list = __addon__.getLocalizedString(30499)
109138

139+
def create_optionsList(optionsDict):
110140
optionsList = []
111141
for line in optionsDict:
112142
optionsList.append(line['Name'])
113-
optionsList.append(end_list)
114143
return optionsList
115144

116145

117-
base_url = get_base_url(host=domoticz_host, port=domoticz_port, useSsl=False, username=domoticz_user, password=domoticz_pass)
118-
119-
if str(domoticz_group) == '0':
120-
optionsDict = get_scenes(base_url=base_url)
121-
optionsList = get_list(optionsDict=optionsDict)
122-
123-
elif str(domoticz_group) == '1':
124-
optionsDict = get_all_switches(base_url=base_url)
125-
optionsList = get_list(optionsDict=optionsDict)
126-
127-
elif str(domoticz_group) == '2':
128-
optionsDict = get_favorite_devices_dict(base_url=base_url)
129-
optionsList = get_list(optionsDict=optionsDict)
130-
131-
else:
132-
optionsDict = get_all_switches(base_url=base_url)
133-
optionsList = get_list(optionsDict=optionsDict)
134-
135-
title = __addon__.getLocalizedString(30498)
136-
137-
answer = xbmcgui.Dialog().select(heading=title, list=optionsList)
138-
action = optionsList[answer]
139-
140-
141146
def get_idx(optionsDict, action):
142-
for line in optionsDict:
147+
for line in optionsDict['result']:
143148
Name = line['Name']
144149
if Name == action:
145150
idx = line['idx']
146151
return idx
147152

148153

154+
def get_group_scene_idx_type(optionsDict, action):
155+
for dev in optionsDict['result']:
156+
if dev['Name'] == action:
157+
if "Type" in dev:
158+
return dev['idx'], dev['Type']
159+
160+
149161
def get_favorites_idx(optionsDict, action):
150-
for line in optionsDict:
162+
for line in optionsDict['result']:
151163
Name = line['Name']
152164
if Name == action:
153165
idx = line['idx']
154166
type = line['Type']
155167
return idx, type
156168

157169

158-
def run():
159-
end_list = __addon__.getLocalizedString(30499)
170+
def create_optionsDict():
171+
if str(domoticz_group) == '0':
172+
data = domoticz_scenes_and_groups()
173+
optionsDict = data["Groups and Scenes"]
174+
optionsList = create_optionsList(optionsDict=optionsDict['result'])
175+
176+
elif str(domoticz_group) == '1':
177+
optionsDict = domoticz_light_switches()
178+
optionsList = create_optionsList(optionsDict=optionsDict['result'])
179+
180+
elif str(domoticz_group) == '2':
181+
optionsDict = domoticz_favorites()
182+
optionsList = create_optionsList(optionsDict=optionsDict['result'])
183+
184+
else:
185+
optionsDict = domoticz_light_switches()
186+
optionsList = create_optionsList(optionsDict=optionsDict['result'])
187+
188+
return optionsDict, optionsList
189+
190+
191+
title = __addon__.getLocalizedString(30498)
160192

161-
if action != end_list:
193+
domoticz_version = domoticz_get_version()
194+
optionsDict, optionsList = create_optionsDict()
195+
196+
answer = xbmcgui.Dialog().select(heading=title, list=optionsList)
197+
if answer == -1:
198+
action = None
199+
else:
200+
action = optionsList[answer]
201+
202+
203+
def run():
204+
if action and action in optionsList:
162205
if str(domoticz_group) == '0':
163-
idx = get_idx(optionsDict=optionsDict, action=action)
164-
switch_scene(base_url=base_url, idx=idx)
206+
idx, groupType = get_group_scene_idx_type(optionsDict=optionsDict, action=action)
207+
if groupType == "Scene":
208+
domoticz_start_scene(idx=idx)
209+
if groupType == "Group":
210+
domoticz_toggle_group(idx=idx)
165211
elif str(domoticz_group) == '1':
166212
idx = get_idx(optionsDict=optionsDict, action=action)
167-
switch_switch(base_url=base_url, idx=idx)
213+
domoticz_toggle_switch(idx=idx)
168214
elif str(domoticz_group) == '2':
169215
idx, type = get_favorites_idx(optionsDict=optionsDict, action=action)
170216
if type == 'Scene':
171-
switch_scene(base_url=base_url, idx=idx)
217+
domoticz_start_scene(idx=idx)
218+
if type == 'Group':
219+
domoticz_toggle_group(idx=idx)
172220
if type == 'Light/Switch':
173-
switch_switch(base_url=base_url, idx=idx)
221+
domoticz_toggle_switch(idx=idx)
174222
if type == 'Color Switch':
175-
switch_switch(base_url=base_url, idx=idx)
223+
domoticz_toggle_switch(idx=idx)
176224
else:
177225
idx = get_idx(optionsDict=optionsDict, action=action)
178-
switch_switch(base_url=base_url, idx=idx)
226+
domoticz_toggle_switch(idx=idx)
227+
228+
229+
230+

0 commit comments

Comments
 (0)