homebridge-deconz 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config.schema.json +1 -1
- package/lib/Deconz/Resource.js +2 -2
- package/lib/DeconzAccessory/Gateway.js +1 -0
- package/lib/DeconzAccessory/Light.js +4 -2
- package/lib/DeconzAccessory/index.js +1 -2
- package/lib/DeconzPlatform.js +1 -1
- package/lib/DeconzService/DeviceSettings.js +1 -4
- package/lib/DeconzService/GatewaySettings.js +1 -4
- package/lib/DeconzService/Light.js +234 -175
- package/package.json +3 -3
package/config.schema.json
CHANGED
@@ -69,7 +69,7 @@
|
|
69
69
|
"maximum": 2000
|
70
70
|
},
|
71
71
|
"waitTimeUpdate": {
|
72
|
-
"description": "The time, in milliseconds, to wait for a change from HomeKit to another characteristic for the same light or group, before updating the deCONZ gateway. Default:
|
72
|
+
"description": "The time, in milliseconds, to wait for a change from HomeKit to another characteristic for the same light or group, before updating the deCONZ gateway. Default: 100.",
|
73
73
|
"type": "integer",
|
74
74
|
"minimum": 0,
|
75
75
|
"maximum": 500
|
package/lib/Deconz/Resource.js
CHANGED
@@ -161,8 +161,8 @@ class Resource {
|
|
161
161
|
*/
|
162
162
|
this.zigbee = true
|
163
163
|
} else {
|
164
|
-
this.subtype =
|
165
|
-
this.id = gateway.id + this.subtype
|
164
|
+
this.subtype = rtype[0].toUpperCase() + rid
|
165
|
+
this.id = gateway.id + '-' + this.subtype
|
166
166
|
this.zigbee = false
|
167
167
|
}
|
168
168
|
|
@@ -139,6 +139,7 @@ class Gateway extends homebridgeLib.AccessoryDelegate {
|
|
139
139
|
primaryService: true,
|
140
140
|
host: params.host
|
141
141
|
})
|
142
|
+
this.manageLogLevel(this.service.characteristicDelegate('logLevel'))
|
142
143
|
|
143
144
|
/** The service delegate for the Stateless Programmable Switch service.
|
144
145
|
* @type {DeconzService.Button}
|
@@ -33,12 +33,14 @@ class Light extends DeconzAccessory {
|
|
33
33
|
expose: true,
|
34
34
|
logLevel: gateway.logLevel
|
35
35
|
})
|
36
|
+
this.manageLogLevel(this.settingsService.characteristicDelegate('logLevel'))
|
36
37
|
|
37
38
|
this
|
38
39
|
.on('polled', (device) => {
|
39
|
-
this.debug(
|
40
|
+
this.debug(
|
41
|
+
'%s: polled: %j', device.rpaths.join(', '), device.resource.body
|
42
|
+
)
|
40
43
|
this.service.update(device.resource.body)
|
41
|
-
this.service.checkAdaptiveLighting()
|
42
44
|
})
|
43
45
|
.on('changed', (rpath, body) => {
|
44
46
|
if (rpath === device.resource.rpath) {
|
@@ -28,8 +28,7 @@ class DeconzAccessory extends homebridgeLib.AccessoryDelegate {
|
|
28
28
|
manufacturer: device.resource.manufacturer,
|
29
29
|
model: device.resource.model,
|
30
30
|
firmware: device.resource.firmware,
|
31
|
-
category: category
|
32
|
-
logLevel: gateway.logLevel
|
31
|
+
category: category
|
33
32
|
})
|
34
33
|
|
35
34
|
/** The gateway.
|
package/lib/DeconzPlatform.js
CHANGED
@@ -37,7 +37,7 @@ class DeconzPlatform extends homebridgeLib.Platform {
|
|
37
37
|
waitTimePutGroup: 1000,
|
38
38
|
waitTimeResend: 300,
|
39
39
|
waitTimeReset: 500,
|
40
|
-
waitTimeUpdate:
|
40
|
+
waitTimeUpdate: 100
|
41
41
|
}
|
42
42
|
const optionParser = new homebridgeLib.OptionParser(this.config, true)
|
43
43
|
optionParser
|
@@ -29,10 +29,7 @@ class DeviceSettings extends homebridgeLib.ServiceDelegate {
|
|
29
29
|
this.addCharacteristicDelegate({
|
30
30
|
key: 'logLevel',
|
31
31
|
Characteristic: this.Characteristics.my.LogLevel,
|
32
|
-
value: params.logLevel
|
33
|
-
silent: true
|
34
|
-
}).on('didSet', (value) => {
|
35
|
-
accessory.logLevel = value
|
32
|
+
value: params.logLevel
|
36
33
|
})
|
37
34
|
}
|
38
35
|
|
@@ -71,10 +71,7 @@ class GatewaySettings extends homebridgeLib.ServiceDelegate {
|
|
71
71
|
this.addCharacteristicDelegate({
|
72
72
|
key: 'logLevel',
|
73
73
|
Characteristic: this.Characteristics.my.LogLevel,
|
74
|
-
value: gateway.platform.logLevel
|
75
|
-
silent: true
|
76
|
-
}).on('didSet', (value) => {
|
77
|
-
gateway.logLevel = value
|
74
|
+
value: gateway.platform.logLevel
|
78
75
|
})
|
79
76
|
|
80
77
|
this.addCharacteristicDelegate({
|
@@ -40,20 +40,24 @@ class Light extends homebridgeLib.ServiceDelegate {
|
|
40
40
|
Characteristic: this.Characteristics.hap.On,
|
41
41
|
value: this.capabilities.on
|
42
42
|
? this.resource.body.state.on
|
43
|
-
: this.resource.body.state.all_on
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
: this.resource.body.state.all_on
|
44
|
+
}).on('didSet', (value, fromHomeKit) => {
|
45
|
+
if (fromHomeKit) {
|
46
|
+
this.put({ on: value })
|
47
|
+
this.updateAdaptiveLighting()
|
48
|
+
}
|
47
49
|
})
|
48
50
|
|
49
51
|
if (!this.capabilities.on) {
|
50
52
|
this.addCharacteristicDelegate({
|
51
53
|
key: 'anyOn',
|
52
54
|
Characteristic: this.Characteristics.my.AnyOn,
|
53
|
-
value: this.resource.body.state.any_on
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
value: this.resource.body.state.any_on
|
56
|
+
}).on('didSet', (value, fromHomeKit) => {
|
57
|
+
if (fromHomeKit) {
|
58
|
+
this.put({ on: value })
|
59
|
+
this.updateAdaptiveLighting()
|
60
|
+
}
|
57
61
|
})
|
58
62
|
}
|
59
63
|
|
@@ -62,23 +66,21 @@ class Light extends homebridgeLib.ServiceDelegate {
|
|
62
66
|
key: 'brightness',
|
63
67
|
Characteristic: this.Characteristics.hap.Brightness,
|
64
68
|
unit: '%',
|
65
|
-
value: this.resource.body.state.bri
|
66
|
-
|
69
|
+
value: this.resource.body.state.bri
|
70
|
+
}).on('didSet', (value, fromHomeKit) => {
|
71
|
+
if (fromHomeKit) {
|
67
72
|
const bri = Math.round(value * 254.0 / 100.0)
|
68
|
-
|
73
|
+
this.put({ bri: bri })
|
74
|
+
this.updateAdaptiveLighting()
|
69
75
|
}
|
70
|
-
}).on('didSet', (value, fromHomekit) => {
|
71
|
-
this.checkAdaptiveLighting()
|
72
76
|
})
|
73
77
|
|
74
78
|
this.addCharacteristicDelegate({
|
75
79
|
key: 'brightnessChange',
|
76
80
|
Characteristic: this.Characteristics.my.BrightnessChange,
|
77
|
-
value: 0
|
78
|
-
|
79
|
-
|
80
|
-
}
|
81
|
-
}).on('didSet', async () => {
|
81
|
+
value: 0
|
82
|
+
}).on('didSet', async (value) => {
|
83
|
+
this.put({ bri_inc: Math.round(value * 254.0 / 100.0) })
|
82
84
|
await timeout(this.platform.config.waitTimeReset)
|
83
85
|
this.values.brightnessChange = 0
|
84
86
|
})
|
@@ -88,7 +90,13 @@ class Light extends homebridgeLib.ServiceDelegate {
|
|
88
90
|
if (this.capabilities.ct || this.capabilities.xy || this.capabilities.hs) {
|
89
91
|
this.addCharacteristicDelegate({
|
90
92
|
key: 'colormode',
|
91
|
-
value: this.resource.body.state.colormode
|
93
|
+
value: this.resource.body.state.colormode,
|
94
|
+
silent: true
|
95
|
+
}).on('didSet', (value) => {
|
96
|
+
this.resource.body.colormode = value
|
97
|
+
if (value !== 'ct') {
|
98
|
+
this.checkAdaptiveLighting()
|
99
|
+
}
|
92
100
|
})
|
93
101
|
}
|
94
102
|
|
@@ -101,118 +109,70 @@ class Light extends homebridgeLib.ServiceDelegate {
|
|
101
109
|
minValue: this.capabilities.ctMin,
|
102
110
|
maxValue: this.capabilities.ctMax
|
103
111
|
},
|
104
|
-
value: this.resource.body.state.ct
|
105
|
-
setter: async (value) => {
|
106
|
-
const ct = Math.max(
|
107
|
-
this.capabilities.ctMin, Math.min(value, this.capabilities.ctMax)
|
108
|
-
)
|
109
|
-
return this.put({ ct: ct })
|
110
|
-
}
|
112
|
+
value: this.resource.body.state.ct
|
111
113
|
}).on('didSet', (value, fromHomeKit) => {
|
114
|
+
this.checkAdaptiveLighting()
|
115
|
+
const ct = Math.max(
|
116
|
+
this.capabilities.ctMin, Math.min(value, this.capabilities.ctMax)
|
117
|
+
)
|
112
118
|
if (fromHomeKit) {
|
113
|
-
this.
|
119
|
+
this.put({ ct: ct })
|
120
|
+
this.values.colormode = 'ct'
|
114
121
|
}
|
115
|
-
if (
|
116
|
-
|
117
|
-
this.values.colormode === 'ct'
|
118
|
-
) {
|
119
|
-
const { h, s } = xyToHsv(ctToXy(value), this.capabilities.gamut)
|
122
|
+
if (this.capabilities.xy && this.values.colormode === 'ct') {
|
123
|
+
const { h, s } = xyToHsv(ctToXy(ct), this.capabilities.gamut)
|
120
124
|
this.values.hue = h
|
121
125
|
this.values.saturation = s
|
122
126
|
}
|
123
127
|
})
|
124
|
-
|
125
|
-
if (this.capabilities.bri) {
|
126
|
-
this.addCharacteristicDelegate({
|
127
|
-
key: 'supportedTransitionConfiguration',
|
128
|
-
Characteristic: this.Characteristics.hap
|
129
|
-
.SupportedCharacteristicValueTransitionConfiguration,
|
130
|
-
silent: true
|
131
|
-
})
|
132
|
-
this.addCharacteristicDelegate({
|
133
|
-
key: 'transitionControl',
|
134
|
-
Characteristic: this.Characteristics.hap
|
135
|
-
.CharacteristicValueTransitionControl,
|
136
|
-
silent: true,
|
137
|
-
getter: async () => {
|
138
|
-
await this.initAdaptiveLighting()
|
139
|
-
return this.adaptiveLighting.generateControl()
|
140
|
-
},
|
141
|
-
setter: async (value) => {
|
142
|
-
await this.initAdaptiveLighting()
|
143
|
-
this.adaptiveLighting.parseControl(value)
|
144
|
-
const response = this.adaptiveLighting.generateControlResponse()
|
145
|
-
this.values.activeTransitionCount = 1
|
146
|
-
return response
|
147
|
-
}
|
148
|
-
})
|
149
|
-
this.addCharacteristicDelegate({
|
150
|
-
key: 'activeTransitionCount',
|
151
|
-
Characteristic: this.Characteristics.hap
|
152
|
-
.CharacteristicValueActiveTransitionCount,
|
153
|
-
value: 0
|
154
|
-
}).on('didSet', (value) => {
|
155
|
-
if (!value) {
|
156
|
-
this.adaptiveLighting.deactivate()
|
157
|
-
} else {
|
158
|
-
this.checkAdaptiveLighting()
|
159
|
-
}
|
160
|
-
})
|
161
|
-
}
|
162
128
|
}
|
163
129
|
|
164
130
|
if (this.capabilities.xy) {
|
165
131
|
this.addCharacteristicDelegate({
|
166
132
|
key: 'hue',
|
167
133
|
Characteristic: this.Characteristics.hap.Hue,
|
168
|
-
unit: '°'
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
this.values.
|
134
|
+
unit: '°'
|
135
|
+
}).on('didSet', (value, fromHomeKit) => {
|
136
|
+
if (fromHomeKit) {
|
137
|
+
const xy = hsvToXy(
|
138
|
+
value, this.values.saturation, this.capabilities.gamut
|
139
|
+
)
|
140
|
+
this.put({ xy: xy })
|
141
|
+
this.values.colormode = 'xy'
|
176
142
|
}
|
177
143
|
})
|
178
144
|
this.addCharacteristicDelegate({
|
179
145
|
key: 'saturation',
|
180
146
|
Characteristic: this.Characteristics.hap.Saturation,
|
181
|
-
unit: '%'
|
182
|
-
|
147
|
+
unit: '%'
|
148
|
+
}).on('didSet', (value, fromHomeKit) => {
|
149
|
+
if (fromHomeKit) {
|
183
150
|
const xy = hsvToXy(this.values.hue, value, this.capabilities.gamut)
|
184
|
-
|
185
|
-
|
186
|
-
}).on('didSet', (value, fromHomekit) => {
|
187
|
-
if (fromHomekit) {
|
188
|
-
this.values.activeTransitionCount = 0
|
151
|
+
this.put({ xy: xy })
|
152
|
+
this.values.colormode = 'xy'
|
189
153
|
}
|
190
154
|
})
|
191
155
|
} else if (this.capabilities.hs) {
|
192
156
|
this.addCharacteristicDelegate({
|
193
157
|
key: 'hue',
|
194
158
|
Characteristic: this.Characteristics.hap.Hue,
|
195
|
-
unit: '°'
|
196
|
-
|
159
|
+
unit: '°'
|
160
|
+
}).on('didSet', (value, fromHomeKit) => {
|
161
|
+
if (fromHomeKit) {
|
197
162
|
const hue = Math.round(this.hk.hue * 65535.0 / 360.0)
|
198
|
-
|
199
|
-
|
200
|
-
}).on('didSet', (value, fromHomekit) => {
|
201
|
-
if (fromHomekit) {
|
202
|
-
this.values.activeTransitionCount = 0
|
163
|
+
this.put({ hue: hue })
|
164
|
+
this.values.colormode = 'hs'
|
203
165
|
}
|
204
166
|
})
|
205
167
|
this.addCharacteristicDelegate({
|
206
168
|
key: 'saturation',
|
207
169
|
Characteristic: this.Characteristics.hap.Saturation,
|
208
|
-
unit: '%'
|
209
|
-
|
170
|
+
unit: '%'
|
171
|
+
}).on('didSet', (value, fromHomeKit) => {
|
172
|
+
if (fromHomeKit) {
|
210
173
|
const sat = Math.round(this.hk.sat * 254.0 / 100.0)
|
211
|
-
|
212
|
-
|
213
|
-
}).on('didSet', (value, fromHomekit) => {
|
214
|
-
if (fromHomekit) {
|
215
|
-
this.values.activeTransitionCount = 0
|
174
|
+
this.put({ sat: sat })
|
175
|
+
this.values.colormode = 'hs'
|
216
176
|
}
|
217
177
|
})
|
218
178
|
}
|
@@ -220,30 +180,36 @@ class Light extends homebridgeLib.ServiceDelegate {
|
|
220
180
|
if (this.capabilities.colorLoop) {
|
221
181
|
this.addCharacteristicDelegate({
|
222
182
|
key: 'colorLoop',
|
223
|
-
Characteristic: this.Characteristics.my.ColorLoop
|
224
|
-
|
183
|
+
Characteristic: this.Characteristics.my.ColorLoop
|
184
|
+
}).on('didSet', (value, fromHomeKit) => {
|
185
|
+
if (fromHomeKit) {
|
225
186
|
const effect = value ? 'colorloop' : 'none'
|
226
187
|
const state = { effect: effect }
|
227
188
|
if (value) {
|
228
189
|
state.colorloopspeed = this.values.colorLoopSpeed
|
229
190
|
}
|
230
|
-
|
191
|
+
this.put(state)
|
192
|
+
this.values.colormode = 'hs'
|
231
193
|
}
|
232
194
|
})
|
233
195
|
this.addCharacteristicDelegate({
|
234
196
|
key: 'colorLoopSpeed',
|
235
197
|
Characteristic: this.Characteristics.my.ColorLoopSpeed,
|
236
198
|
unit: 's',
|
237
|
-
value: 25
|
238
|
-
|
239
|
-
|
199
|
+
value: 25
|
200
|
+
}).on('didSet', (value, fromHomeKit) => {
|
201
|
+
if (fromHomeKit) {
|
202
|
+
const effect = 'colorloop'
|
203
|
+
this.put({ effect: effect, colorloopspeed: value })
|
204
|
+
this.values.colormode = 'hs'
|
240
205
|
}
|
241
206
|
})
|
242
207
|
}
|
243
208
|
|
244
209
|
this.addCharacteristicDelegate({
|
245
210
|
key: 'lastSeen',
|
246
|
-
Characteristic: this.Characteristics.my.LastSeen
|
211
|
+
Characteristic: this.Characteristics.my.LastSeen,
|
212
|
+
silent: true
|
247
213
|
})
|
248
214
|
|
249
215
|
this.addCharacteristicDelegate({
|
@@ -251,17 +217,65 @@ class Light extends homebridgeLib.ServiceDelegate {
|
|
251
217
|
Characteristic: this.Characteristics.hap.StatusFault
|
252
218
|
})
|
253
219
|
|
220
|
+
if (this.capabilities.bri && this.capabilities.ct && !this.capabilities.hs) {
|
221
|
+
this.addCharacteristicDelegate({
|
222
|
+
key: 'supportedTransitionConfiguration',
|
223
|
+
Characteristic: this.Characteristics.hap
|
224
|
+
.SupportedCharacteristicValueTransitionConfiguration,
|
225
|
+
silent: true
|
226
|
+
})
|
227
|
+
this.addCharacteristicDelegate({
|
228
|
+
key: 'transitionControl',
|
229
|
+
Characteristic: this.Characteristics.hap
|
230
|
+
.CharacteristicValueTransitionControl,
|
231
|
+
silent: true,
|
232
|
+
getter: async () => {
|
233
|
+
this.initAdaptiveLighting()
|
234
|
+
return this.adaptiveLighting.generateControl()
|
235
|
+
},
|
236
|
+
setter: async (value) => {
|
237
|
+
this.initAdaptiveLighting()
|
238
|
+
const control = this.adaptiveLighting.parseControl(value)
|
239
|
+
this.context.transitionControl = value
|
240
|
+
const response = this.adaptiveLighting.generateControlResponse()
|
241
|
+
const parsedResponse = this.adaptiveLighting.parseControl(response)
|
242
|
+
this.vdebug(
|
243
|
+
'Adaptive Lighting: control update: %j => %j',
|
244
|
+
control, parsedResponse
|
245
|
+
)
|
246
|
+
this.values.activeTransitionCount = parsedResponse === '' ? 0 : 1
|
247
|
+
return response
|
248
|
+
}
|
249
|
+
})
|
250
|
+
this.addCharacteristicDelegate({
|
251
|
+
key: 'activeTransitionCount',
|
252
|
+
Characteristic: this.Characteristics.hap
|
253
|
+
.CharacteristicValueActiveTransitionCount,
|
254
|
+
silent: true,
|
255
|
+
value: 0
|
256
|
+
}).on('didSet', (value) => {
|
257
|
+
this.log('Adaptive Lighting: %sabled', value > 0 ? 'en' : 'dis')
|
258
|
+
if (value) {
|
259
|
+
this.updateAdaptiveLighting()
|
260
|
+
}
|
261
|
+
})
|
262
|
+
if (this.values.supportedTransitionConfiguration != null) {
|
263
|
+
this.initAdaptiveLighting()
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
254
267
|
this.settings = {
|
255
268
|
brightnessAdjustment: 1,
|
256
269
|
resetTimeout: this.platform.config.resetTimeout,
|
257
270
|
waitTimeUpdate: this.platform.config.waitTimeUpdate,
|
258
271
|
wallSwitch: false
|
259
272
|
}
|
260
|
-
|
261
|
-
this.update(this.resource.body)
|
262
273
|
}
|
263
274
|
|
264
275
|
update (body) {
|
276
|
+
if (this.updating) {
|
277
|
+
return
|
278
|
+
}
|
265
279
|
for (const key in body) {
|
266
280
|
const value = body[key]
|
267
281
|
switch (key) {
|
@@ -275,6 +289,7 @@ class Light extends homebridgeLib.ServiceDelegate {
|
|
275
289
|
// this.values.lastBoot = dateToString(value)
|
276
290
|
break
|
277
291
|
case 'lastseen':
|
292
|
+
this.resource.body.lastseen = value
|
278
293
|
this.values.lastSeen = dateToString(value)
|
279
294
|
break
|
280
295
|
case 'colorcapabilities':
|
@@ -302,25 +317,34 @@ class Light extends homebridgeLib.ServiceDelegate {
|
|
302
317
|
}
|
303
318
|
|
304
319
|
updateState (state) {
|
320
|
+
let updateAdaptiveLighting = false
|
305
321
|
for (const key in state) {
|
306
322
|
const value = state[key]
|
323
|
+
this.resource.body.state[key] = value
|
307
324
|
switch (key) {
|
308
325
|
case 'all_on':
|
309
326
|
this.values.on = value
|
327
|
+
updateAdaptiveLighting = true
|
310
328
|
break
|
311
329
|
case 'any_on':
|
312
330
|
this.values.anyOn = value
|
331
|
+
updateAdaptiveLighting = true
|
313
332
|
break
|
314
333
|
case 'alert':
|
315
334
|
break
|
316
335
|
case 'bri':
|
317
|
-
|
336
|
+
if (!this.recentlyUpdated) {
|
337
|
+
this.values.brightness = Math.round(value * 100.0 / 254.0)
|
338
|
+
updateAdaptiveLighting = true
|
339
|
+
}
|
318
340
|
break
|
319
341
|
case 'colormode':
|
320
342
|
this.values.colormode = value
|
321
343
|
break
|
322
344
|
case 'ct':
|
323
|
-
this.values.
|
345
|
+
if (!this.recentlyUpdated && this.values.colormode === 'ct') {
|
346
|
+
this.values.colorTemperature = value
|
347
|
+
}
|
324
348
|
break
|
325
349
|
case 'effect':
|
326
350
|
break
|
@@ -345,7 +369,10 @@ class Light extends homebridgeLib.ServiceDelegate {
|
|
345
369
|
case 'scene':
|
346
370
|
break
|
347
371
|
case 'xy':
|
348
|
-
if (
|
372
|
+
if (
|
373
|
+
!this.recentlyUpdated &&
|
374
|
+
(this.values.colormode !== 'ct' || this.capabilities.computesXy)
|
375
|
+
) {
|
349
376
|
const { h, s } = xyToHsv(value, this.capabilities.gamut)
|
350
377
|
this.values.hue = h
|
351
378
|
this.values.saturation = s
|
@@ -356,113 +383,145 @@ class Light extends homebridgeLib.ServiceDelegate {
|
|
356
383
|
break
|
357
384
|
}
|
358
385
|
}
|
386
|
+
if (updateAdaptiveLighting) {
|
387
|
+
this.updateAdaptiveLighting()
|
388
|
+
}
|
359
389
|
}
|
360
390
|
|
361
391
|
async identify () {
|
362
392
|
try {
|
363
393
|
if (this.capabilities.alert) {
|
364
394
|
if (this.capabilities.breathe) {
|
365
|
-
await this.put({ alert: 'breathe' })
|
395
|
+
await this.client.put({ alert: 'breathe' })
|
366
396
|
await timeout(1500)
|
367
|
-
return this.put({ alert: 'stop' })
|
397
|
+
return this.client.put({ alert: 'stop' })
|
368
398
|
}
|
369
399
|
return this.put({ alert: 'select' })
|
370
400
|
}
|
371
|
-
} catch (error) {
|
401
|
+
} catch (error) {
|
402
|
+
if (!(error instanceof Deconz.ApiClient.HttpError)) {
|
403
|
+
this.warn(error)
|
404
|
+
}
|
405
|
+
}
|
372
406
|
}
|
373
407
|
|
374
|
-
|
408
|
+
initAdaptiveLighting () {
|
375
409
|
if (this.adaptiveLighting == null) {
|
376
410
|
this.adaptiveLighting = new homebridgeLib.AdaptiveLighting(
|
377
411
|
this.brightnessDelegate, this.colorTemperatureDelegate
|
378
412
|
)
|
379
413
|
this.values.supportedTransitionConfiguration =
|
380
414
|
this.adaptiveLighting.generateConfiguration()
|
381
|
-
if (
|
382
|
-
this.
|
383
|
-
|
384
|
-
|
385
|
-
this.
|
415
|
+
if (this.values.activeTransitionCount > 0) {
|
416
|
+
const control = this.adaptiveLighting.parseControl(
|
417
|
+
this.context.transitionControl
|
418
|
+
)
|
419
|
+
this.vdebug('Adaptive Lighting: restore control: %j', control)
|
420
|
+
this.adaptiveLighting.parseControl(this.context.transitionControl)
|
386
421
|
}
|
422
|
+
this.log(
|
423
|
+
'Adaptive Lighting: %sabled',
|
424
|
+
this.values.activeTransitionCount > 0 ? 'en' : 'dis'
|
425
|
+
)
|
387
426
|
}
|
388
427
|
}
|
389
428
|
|
390
|
-
async
|
391
|
-
if (
|
429
|
+
async updateAdaptiveLighting () {
|
430
|
+
if (
|
431
|
+
this.adaptiveLighting == null || // not supported
|
432
|
+
this.values.activeTransitionCount === 0 || // disabled
|
433
|
+
!this.values.on // light is off
|
434
|
+
) {
|
392
435
|
return
|
393
436
|
}
|
394
437
|
const ct = this.adaptiveLighting.getCt(
|
395
438
|
this.values.brightness * this.settings.brightnessAdjustment
|
396
439
|
)
|
397
|
-
if (ct == null
|
440
|
+
if (ct == null) {
|
441
|
+
this.warn('assertion failed')
|
442
|
+
return
|
443
|
+
}
|
444
|
+
this.debug(
|
445
|
+
'/%s/%d: adaptive lighting: {"state":{"ct": %d}}',
|
446
|
+
this.rtype, this.rid, ct
|
447
|
+
)
|
448
|
+
if (this.values.colormode === 'ct' && ct === this.values.colorTemperature) {
|
449
|
+
return
|
450
|
+
}
|
451
|
+
this.put({ ct: ct })
|
452
|
+
this.fromAdaptiveLighting = true
|
453
|
+
this.values.colormode = 'ct'
|
454
|
+
if (ct !== this.values.colorTemperature) {
|
455
|
+
this.values.colorTemperature = ct
|
456
|
+
} else if (this.capabilities.xy) { // colormode changed
|
457
|
+
const { h, s } = xyToHsv(ctToXy(ct), this.capabilities.gamut)
|
458
|
+
this.values.hue = h
|
459
|
+
this.values.saturation = s
|
460
|
+
}
|
461
|
+
this.fromAdaptiveLighting = false
|
462
|
+
}
|
463
|
+
|
464
|
+
checkAdaptiveLighting (key, value) {
|
465
|
+
if (this.fromAdaptiveLighting) {
|
398
466
|
return
|
399
467
|
}
|
400
|
-
|
468
|
+
this.adaptiveLighting.deactivate()
|
469
|
+
this.values.activeTransitionCount = 0
|
401
470
|
}
|
402
471
|
|
403
472
|
// Collect changes into a combined request.
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
473
|
+
put (state) {
|
474
|
+
for (const key in state) {
|
475
|
+
this.resource.body.state[key] = state[key]
|
476
|
+
this.targetState[key] = state[key]
|
477
|
+
}
|
478
|
+
this._put()
|
479
|
+
}
|
480
|
+
|
481
|
+
// Send the request (for the combined changes) to the gateway.
|
482
|
+
async _put () {
|
483
|
+
try {
|
411
484
|
if (this.updating) {
|
412
485
|
return
|
413
486
|
}
|
414
487
|
this.updating = true
|
415
488
|
if (this.settings.waitTimeUpdate > 0) {
|
416
|
-
|
417
|
-
this._put()
|
418
|
-
}, this.settings.waitTimeUpdate)
|
419
|
-
} else {
|
420
|
-
this._put()
|
489
|
+
await timeout(this.settings.waitTimeUpdate)
|
421
490
|
}
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
// Send the request (for the combined changes) to the gateway.
|
426
|
-
async _put () {
|
427
|
-
const targetState = this.targetState
|
428
|
-
const deferrals = this.deferrals
|
429
|
-
this.targetState = {}
|
430
|
-
this.deferrals = []
|
431
|
-
this.updating = false
|
432
|
-
if (
|
433
|
-
this.gateway.transitionTime !== this.gateway.defaultTransitionTime &&
|
434
|
-
targetState.transitiontime === undefined
|
435
|
-
) {
|
436
|
-
targetState.transitiontime = this.gateway.transitionTime * 10
|
437
|
-
this.gateway.resetTransitionTime()
|
438
|
-
}
|
439
|
-
if (this.capabilities.noTransition) {
|
491
|
+
const targetState = this.targetState
|
492
|
+
this.targetState = {}
|
493
|
+
this.updating = false
|
440
494
|
if (
|
441
|
-
|
442
|
-
|
443
|
-
targetState.bri_inc != null
|
444
|
-
) && (
|
445
|
-
targetState.xy != null || targetState.ct != null ||
|
446
|
-
targetState.hue != null || targetState.sat != null ||
|
447
|
-
targetState.effect != null
|
448
|
-
)
|
495
|
+
this.gateway.transitionTime !== this.gateway.defaultTransitionTime &&
|
496
|
+
targetState.transitiontime === undefined
|
449
497
|
) {
|
450
|
-
targetState.transitiontime =
|
498
|
+
targetState.transitiontime = this.gateway.transitionTime * 10
|
499
|
+
this.gateway.resetTransitionTime()
|
451
500
|
}
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
501
|
+
if (this.capabilities.noTransition) {
|
502
|
+
if (
|
503
|
+
(
|
504
|
+
targetState.on != null || targetState.bri != null ||
|
505
|
+
targetState.bri_inc != null
|
506
|
+
) && (
|
507
|
+
targetState.xy != null || targetState.ct != null ||
|
508
|
+
targetState.hue != null || targetState.sat != null ||
|
509
|
+
targetState.effect != null
|
510
|
+
)
|
511
|
+
) {
|
512
|
+
targetState.transitiontime = 0
|
513
|
+
}
|
457
514
|
}
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
515
|
+
this.debug('PUT %s %j', this.rpath, targetState)
|
516
|
+
await this.client.put(this.rpath, targetState)
|
517
|
+
this.recentlyUpdated = true
|
518
|
+
await timeout(500)
|
519
|
+
this.recentlyUpdated = false
|
520
|
+
} catch (error) {
|
521
|
+
if (!(error instanceof Deconz.ApiClient.HttpError)) {
|
522
|
+
this.warn(error)
|
464
523
|
}
|
465
|
-
}
|
524
|
+
}
|
466
525
|
}
|
467
526
|
}
|
468
527
|
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
"displayName": "Homebridge deCONZ",
|
5
5
|
"author": "Erik Baauw",
|
6
6
|
"license": "Apache-2.0",
|
7
|
-
"version": "0.0.
|
7
|
+
"version": "0.0.10",
|
8
8
|
"keywords": [
|
9
9
|
"homebridge-plugin",
|
10
10
|
"homekit",
|
@@ -21,11 +21,11 @@
|
|
21
21
|
},
|
22
22
|
"engines": {
|
23
23
|
"deCONZ": "2.13.4",
|
24
|
-
"homebridge": "^1.
|
24
|
+
"homebridge": "^1.4.0",
|
25
25
|
"node": "^16.13.2"
|
26
26
|
},
|
27
27
|
"dependencies": {
|
28
|
-
"homebridge-lib": "~5.
|
28
|
+
"homebridge-lib": "~5.2.0",
|
29
29
|
"semver": "^7.3.5",
|
30
30
|
"ws": "^8.4.2",
|
31
31
|
"xml2js": "~0.4.23"
|