forked from robheyes/lifxcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LIFXMultiZoneChild.groovy
154 lines (130 loc) · 4.25 KB
/
LIFXMultiZoneChild.groovy
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
*
* Copyright 2020 David Kilgore. All Rights Reserved
*
* This software is free for Private Use. You may use and modify the software without distributing it.
* If you make a fork, and add new code, then you should create a pull request to add value, there is no
* guarantee that your pull request will be merged.
*
* You may not grant a sublicense to modify and distribute this software to third parties without permission
* from the copyright holder
* Software is provided without warranty and your use of it is at your own risk.
*
*/
metadata {
definition(name: "LIFX Multizone Child", namespace: "robheyes", author: "David Kilgore", importUrl: 'https://raw.githubusercontent.com/robheyes/lifxcode/master/LIFXMultiZoneChild.groovy') {
capability 'Light'
capability 'ColorControl'
capability 'ColorTemperature'
capability 'Initialize'
capability 'Switch'
capability "Switch Level"
attribute "label", "string"
attribute "zone", "number"
command "setState", ["MAP"]
}
preferences {
input "useActivityLogFlag", "bool", title: "Enable activity logging", required: false
input "useDebugActivityLogFlag", "bool", title: "Enable debug logging", required: false
}
}
@SuppressWarnings("unused")
def installed() {
initialize()
}
@SuppressWarnings("unused")
def updated() {
initialize()
}
def initialize() {
state.useActivityLog = useActivityLogFlag
state.useActivityLogDebug = useDebugActivityLogFlag
unschedule()
}
@SuppressWarnings("unused")
def refresh() {
}
def getZone() {
return device.getDataValue("zone")
}
def on() {
parent.setZones(getZone() + ': "[brightness:100]"')
device.sendEvent(name: "switch", value: "on")
device.sendEvent(name: "level", value: 100)
}
def off() {
parent.setZones(getZone() + ': "[brightness:0]"')
device.sendEvent(name: "switch", value: "off")
device.sendEvent(name: "level", value: 0)
}
@SuppressWarnings("unused")
def setColor(Map colorMap) {
parent.setZones(getZone() + ': "[hue: ' + colorMap.hue + ', saturation: ' + colorMap.saturation + ', brightness: '+ colorMap.level + ']"')
device.sendEvent(name: "hue", value: colorMap.hue)
device.sendEvent(name: "saturation", value: colorMap.saturation)
device.sendEvent(name: "level", value: colorMap.level)
if (colorMap.level > 0) {
device.sendEvent(name: "switch", value: "on")
} else if (colorMap.level == 0) {
device.sendEvent(name: "switch", value: "off")
}
}
@SuppressWarnings("unused")
def setHue(hue) {
parent.setZones(getZone() + ': "[hue: ' + hue + ']"')
device.sendEvent(name: "hue", value: hue)
}
@SuppressWarnings("unused")
def setSaturation(saturation) {
parent.setZones(getZone() + ': "[saturation: ' + saturation + ']"')
device.sendEvent(name: "saturation", value: saturation)
}
@SuppressWarnings("unused")
def setColorTemperature(temperature) {
parent.setZones(getZone() + ': "[saturation: 0, kelvin: ' + temperature + ']"')
device.sendEvent(name: "colorTemperature", value: temperature)
device.sendEvent(name: "saturation", value: 0)
}
@SuppressWarnings("unused")
def setLevel(level, duration = 0) {
parent.setZones(getZone() + ': "[brightness: ' + level + ']"', duration)
device.sendEvent(name: "level", value: level)
}
def setState(value, duration = 0) {
parent.setZones(getZone() + ': "' + value + '"', duration)
}
def getUseActivityLog() {
if (state.useActivityLog == null) {
state.useActivityLog = true
}
return state.useActivityLog
}
def setUseActivityLog(value) {
log.debug("Setting useActivityLog to ${value ? 'true' : 'false'}")
state.useActivityLog = value
}
Boolean getUseActivityLogDebug() {
if (state.useActivityLogDebug == null) {
state.useActivityLogDebug = false
}
return state.useActivityLogDebug as Boolean
}
def setUseActivityLogDebug(value) {
log.debug("Setting useActivityLogDebug to ${value ? 'true' : 'false'}")
state.useActivityLogDebug = value
}
void logDebug(msg) {
if (getUseActivityLogDebug()) {
log.debug msg
}
}
void logInfo(msg) {
if (getUseActivityLog()) {
log.info msg
}
}
void logWarn(String msg) {
if (getUseActivityLog()) {
log.warn msg
}
}