homebridge-deconz 0.0.10 → 0.0.11
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/cli/deconz.js +12 -0
- package/lib/Deconz/ApiClient.js +34 -1
- package/lib/Deconz/ApiResponse.js +1 -1
- package/lib/Deconz/Device.js +0 -7
- package/lib/Deconz/Resource.js +749 -24
- package/lib/DeconzAccessory/Contact.js +54 -0
- package/lib/DeconzAccessory/Gateway.js +83 -61
- package/lib/DeconzAccessory/Light.js +42 -37
- package/lib/DeconzAccessory/Motion.js +51 -0
- package/lib/DeconzAccessory/Sensor.js +35 -0
- package/lib/DeconzAccessory/Temperature.js +63 -0
- package/lib/DeconzAccessory/Thermostat.js +50 -0
- package/lib/DeconzAccessory/WarningDevice.js +56 -0
- package/lib/DeconzAccessory/WindowCovering.js +47 -0
- package/lib/DeconzAccessory/index.js +142 -2
- package/lib/DeconzPlatform.js +5 -0
- package/lib/DeconzService/AirPressure.js +43 -0
- package/lib/DeconzService/AirQuality.js +17 -10
- package/lib/DeconzService/Alarm.js +13 -9
- package/lib/DeconzService/Battery.js +43 -0
- package/lib/DeconzService/Button.js +9 -2
- package/lib/DeconzService/CarbonMonoxide.js +38 -0
- package/lib/DeconzService/Consumption.js +65 -0
- package/lib/DeconzService/Contact.js +60 -0
- package/lib/DeconzService/Daylight.js +132 -0
- package/lib/DeconzService/DeviceSettings.js +11 -0
- package/lib/DeconzService/Flag.js +52 -0
- package/lib/DeconzService/Humidity.js +37 -0
- package/lib/DeconzService/Leak.js +38 -0
- package/lib/DeconzService/Light.js +12 -164
- package/lib/DeconzService/LightLevel.js +54 -0
- package/lib/DeconzService/LightsResource.js +112 -0
- package/lib/DeconzService/Motion.js +101 -0
- package/lib/DeconzService/Outlet.js +76 -0
- package/lib/DeconzService/Power.js +83 -0
- package/lib/DeconzService/SensorsResource.js +96 -0
- package/lib/DeconzService/Smoke.js +38 -0
- package/lib/DeconzService/Status.js +53 -0
- package/lib/DeconzService/Switch.js +93 -0
- package/lib/DeconzService/Temperature.js +63 -0
- package/lib/DeconzService/Thermostat.js +175 -0
- package/lib/DeconzService/WarningDevice.js +68 -0
- package/lib/DeconzService/WindowCovering.js +139 -0
- package/lib/DeconzService/index.js +76 -25
- package/package.json +2 -2
- package/lib/DeconzAccessory/Device.js +0 -69
- package/lib/DeconzService/Sensor.js +0 -61
@@ -0,0 +1,54 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzAccessory/Contact.js
|
2
|
+
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
|
+
//
|
4
|
+
// Homebridge plugin for deCONZ.
|
5
|
+
|
6
|
+
'use strict'
|
7
|
+
|
8
|
+
const homebridgeLib = require('homebridge-lib')
|
9
|
+
const DeconzAccessory = require('../DeconzAccessory')
|
10
|
+
|
11
|
+
const { History } = homebridgeLib.ServiceDelegate
|
12
|
+
|
13
|
+
/** Delegate class for a HomeKit accessory corresponding to a contact sensor,
|
14
|
+
* with Eve Door & Window history.
|
15
|
+
* @extends DeconzAccessory
|
16
|
+
* @memberof DeconzAccessory
|
17
|
+
*/
|
18
|
+
class Contact extends DeconzAccessory {
|
19
|
+
/** Instantiate a contact sensor delegate.
|
20
|
+
* @param {DeconzAccessory.Gateway} gateway - The gateway.
|
21
|
+
* @param {Deconz.Device} device - The device.
|
22
|
+
*/
|
23
|
+
constructor (gateway, device) {
|
24
|
+
super(gateway, device, gateway.Accessory.Categories.SENSOR)
|
25
|
+
|
26
|
+
this.identify()
|
27
|
+
|
28
|
+
this.service = this.createService(device.resource, { primaryService: true })
|
29
|
+
|
30
|
+
for (const subtype in device.resourceBySubtype) {
|
31
|
+
const resource = device.resourceBySubtype[subtype]
|
32
|
+
if (subtype === device.primary) {
|
33
|
+
continue
|
34
|
+
}
|
35
|
+
this.createService(resource)
|
36
|
+
}
|
37
|
+
|
38
|
+
this.historyService = new History.Contact(
|
39
|
+
this, {},
|
40
|
+
this.service.characteristicDelegate('contact'),
|
41
|
+
this.service.characteristicDelegate('timesOpened'),
|
42
|
+
this.service.characteristicDelegate('lastActivation')
|
43
|
+
)
|
44
|
+
|
45
|
+
this.createSettingsService()
|
46
|
+
|
47
|
+
setImmediate(() => {
|
48
|
+
this.debug('initialised')
|
49
|
+
this.emit('initialised')
|
50
|
+
})
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
module.exports = Contact
|
@@ -8,7 +8,7 @@
|
|
8
8
|
const homebridgeLib = require('homebridge-lib')
|
9
9
|
|
10
10
|
const Deconz = require('../Deconz')
|
11
|
-
const DeconzAccessory = require('
|
11
|
+
const DeconzAccessory = require('../DeconzAccessory')
|
12
12
|
const DeconzService = require('../DeconzService')
|
13
13
|
|
14
14
|
const rtypes = ['lights', 'sensors', 'groups']
|
@@ -20,8 +20,6 @@ const periodicEvents = [
|
|
20
20
|
]
|
21
21
|
|
22
22
|
/** Delegate class for a deCONZ gateway.
|
23
|
-
*
|
24
|
-
* @class
|
25
23
|
* @extends AccessoryDelegate
|
26
24
|
* @memberof DeconzAccessory
|
27
25
|
*/
|
@@ -41,7 +39,7 @@ class Gateway extends homebridgeLib.AccessoryDelegate {
|
|
41
39
|
model: params.config.modelid + ' / ' + params.config.devicename,
|
42
40
|
firmware: '0.0.0',
|
43
41
|
software: params.config.swversion,
|
44
|
-
category: platform.Accessory.Categories.
|
42
|
+
category: platform.Accessory.Categories.BRIDGE
|
45
43
|
})
|
46
44
|
|
47
45
|
this.gateway = this
|
@@ -62,6 +60,9 @@ class Gateway extends homebridgeLib.AccessoryDelegate {
|
|
62
60
|
if (this.context.blacklist == null) {
|
63
61
|
this.context.blacklist = {}
|
64
62
|
}
|
63
|
+
if (this.context.fullState != null) {
|
64
|
+
this.analyseFullState(this.context.fullState, { analyseOnly: true })
|
65
|
+
}
|
65
66
|
|
66
67
|
this.addPropertyDelegate({
|
67
68
|
key: 'apiKey',
|
@@ -215,9 +216,14 @@ class Gateway extends homebridgeLib.AccessoryDelegate {
|
|
215
216
|
try {
|
216
217
|
this.debug('initialising...')
|
217
218
|
this.initialBeat = beat
|
218
|
-
if (this.context.fullState != null) {
|
219
|
-
|
220
|
-
|
219
|
+
// if (this.context.fullState != null) {
|
220
|
+
// this.analyseFullState(this.context.fullState, { logUnsupported: true })
|
221
|
+
// for (const id of this.restoredAccessories) {
|
222
|
+
// try {
|
223
|
+
// this.addAccessory(id)
|
224
|
+
// } catch (error) { this.error(error) }
|
225
|
+
// }
|
226
|
+
// }
|
221
227
|
await this.connect()
|
222
228
|
this.initialised = true
|
223
229
|
this.debug('initialised')
|
@@ -461,6 +467,7 @@ class Gateway extends homebridgeLib.AccessoryDelegate {
|
|
461
467
|
this.service.values.sensors = false
|
462
468
|
this.service.values.groups = false
|
463
469
|
this.service.values.schedules = false
|
470
|
+
this.service.values.logLevel = 2
|
464
471
|
this.values.rtypes = []
|
465
472
|
} catch (error) { this.error(error) }
|
466
473
|
}
|
@@ -504,12 +511,12 @@ class Gateway extends homebridgeLib.AccessoryDelegate {
|
|
504
511
|
if (this.accessoryById[id] == null) {
|
505
512
|
const device = this.deviceById[id]
|
506
513
|
delete this.exposeErrorById[id]
|
507
|
-
const { body
|
514
|
+
const { body } = device.resource
|
508
515
|
this.log('%s: add accessory', body.name)
|
509
516
|
let { serviceName } = device.resource
|
510
517
|
if (DeconzAccessory[serviceName] == null) {
|
511
|
-
this.warn('%s: %s: not yet supported %s type', body.name, body.type, rtype)
|
512
|
-
serviceName = '
|
518
|
+
// this.warn('%s: %s: not yet supported %s type', body.name, body.type, rtype)
|
519
|
+
serviceName = 'Sensor'
|
513
520
|
}
|
514
521
|
const accessory = new DeconzAccessory[serviceName](this, device)
|
515
522
|
this.accessoryById[id] = accessory
|
@@ -593,6 +600,9 @@ class Gateway extends homebridgeLib.AccessoryDelegate {
|
|
593
600
|
throw new RangeError(`${id}: unknown device ID`)
|
594
601
|
}
|
595
602
|
if (this.serviceById[id] == null) {
|
603
|
+
if (Object.keys(this.serviceById).length >= 97) {
|
604
|
+
return null
|
605
|
+
}
|
596
606
|
const { resource, rpaths } = this.deviceById[id]
|
597
607
|
const { body } = resource
|
598
608
|
const service = new DeconzService.DeviceSettings(this, {
|
@@ -698,12 +708,12 @@ class Gateway extends homebridgeLib.AccessoryDelegate {
|
|
698
708
|
* accessories, corresponding to devices have been blacklisted.
|
699
709
|
* @param {Object} fullState - The gateway full state, as returned by
|
700
710
|
* {@link DeconzAccessory.Gateway#poll poll()}.
|
701
|
-
* @param {
|
702
|
-
*
|
711
|
+
* @param {Object} params - Parameters
|
712
|
+
* @param {boolean} [params.logUnsupportedResources=false] - Issue debug
|
713
|
+
* messsages for unsupported resources.
|
714
|
+
* @param {boolean} [params.analyseOnly=false]
|
703
715
|
*/
|
704
|
-
analyseFullState (fullState,
|
705
|
-
this.update(fullState.config)
|
706
|
-
|
716
|
+
analyseFullState (fullState, params = {}) {
|
707
717
|
/** Supported devices by device ID.
|
708
718
|
*
|
709
719
|
* Updated by
|
@@ -740,8 +750,10 @@ class Gateway extends homebridgeLib.AccessoryDelegate {
|
|
740
750
|
for (const rtype of rtypes) {
|
741
751
|
this.deviceByRidByRtype[rtype] = {}
|
742
752
|
for (const rid in fullState[rtype]) {
|
743
|
-
|
744
|
-
|
753
|
+
try {
|
754
|
+
const body = fullState[rtype][rid]
|
755
|
+
this.analyseResource(rtype, rid, body, params.logUnsupported)
|
756
|
+
} catch (error) { this.error(error) }
|
745
757
|
}
|
746
758
|
}
|
747
759
|
|
@@ -774,64 +786,74 @@ class Gateway extends homebridgeLib.AccessoryDelegate {
|
|
774
786
|
this.vdebug('%d %s devices', this.nDevicesByRtype[rtype], rtype)
|
775
787
|
}
|
776
788
|
|
789
|
+
if (params.analyseOnly) {
|
790
|
+
return
|
791
|
+
}
|
792
|
+
|
793
|
+
this.update(fullState.config)
|
794
|
+
|
777
795
|
let changed = false
|
778
796
|
|
779
797
|
this.vdebug('analysing accessories...')
|
780
798
|
for (const id in this.accessoryById) {
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
799
|
+
try {
|
800
|
+
if (
|
801
|
+
this.deviceById[id] == null
|
802
|
+
) {
|
803
|
+
delete this.context.blacklist[id]
|
804
|
+
this.deleteAccessory(id)
|
805
|
+
this.deleteService(id)
|
806
|
+
changed = true
|
807
|
+
} else {
|
808
|
+
/** Emitted when the gateway has been polled.
|
809
|
+
* @event DeconzAccessory.Device#polled
|
810
|
+
* @param {Deconz.Device} device - The updated device.
|
811
|
+
*/
|
812
|
+
this.accessoryById[id].emit('polled', this.deviceById[id])
|
813
|
+
}
|
814
|
+
} catch (error) { this.error(error) }
|
796
815
|
}
|
797
816
|
|
798
817
|
this.vdebug('analysing services...')
|
799
818
|
for (const id in this.serviceById) {
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
819
|
+
try {
|
820
|
+
if (
|
821
|
+
this.deviceById[id] == null ||
|
822
|
+
!this.values.rtypes.includes(this.deviceById[id].resource.rtype)
|
823
|
+
) {
|
824
|
+
delete this.exposeErrorById[id]
|
825
|
+
this.deleteService(id)
|
826
|
+
changed = true
|
827
|
+
}
|
828
|
+
} catch (error) { this.error(error) }
|
809
829
|
}
|
810
830
|
|
811
831
|
for (const rtype of this.values.rtypes) {
|
812
832
|
this.vdebug('analysing %s devices...', rtype)
|
813
833
|
const rids = Object.keys(this.deviceByRidByRtype[rtype]).sort()
|
814
834
|
for (const rid of rids) {
|
815
|
-
|
816
|
-
|
817
|
-
if (this.
|
818
|
-
this.
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
this.
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
this.
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
this.
|
832
|
-
|
835
|
+
try {
|
836
|
+
const { id } = this.deviceByRidByRtype[rtype][rid]
|
837
|
+
if (this.context.blacklist[id] == null) {
|
838
|
+
if (this.accessoryById[id] == null) {
|
839
|
+
this.addAccessory(id)
|
840
|
+
changed = true
|
841
|
+
}
|
842
|
+
if (this.serviceById[id] != null) {
|
843
|
+
this.deleteService(id)
|
844
|
+
changed = true
|
845
|
+
}
|
846
|
+
} else {
|
847
|
+
if (this.serviceById[id] == null) {
|
848
|
+
this.addService(id)
|
849
|
+
changed = true
|
850
|
+
}
|
851
|
+
if (this.accessoryById[id] != null) {
|
852
|
+
this.deleteAccessory(id)
|
853
|
+
changed = true
|
854
|
+
}
|
833
855
|
}
|
834
|
-
}
|
856
|
+
} catch (error) { this.error(error) }
|
835
857
|
}
|
836
858
|
}
|
837
859
|
|
@@ -862,7 +884,7 @@ class Gateway extends homebridgeLib.AccessoryDelegate {
|
|
862
884
|
* `groups`, `lights`, or `sensors`.
|
863
885
|
* @param {integer} rid - The resource ID of the resource.
|
864
886
|
* @param {object} body - The body of the resource.
|
865
|
-
* @param {boolean}
|
887
|
+
* @param {boolean} logUnsupported - Issue a debug message for
|
866
888
|
* unsupported resources.
|
867
889
|
*/
|
868
890
|
analyseResource (rtype, rid, body, logUnsupported) {
|
@@ -1,16 +1,17 @@
|
|
1
|
-
// homebridge-deconz/lib/DeconzAccessory/
|
1
|
+
// homebridge-deconz/lib/DeconzAccessory/Light.js
|
2
2
|
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
3
|
//
|
4
4
|
// Homebridge plugin for deCONZ.
|
5
5
|
|
6
6
|
'use strict'
|
7
7
|
|
8
|
-
const
|
9
|
-
const
|
8
|
+
const homebridgeLib = require('homebridge-lib')
|
9
|
+
const DeconzAccessory = require('../DeconzAccessory')
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
const { History } = homebridgeLib.ServiceDelegate
|
12
|
+
|
13
|
+
/** Delegate class for a HomeKit accessory, corresponding to a light device
|
14
|
+
* or groups resource.
|
14
15
|
* @extends DeconzAccessory
|
15
16
|
* @memberof DeconzAccessory
|
16
17
|
*/
|
@@ -19,49 +20,53 @@ class Light extends DeconzAccessory {
|
|
19
20
|
* @param {DeconzAccessory.Gateway} gateway - The gateway.
|
20
21
|
* @param {Deconz.Device} device - The device.
|
21
22
|
*/
|
22
|
-
constructor (gateway, device) {
|
23
|
-
super(gateway, device)
|
23
|
+
constructor (gateway, device, settings = {}) {
|
24
|
+
super(gateway, device, gateway.Accessory.Categories.LIGHTBULB)
|
24
25
|
|
25
26
|
this.identify()
|
26
27
|
|
27
|
-
this.
|
28
|
+
this.addPropertyDelegate({
|
29
|
+
key: 'serviceName',
|
30
|
+
value: device.resource.capabilities.bri ? 'Light' : 'Outlet'
|
31
|
+
})
|
28
32
|
|
29
|
-
this.
|
30
|
-
|
31
|
-
|
32
|
-
resource: this.device.rpaths.join(', '),
|
33
|
-
expose: true,
|
34
|
-
logLevel: gateway.logLevel
|
33
|
+
this.service = this.createService(device.resource, {
|
34
|
+
primaryService: true,
|
35
|
+
serviceName: this.values.serviceName
|
35
36
|
})
|
36
|
-
this.manageLogLevel(this.settingsService.characteristicDelegate('logLevel'))
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
.
|
38
|
+
for (const subtype in device.resourceBySubtype) {
|
39
|
+
const resource = device.resourceBySubtype[subtype]
|
40
|
+
if (subtype === device.primary) {
|
41
|
+
continue
|
42
|
+
}
|
43
|
+
if (resource.rtype === 'lights') {
|
44
|
+
this.createService(resource, { serviceName: this.values.serviceName })
|
45
|
+
} else {
|
46
|
+
this.createService(resource)
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
if (this.serviceByServiceName.Consumption != null) {
|
51
|
+
this.historyService = new History.Consumption(
|
52
|
+
this, {},
|
53
|
+
this.serviceByServiceName.Consumption.characteristicDelegate('totalConsumption'),
|
54
|
+
this.serviceByServiceName.Consumption.characteristicDelegate('currentConsumption')
|
55
|
+
)
|
56
|
+
} else if (this.serviceByServiceName.Power != null) {
|
57
|
+
this.historyService = new History.Power(
|
58
|
+
this, {},
|
59
|
+
this.serviceByServiceName.Power.characteristicDelegate('currentConsumption')
|
60
|
+
)
|
61
|
+
}
|
62
|
+
|
63
|
+
this.createSettingsService()
|
52
64
|
|
53
65
|
setImmediate(() => {
|
54
66
|
this.debug('initialised')
|
55
67
|
this.emit('initialised')
|
56
68
|
})
|
57
69
|
}
|
58
|
-
|
59
|
-
async identify () {
|
60
|
-
super.identify()
|
61
|
-
if (this.service != null) {
|
62
|
-
await this.service.identify()
|
63
|
-
}
|
64
|
-
}
|
65
70
|
}
|
66
71
|
|
67
72
|
module.exports = Light
|
@@ -0,0 +1,51 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzAccessory/Motion.js
|
2
|
+
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
|
+
//
|
4
|
+
// Homebridge plugin for deCONZ.
|
5
|
+
|
6
|
+
'use strict'
|
7
|
+
|
8
|
+
const homebridgeLib = require('homebridge-lib')
|
9
|
+
const DeconzAccessory = require('../DeconzAccessory')
|
10
|
+
|
11
|
+
const { History } = homebridgeLib.ServiceDelegate
|
12
|
+
|
13
|
+
class Motion extends DeconzAccessory {
|
14
|
+
/** Instantiate a delegate for an accessory corresponding to a device.
|
15
|
+
* @param {DeconzAccessory.Gateway} gateway - The gateway.
|
16
|
+
* @param {Deconz.Device} device - The device.
|
17
|
+
*/
|
18
|
+
constructor (gateway, device) {
|
19
|
+
super(gateway, device, gateway.Accessory.Categories.SENSOR)
|
20
|
+
|
21
|
+
this.identify()
|
22
|
+
|
23
|
+
this.service = this.createService(device.resource, { primaryService: true })
|
24
|
+
|
25
|
+
for (const subtype in device.resourceBySubtype) {
|
26
|
+
const resource = device.resourceBySubtype[subtype]
|
27
|
+
if (subtype === device.primary) {
|
28
|
+
continue
|
29
|
+
}
|
30
|
+
this.createService(resource)
|
31
|
+
}
|
32
|
+
|
33
|
+
this.historyService = new History.Motion(
|
34
|
+
this, {},
|
35
|
+
this.service.characteristicDelegate('motion'),
|
36
|
+
this.service.characteristicDelegate('lastActivation'),
|
37
|
+
this.serviceByServiceName.Temperature == null
|
38
|
+
? null
|
39
|
+
: this.serviceByServiceName.Temperature.characteristicDelegate('temperature')
|
40
|
+
)
|
41
|
+
|
42
|
+
this.createSettingsService()
|
43
|
+
|
44
|
+
setImmediate(() => {
|
45
|
+
this.debug('initialised')
|
46
|
+
this.emit('initialised')
|
47
|
+
})
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
module.exports = Motion
|
@@ -0,0 +1,35 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzAccessory/Sensor.js
|
2
|
+
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
|
+
//
|
4
|
+
// Homebridge plugin for deCONZ.
|
5
|
+
|
6
|
+
'use strict'
|
7
|
+
|
8
|
+
const DeconzAccessory = require('../DeconzAccessory')
|
9
|
+
|
10
|
+
class Sensor extends DeconzAccessory {
|
11
|
+
constructor (gateway, device) {
|
12
|
+
super(gateway, device, gateway.Accessory.Categories.SENSOR)
|
13
|
+
|
14
|
+
this.identify()
|
15
|
+
|
16
|
+
this.service = this.createService(device.resource, { primaryService: true })
|
17
|
+
|
18
|
+
for (const subtype in device.resourceBySubtype) {
|
19
|
+
const resource = device.resourceBySubtype[subtype]
|
20
|
+
if (subtype === device.primary) {
|
21
|
+
continue
|
22
|
+
}
|
23
|
+
this.createService(resource)
|
24
|
+
}
|
25
|
+
|
26
|
+
this.createSettingsService()
|
27
|
+
|
28
|
+
setImmediate(() => {
|
29
|
+
this.debug('initialised')
|
30
|
+
this.emit('initialised')
|
31
|
+
})
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
module.exports = Sensor
|
@@ -0,0 +1,63 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzAccessory/Temperature.js
|
2
|
+
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
|
+
//
|
4
|
+
// Homebridge plugin for deCONZ.
|
5
|
+
|
6
|
+
'use strict'
|
7
|
+
|
8
|
+
const homebridgeLib = require('homebridge-lib')
|
9
|
+
const DeconzAccessory = require('../DeconzAccessory')
|
10
|
+
|
11
|
+
const { History } = homebridgeLib.ServiceDelegate
|
12
|
+
|
13
|
+
class Temperature extends DeconzAccessory {
|
14
|
+
/** Instantiate a delegate for an accessory corresponding to a device.
|
15
|
+
* @param {DeconzAccessory.Gateway} gateway - The gateway.
|
16
|
+
* @param {Deconz.Device} device - The device.
|
17
|
+
*/
|
18
|
+
constructor (gateway, device, settings = {}) {
|
19
|
+
super(gateway, device, gateway.Accessory.Categories.SENSOR)
|
20
|
+
this.identify()
|
21
|
+
|
22
|
+
this.service = this.createService(device.resource, { primaryService: true })
|
23
|
+
|
24
|
+
for (const subtype in device.resourceBySubtype) {
|
25
|
+
const resource = device.resourceBySubtype[subtype]
|
26
|
+
if (subtype === device.primary) {
|
27
|
+
continue
|
28
|
+
}
|
29
|
+
this.createService(resource)
|
30
|
+
}
|
31
|
+
|
32
|
+
if (this.serviceByServiceName.AirQuality == null) {
|
33
|
+
this.historyService = new History.Weather(
|
34
|
+
this, {},
|
35
|
+
this.service.characteristicDelegate('temperature'),
|
36
|
+
this.serviceByServiceName.Humidity == null
|
37
|
+
? null
|
38
|
+
: this.serviceByServiceName.Humidity.characteristicDelegate('humidity'),
|
39
|
+
this.serviceByServiceName.AirPressure == null
|
40
|
+
? null
|
41
|
+
: this.serviceByServiceName.AirPressure.characteristicDelegate('airPressure')
|
42
|
+
)
|
43
|
+
} else {
|
44
|
+
this.historyService = new History.Room(
|
45
|
+
this, {},
|
46
|
+
this.service.characteristicDelegate('temperature'),
|
47
|
+
this.serviceByServiceName.Humidity == null
|
48
|
+
? null
|
49
|
+
: this.serviceByServiceName.Humidity.characteristicDelegate('humidity'),
|
50
|
+
this.serviceByServiceName.AirQuality.characteristicDelegate('vocDensity')
|
51
|
+
)
|
52
|
+
}
|
53
|
+
|
54
|
+
this.createSettingsService()
|
55
|
+
|
56
|
+
setImmediate(() => {
|
57
|
+
this.debug('initialised')
|
58
|
+
this.emit('initialised')
|
59
|
+
})
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
module.exports = Temperature
|
@@ -0,0 +1,50 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzAccessory/Thermostat.js
|
2
|
+
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
|
+
//
|
4
|
+
// Homebridge plugin for deCONZ.
|
5
|
+
|
6
|
+
'use strict'
|
7
|
+
|
8
|
+
const homebridgeLib = require('homebridge-lib')
|
9
|
+
const DeconzAccessory = require('../DeconzAccessory')
|
10
|
+
|
11
|
+
const { History } = homebridgeLib.ServiceDelegate
|
12
|
+
|
13
|
+
class Thermostat extends DeconzAccessory {
|
14
|
+
/** Instantiate a delegate for an accessory corresponding to a device.
|
15
|
+
* @param {DeconzAccessory.Gateway} gateway - The gateway.
|
16
|
+
* @param {Deconz.Device} device - The device.
|
17
|
+
*/
|
18
|
+
constructor (gateway, device, settings = {}) {
|
19
|
+
super(gateway, device, gateway.Accessory.Categories.THERMOSTAT)
|
20
|
+
this.identify()
|
21
|
+
|
22
|
+
this.service = this.createService(device.resource, { primaryService: true })
|
23
|
+
|
24
|
+
for (const subtype in device.resourceBySubtype) {
|
25
|
+
const resource = device.resourceBySubtype[subtype]
|
26
|
+
if (subtype === device.primary) {
|
27
|
+
continue
|
28
|
+
}
|
29
|
+
this.createService(resource)
|
30
|
+
}
|
31
|
+
|
32
|
+
if (device.resource.body.state.valve !== undefined) {
|
33
|
+
this.historyService = new History.Thermo(
|
34
|
+
this, {},
|
35
|
+
this.service.characteristicDelegate('currentTemperature'),
|
36
|
+
this.service.characteristicDelegate('targetTemperature'),
|
37
|
+
this.service.characteristicDelegate('valvePosition')
|
38
|
+
)
|
39
|
+
}
|
40
|
+
|
41
|
+
this.createSettingsService()
|
42
|
+
|
43
|
+
setImmediate(() => {
|
44
|
+
this.debug('initialised')
|
45
|
+
this.emit('initialised')
|
46
|
+
})
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
module.exports = Thermostat
|
@@ -0,0 +1,56 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzAccessory/WarningDevice.js
|
2
|
+
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
|
+
//
|
4
|
+
// Homebridge plugin for deCONZ.
|
5
|
+
|
6
|
+
'use strict'
|
7
|
+
|
8
|
+
const homebridgeLib = require('homebridge-lib')
|
9
|
+
const DeconzAccessory = require('../DeconzAccessory')
|
10
|
+
|
11
|
+
const { History } = homebridgeLib.ServiceDelegate
|
12
|
+
|
13
|
+
/** Delegate class for a HomeKit accessory, corresponding to a light device
|
14
|
+
* or groups resource.
|
15
|
+
* @extends DeconzAccessory
|
16
|
+
* @memberof DeconzAccessory
|
17
|
+
*/
|
18
|
+
class WarningDevice extends DeconzAccessory {
|
19
|
+
/** Instantiate a delegate for an accessory corresponding to a device.
|
20
|
+
* @param {DeconzAccessory.Gateway} gateway - The gateway.
|
21
|
+
* @param {Deconz.Device} device - The device.
|
22
|
+
*/
|
23
|
+
constructor (gateway, device, settings = {}) {
|
24
|
+
super(gateway, device, gateway.Accessory.Categories.SENSOR)
|
25
|
+
|
26
|
+
this.identify()
|
27
|
+
|
28
|
+
this.service = this.createService(device.resource, { primaryService: true })
|
29
|
+
|
30
|
+
for (const subtype in device.resourceBySubtype) {
|
31
|
+
const resource = device.resourceBySubtype[subtype]
|
32
|
+
if (subtype === device.primary) {
|
33
|
+
continue
|
34
|
+
}
|
35
|
+
this.createService(resource)
|
36
|
+
}
|
37
|
+
|
38
|
+
if (this.serviceByServiceName.Temperature != null) {
|
39
|
+
this.historyService = new History.Weather(
|
40
|
+
this, {},
|
41
|
+
this.serviceByServiceName.Temperature.characteristicDelegate('temperature'),
|
42
|
+
null,
|
43
|
+
null
|
44
|
+
)
|
45
|
+
}
|
46
|
+
|
47
|
+
this.createSettingsService()
|
48
|
+
|
49
|
+
setImmediate(() => {
|
50
|
+
this.debug('initialised')
|
51
|
+
this.emit('initialised')
|
52
|
+
})
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
module.exports = WarningDevice
|