Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[script.domoticz.scenes] 0.0.22 #2533

Merged
merged 7 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions script.domoticz.scenes/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.domoticz.scenes" name="Domoticz Scenes" version="0.0.10" provider-name="Paul VW">
<addon id="script.domoticz.scenes" name="Domoticz Scenes" version="0.0.22" provider-name="Paul VW">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests" version="1.0.0"/>
Expand All @@ -18,15 +18,29 @@
<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. -->
<email>[email protected]</email> <!-- may be omitted -->
<source>https://github.com/Paul-VW/script.domoticz.scenes</source>
<news>v0.0.1 (22/03/2021)
[new] beta Release
<news>
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
</news>
<assets>
<icon>resources/icon.png</icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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------"
Original file line number Diff line number Diff line change
Expand Up @@ -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------"
Original file line number Diff line number Diff line change
Expand Up @@ -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------"

236 changes: 144 additions & 92 deletions script.domoticz.scenes/resources/lib/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -30,149 +29,202 @@
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&param=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&param=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&param=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&param=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&param=switchscene&idx=" + str(idx) + "&switchcmd=On"
requests.get(url=url)

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

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

def domoticz_toggle_group(idx):
query = "type=command&param=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&param=switchlight&idx=" + str(idx) + "&switchcmd=Set%20Level&level=" + state
requests.get(url=url)

def domoticz_toggle_switch(idx):
query = "type=command&param=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']
type = line['Type']
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)




Loading
Loading