homebridge-deconz 0.0.9 → 0.0.12
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/README.md +3 -6
- package/cli/deconz.js +12 -0
- package/config.schema.json +2 -1
- package/homebridge-ui/public/index.html +26 -0
- package/homebridge-ui/public/style.css +0 -0
- package/homebridge-ui/server.js +43 -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 +752 -27
- package/lib/DeconzAccessory/Contact.js +54 -0
- package/lib/DeconzAccessory/Gateway.js +102 -66
- package/lib/DeconzAccessory/Light.js +42 -35
- 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 +145 -4
- package/lib/DeconzPlatform.js +6 -3
- package/lib/DeconzService/AirPressure.js +43 -0
- package/lib/DeconzService/AirQuality.js +20 -11
- package/lib/DeconzService/Alarm.js +13 -9
- package/lib/DeconzService/Battery.js +53 -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 +12 -4
- package/lib/DeconzService/Flag.js +52 -0
- package/lib/DeconzService/GatewaySettings.js +1 -4
- package/lib/DeconzService/Humidity.js +37 -0
- package/lib/DeconzService/Leak.js +38 -0
- package/lib/DeconzService/Light.js +289 -280
- 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 +79 -25
- package/package.json +6 -5
- package/lib/Client/ApiError.js +0 -42
- package/lib/DeconzAccessory/Device.js +0 -69
- package/lib/DeconzService/Sensor.js +0 -61
@@ -0,0 +1,60 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzService/Contact.js
|
2
|
+
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
|
+
//
|
4
|
+
// Homebridge plugin for deCONZ.
|
5
|
+
|
6
|
+
'use strict'
|
7
|
+
|
8
|
+
const DeconzService = require('../DeconzService')
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @memberof DeconzService
|
12
|
+
*/
|
13
|
+
class Contact extends DeconzService.SensorsResource {
|
14
|
+
constructor (accessory, resource, params = {}) {
|
15
|
+
params.Service = accessory.Services.hap.ContactSensor
|
16
|
+
super(accessory, resource, params)
|
17
|
+
|
18
|
+
this.addCharacteristicDelegate({
|
19
|
+
key: 'contact',
|
20
|
+
Characteristic: this.Characteristics.hap.ContactSensorState
|
21
|
+
})
|
22
|
+
|
23
|
+
this.addCharacteristicDelegate({
|
24
|
+
key: 'timesOpened',
|
25
|
+
Characteristic: this.Characteristics.eve.TimesOpened,
|
26
|
+
value: 0
|
27
|
+
})
|
28
|
+
|
29
|
+
this.addCharacteristicDelegate({
|
30
|
+
key: 'openDuration',
|
31
|
+
Characteristic: this.Characteristics.eve.OpenDuration,
|
32
|
+
value: 0
|
33
|
+
})
|
34
|
+
|
35
|
+
this.addCharacteristicDelegate({
|
36
|
+
key: 'closedDuration',
|
37
|
+
Characteristic: this.Characteristics.eve.ClosedDuration,
|
38
|
+
value: 0
|
39
|
+
})
|
40
|
+
|
41
|
+
this.addCharacteristicDelegate({
|
42
|
+
key: 'lastActivation',
|
43
|
+
Characteristic: this.Characteristics.eve.LastActivation,
|
44
|
+
silent: true
|
45
|
+
})
|
46
|
+
|
47
|
+
this.addCharacteristicDelegates({ noTampered: true })
|
48
|
+
}
|
49
|
+
|
50
|
+
updateState (state) {
|
51
|
+
if (state.open != null) {
|
52
|
+
this.values.contact = state.open
|
53
|
+
? this.Characteristics.hap.ContactSensorState.CONTACT_NOT_DETECTED
|
54
|
+
: this.Characteristics.hap.ContactSensorState.CONTACT_DETECTED
|
55
|
+
}
|
56
|
+
super.updateState(state)
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
module.exports = Contact
|
@@ -0,0 +1,132 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzService/Daylight.js
|
2
|
+
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
|
+
//
|
4
|
+
// Homebridge plugin for deCONZ.
|
5
|
+
|
6
|
+
'use strict'
|
7
|
+
|
8
|
+
const DeconzService = require('../DeconzService')
|
9
|
+
const Deconz = require('../Deconz')
|
10
|
+
|
11
|
+
const { dateToString, lightLevelToLux } = Deconz.ApiClient
|
12
|
+
|
13
|
+
const daylightEvents = {
|
14
|
+
100: { name: 'Solar Midnight', period: 'Night' },
|
15
|
+
110: { name: 'Astronomical Dawn', period: 'Astronomical Twilight' },
|
16
|
+
120: { name: 'Nautical Dawn', period: 'Nautical Twilight' },
|
17
|
+
130: { name: 'Dawn', period: 'Twilight' },
|
18
|
+
140: { name: 'Sunrise', period: 'Sunrise' },
|
19
|
+
150: { name: 'End Sunrise', period: 'Golden Hour' },
|
20
|
+
160: { name: 'End Golden Hour', period: 'Day' },
|
21
|
+
170: { name: 'Solar Noon', period: 'Day' },
|
22
|
+
180: { name: 'Start Golden Hour', period: 'Golden Hour' },
|
23
|
+
190: { name: 'Start Sunset', period: 'Sunset' },
|
24
|
+
200: { name: 'Sunset', period: 'Twilight' },
|
25
|
+
210: { name: 'Dusk', period: 'Nautical Twilight' },
|
26
|
+
220: { name: 'Nautical Dusk', period: 'Astronomical Twilight' },
|
27
|
+
230: { name: 'Astronomical Dusk', period: 'Night' }
|
28
|
+
}
|
29
|
+
|
30
|
+
const daylightPeriods = {
|
31
|
+
Night: { lightlevel: 0, daylight: false, dark: true },
|
32
|
+
'Astronomical Twilight': { lightlevel: 100, daylight: false, dark: true },
|
33
|
+
'Nautical Twilight': { lightlevel: 1000, daylight: false, dark: true },
|
34
|
+
Twilight: { lightlevel: 10000, daylight: false, dark: false },
|
35
|
+
Sunrise: { lightlevel: 15000, daylight: true, dark: false },
|
36
|
+
Sunset: { lightlevel: 20000, daylight: true, dark: false },
|
37
|
+
'Golden Hour': { lightlevel: 40000, daylight: true, dark: false },
|
38
|
+
Day: { lightlevel: 65535, daylight: true, dark: false }
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @memberof DeconzService
|
43
|
+
*/
|
44
|
+
class Daylight extends DeconzService.SensorsResource {
|
45
|
+
constructor (accessory, resource, params = {}) {
|
46
|
+
params.Service = accessory.Services.hap.LightSensor
|
47
|
+
super(accessory, resource, params)
|
48
|
+
|
49
|
+
this.addCharacteristicDelegate({
|
50
|
+
key: 'lightlevel',
|
51
|
+
Characteristic: this.Characteristics.hap.CurrentAmbientLightLevel,
|
52
|
+
unit: ' lux'
|
53
|
+
})
|
54
|
+
|
55
|
+
this.addCharacteristicDelegate({
|
56
|
+
key: 'dark',
|
57
|
+
Characteristic: this.Characteristics.my.Dark
|
58
|
+
})
|
59
|
+
|
60
|
+
this.addCharacteristicDelegate({
|
61
|
+
key: 'daylight',
|
62
|
+
Characteristic: this.Characteristics.my.Daylight
|
63
|
+
})
|
64
|
+
|
65
|
+
this.addCharacteristicDelegate({
|
66
|
+
key: 'status',
|
67
|
+
Characteristic: this.Characteristics.my.Status,
|
68
|
+
props: {
|
69
|
+
minValue: 100,
|
70
|
+
maxValue: 230,
|
71
|
+
perms: [
|
72
|
+
this.Characteristic.Perms.READ,
|
73
|
+
this.Characteristic.Perms.NOTIFY]
|
74
|
+
},
|
75
|
+
value: resource.body.state.status
|
76
|
+
})
|
77
|
+
|
78
|
+
this.addCharacteristicDelegate({
|
79
|
+
key: 'lastEvent',
|
80
|
+
Characteristic: this.Characteristics.my.LastEvent
|
81
|
+
})
|
82
|
+
|
83
|
+
this.addCharacteristicDelegate({
|
84
|
+
key: 'period',
|
85
|
+
Characteristic: this.Characteristics.my.Period
|
86
|
+
})
|
87
|
+
|
88
|
+
this.addCharacteristicDelegates()
|
89
|
+
|
90
|
+
this.addCharacteristicDelegate({
|
91
|
+
key: 'sunrise',
|
92
|
+
Characteristic: this.Characteristics.my.Sunrise
|
93
|
+
})
|
94
|
+
|
95
|
+
this.addCharacteristicDelegate({
|
96
|
+
key: 'sunset',
|
97
|
+
Characteristic: this.Characteristics.my.Sunset
|
98
|
+
})
|
99
|
+
|
100
|
+
if (!resource.body.config.configured) {
|
101
|
+
this.warn('%s: %s not configured', resource.rpath, resource.body.type)
|
102
|
+
}
|
103
|
+
|
104
|
+
this.update(resource.body)
|
105
|
+
}
|
106
|
+
|
107
|
+
updateState (state) {
|
108
|
+
if (state.status != null) {
|
109
|
+
this.values.status = state.status
|
110
|
+
const { name, period } = daylightEvents[state.status]
|
111
|
+
this.values.lastEvent = name
|
112
|
+
this.values.period = period
|
113
|
+
const { lightlevel } = daylightPeriods[period]
|
114
|
+
this.values.lightlevel = lightLevelToLux(lightlevel)
|
115
|
+
}
|
116
|
+
if (state.dark != null) {
|
117
|
+
this.values.dark = state.dark
|
118
|
+
}
|
119
|
+
if (state.daylight != null) {
|
120
|
+
this.values.daylight = state.daylight
|
121
|
+
}
|
122
|
+
if (state.sunrise != null) {
|
123
|
+
this.values.sunrise = dateToString(state.sunrise)
|
124
|
+
}
|
125
|
+
if (state.sunset != null) {
|
126
|
+
this.values.sunset = dateToString(state.sunset)
|
127
|
+
}
|
128
|
+
super.updateState(state)
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
module.exports = Daylight
|
@@ -16,6 +16,8 @@ class DeviceSettings extends homebridgeLib.ServiceDelegate {
|
|
16
16
|
params.Service = accessory.Services.my.DeconzDevice
|
17
17
|
super(accessory, params)
|
18
18
|
|
19
|
+
this.debug('settings: %j', params)
|
20
|
+
|
19
21
|
this.addCharacteristicDelegate({
|
20
22
|
key: 'expose',
|
21
23
|
Characteristic: this.Characteristics.my.Expose,
|
@@ -25,14 +27,20 @@ class DeviceSettings extends homebridgeLib.ServiceDelegate {
|
|
25
27
|
accessory.gateway.exposeDevice(params.subtype, value)
|
26
28
|
})
|
27
29
|
|
30
|
+
if (params.hasRepeat != null) {
|
31
|
+
this.addCharacteristicDelegate({
|
32
|
+
key: 'repeat',
|
33
|
+
Characteristic: this.Characteristics.my.Repeat,
|
34
|
+
props: { minValue: 0, maxValue: 1, minStep: 1 },
|
35
|
+
value: 0
|
36
|
+
})
|
37
|
+
}
|
38
|
+
|
28
39
|
if (params.logLevel != null) {
|
29
40
|
this.addCharacteristicDelegate({
|
30
41
|
key: 'logLevel',
|
31
42
|
Characteristic: this.Characteristics.my.LogLevel,
|
32
|
-
value: params.logLevel
|
33
|
-
silent: true
|
34
|
-
}).on('didSet', (value) => {
|
35
|
-
accessory.logLevel = value
|
43
|
+
value: params.logLevel
|
36
44
|
})
|
37
45
|
}
|
38
46
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzService/Flag.js
|
2
|
+
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
|
+
//
|
4
|
+
// Homebridge plugin for deCONZ.
|
5
|
+
|
6
|
+
'use strict'
|
7
|
+
|
8
|
+
const DeconzService = require('../DeconzService')
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @memberof DeconzService
|
12
|
+
*/
|
13
|
+
class Flag extends DeconzService.SensorsResource {
|
14
|
+
constructor (accessory, resource, params = {}) {
|
15
|
+
params.Service = accessory.Services.hap.Switch
|
16
|
+
super(accessory, resource, params)
|
17
|
+
|
18
|
+
if (resource.capabilities.readonly) {
|
19
|
+
this.addCharacteristicDelegate({
|
20
|
+
key: 'on',
|
21
|
+
Characteristic: this.Characteristics.hap.On,
|
22
|
+
props: {
|
23
|
+
perms: [
|
24
|
+
this.Characteristic.Perms.READ, this.Characteristic.Perms.NOTIFY
|
25
|
+
]
|
26
|
+
}
|
27
|
+
})
|
28
|
+
} else {
|
29
|
+
this.addCharacteristicDelegate({
|
30
|
+
key: 'on',
|
31
|
+
Characteristic: this.Characteristics.hap.On
|
32
|
+
}).on('didSet', async (value, fromHomeKit) => {
|
33
|
+
if (fromHomeKit) {
|
34
|
+
await this.put('/state', { flag: value })
|
35
|
+
}
|
36
|
+
})
|
37
|
+
}
|
38
|
+
|
39
|
+
this.addCharacteristicDelegates()
|
40
|
+
|
41
|
+
this.update(resource.body)
|
42
|
+
}
|
43
|
+
|
44
|
+
updateState (state) {
|
45
|
+
if (state.flag != null) {
|
46
|
+
this.values.on = state.flag
|
47
|
+
}
|
48
|
+
super.updateState(state)
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
module.exports = Flag
|
@@ -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({
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzService/Humidity.js
|
2
|
+
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
|
+
//
|
4
|
+
// Homebridge plugin for deCONZ.
|
5
|
+
|
6
|
+
'use strict'
|
7
|
+
|
8
|
+
const DeconzService = require('../DeconzService')
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @memberof DeconzService
|
12
|
+
*/
|
13
|
+
class Humidity extends DeconzService.SensorsResource {
|
14
|
+
constructor (accessory, resource, params = {}) {
|
15
|
+
params.Service = accessory.Services.hap.HumiditySensor
|
16
|
+
super(accessory, resource, params)
|
17
|
+
|
18
|
+
this.addCharacteristicDelegate({
|
19
|
+
key: 'humidity',
|
20
|
+
Characteristic: this.Characteristics.hap.CurrentRelativeHumidity,
|
21
|
+
unit: '%'
|
22
|
+
})
|
23
|
+
|
24
|
+
this.addCharacteristicDelegates()
|
25
|
+
|
26
|
+
this.update(resource.body)
|
27
|
+
}
|
28
|
+
|
29
|
+
updateState (state) {
|
30
|
+
if (state.humidity != null) {
|
31
|
+
this.values.humidity = Math.round(state.humidity / 10) / 10
|
32
|
+
}
|
33
|
+
super.updateState(state)
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
module.exports = Humidity
|
@@ -0,0 +1,38 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzService/Leak.js
|
2
|
+
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
|
+
//
|
4
|
+
// Homebridge plugin for deCONZ.
|
5
|
+
|
6
|
+
'use strict'
|
7
|
+
|
8
|
+
const DeconzService = require('../DeconzService')
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @memberof DeconzService
|
12
|
+
*/
|
13
|
+
class Leak extends DeconzService.SensorsResource {
|
14
|
+
constructor (accessory, resource, params = {}) {
|
15
|
+
params.Service = accessory.Services.hap.LeakSensor
|
16
|
+
super(accessory, resource, params)
|
17
|
+
|
18
|
+
this.addCharacteristicDelegate({
|
19
|
+
key: 'leak',
|
20
|
+
Characteristic: this.Characteristics.hap.LeakDetected
|
21
|
+
})
|
22
|
+
|
23
|
+
super.addCharacteristicDelegates()
|
24
|
+
|
25
|
+
this.update(resource.body)
|
26
|
+
}
|
27
|
+
|
28
|
+
updateState (state) {
|
29
|
+
if (state.water != null || state.test != null) {
|
30
|
+
this.values.leak = state.water || state.test
|
31
|
+
? this.Characteristics.hap.LeakDetected.LEAK_DETECTED
|
32
|
+
: this.Characteristics.hap.LeakDetected.LEAK_NOT_DETECTED
|
33
|
+
}
|
34
|
+
super.updateState(state)
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
module.exports = Leak
|