-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddon.py
96 lines (91 loc) · 3.8 KB
/
addon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import xbmcaddon
import xbmcgui
import logging
import threading
import socket
import time
import random
import sys
from resources.lib.limitlessbridge import *
from resources.lib.limitlesslight import *
from resources.lib.limitlessscene import *
from resources.lib import utils
from service import SCENES
addon = xbmcaddon.Addon()
addonname = addon.getAddonInfo('name')
class Main(object):
def __init__(self,scenename):
utils.log_normal("Applying Scene: " + scenename)
self.bridge = LimitlessBridge(addon.getSetting("b0_host"),addon.getSetting("b0_port"))
scene = LimitlessScene(scenename,0,False)
for i in ("0","1","2","3","4"):
lowerscenename = scenename.lower()
enabled=utils.get_bool_setting("b0_l"+i+"_"+lowerscenename+"_enable")
if enabled:
color = utils.get_setting("b0_l"+i+"_"+lowerscenename+"_color")
brightness = utils.get_setting("b0_l"+i+"_"+lowerscenename+"_brightness")
light = LimitlessLight(self.bridge,'rgbw',i,True,color,brightness)
utils.log_verbose("Settings: label: " + lowerscenename + " scenename: " + scenename + " lights: " + str(light))
scene.addLight(light)
self.bridge.applyScene(scene)
def enabledDialog():
dialog = xbmcgui.Dialog().ok("Activities Enabled","Scenes will be applied according to your activity settings")
def disabledDialog():
dialog = xbmcgui.Dialog().ok("Activities Disabled","Scenes will be no loger be applied. You may still manually control the scene.")
# Args:
# argv[1] (first argument)
# "scene" - will configure a named scene.
# - argv[2] - scene name ("TV","Movie","Normal","Off","Reading","Dimmed","Video","Music" etc.)
# "toggle" - will toggle activity handling state
# "activity"- will set activity handling state
# - argv[2] - "true"|"false"
# "settings"- will open settings dialog
# None - will open an options dialog to allow user to choose the above capabilities
if __name__ == "__main__":
count = len(sys.argv) - 1
activityState = utils.get_bool_setting("activity_enable")
currentState = "Enabled" if activityState else "Disabled"
toggleState = "Disable" if activityState else "Enable"
if count > 0:
if sys.argv[1] == "scene":
Main(sys.argv[2])
elif sys.argv[1] == "toggle":
val = "false" if activityState else "true"
utils.set_setting("activity_enable",val)
if val == "false":
disabledDialog()
else:
enabledDialog()
elif sys.argv[1] == "activity":
val = "true"
try:
val = "true" if sys.argv[2] == "true" else "false"
except:
pass
utils.set_setting("activity_enable",val)
if val == "true":
enabledDiaglog()
else:
disabledDialog()
elif sys.argv[1] == "settings":
utils.open_settings()
else:
dialog = xbmcgui.Dialog()
options = sorted([elem for elem in SCENES.keys() if elem!="None"])
change_index = len(options)
options.append(" - " + toggleState + " Activities -")
options.append(" - Settings -")
options.append(" - Cancel - ")
rets = dialog.select("Select a Scene (Activities " + currentState + ")",options)
txt = options[rets]
if rets < change_index:
Main(options[rets])
elif txt == " - Settings -":
utils.open_settings()
elif txt == " - Enable Activities -":
utils.set_setting("activity_enable","true")
enabledDialog()
elif txt == " - Disable Activities -":
utils.set_setting("activity_enable","false")
disabledDialog()
pass