forked from robheyes/lifxcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLIFXMultiZone.groovy
More file actions
154 lines (122 loc) · 3.79 KB
/
LIFXMultiZone.groovy
File metadata and controls
154 lines (122 loc) · 3.79 KB
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
/**
*
* Copyright 2018, 2019 Robert Heyes. All Rights Reserved
*
* This software if free for Private Use. You may use and modify the software without distributing it.
* You may not grant a sublicense to modify and distribute this software to third parties.
* Software is provided without warranty and your use of it is at your own risk.
*
*/
metadata {
definition(name: 'LIFX Multizone', namespace: 'robheyes', author: 'Robert Alan Heyes', importUrl: 'https://github.com/robheyes/lifxcode/master/LIFXMultiZone.groovy') {
capability 'Light'
capability 'ColorControl'
capability 'ColorTemperature'
capability 'Polling'
capability 'Initialize'
capability 'Switch'
attribute "label", "string"
attribute "group", "string"
attribute "location", "string"
}
preferences {
input 'logEnable', 'bool', title: 'Enable debug logging', required: false
}
}
@SuppressWarnings("unused")
def installed() {
initialize()
}
@SuppressWarnings("unused")
def updated() {
unsubscribe 'LIFX.MULTIZONEQUERY'
state.transitionTime = defaultTransition
initialize()
subscribe 'LIFX.MULTIZONEQUERY'
}
def initialize() {
requestInfo()
runEvery1Minute poll
}
@SuppressWarnings("unused")
def refresh() {
}
@SuppressWarnings("unused")
def poll() {
parent.lifxQuery (device, 'DEVICE.GET_POWER') { List buffer -> sendPacket buffer }
parent.lifxQuery (device, 'LIGHT.GET_STATE') { List buffer -> sendPacket buffer }
// parent.lifxQuery (device, 'MULTIZONE.GET_EXTENDED_COLOR_ZONES') { List buffer -> sendPacket buffer }
}
def requestInfo() {
parent.lifxQuery(device, 'LIGHT.GET_STATE') { List buffer -> sendPacket buffer }
}
def on() {
sendActions parent.deviceOnOff('on', getUseActivityLog(), state.transitionTime ?: 0)
}
def off() {
sendActions parent.deviceOnOff('off', getUseActivityLog(), state.transitionTime ?: 0)
}
@SuppressWarnings("unused")
def setColor(Map colorMap) {
}
@SuppressWarnings("unused")
def setHue(number) {
}
@SuppressWarnings("unused")
def setSaturation(number) {
}
@SuppressWarnings("unused")
def setColorTemperature(temperature) {
}
private void sendActions(Map<String, List> actions) {
actions.commands?.eachWithIndex { item, index -> parent.lifxCommand(device, item.cmd, item.payload, index as Byte) { List buffer -> sendPacket buffer } }
actions.events?.each { sendEvent it }
}
def parse(String description) {
List<Map> events = parent.parseForDevice(device, description, getUseActivityLog())
events.collect { createEvent(it) }
}
private String myIp() {
device.getDeviceNetworkId()
}
private void sendPacket(List buffer) {
String stringBytes = hubitat.helper.HexUtils.byteArrayToHexString parent.asByteArray(buffer)
sendHubCommand(
new hubitat.device.HubAction(
stringBytes,
hubitat.device.Protocol.LAN,
[
type : hubitat.device.HubAction.Type.LAN_TYPE_UDPCLIENT,
destinationAddress: myIp() + ":56700",
encoding : hubitat.device.HubAction.Encoding.HEX_STRING
]
)
)
}
def getUseActivityLog() {
if (state.useActivityLog == null) {
state.useActivityLog = true
}
return state.useActivityLog
}
def setUseActivityLog(value) {
state.useActivityLog = value
}
def getUseActivityLogDebug() {
if (state.useActivityLogDebug == null) {
state.useActivityLogDebug = false
}
return state.useActivityLogDebug
}
def setUseActivityLogDebug(value) {
state.useActivityLogDebug = value
}
void logDebug(msg) {
log.debug msg
}
void logInfo(msg) {
log.info msg
}
void logWarn(String msg) {
log.warn msg
}