homebridge-deconz 0.0.6 → 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/README.md +8 -0
- package/cli/deconz.js +980 -0
- package/config.schema.json +1 -1
- package/lib/Client/ApiError.js +42 -0
- package/lib/{DeconzClient.js → Deconz/ApiClient.js} +82 -158
- package/lib/Deconz/ApiError.js +42 -0
- package/lib/Deconz/ApiResponse.js +54 -0
- package/lib/Deconz/Device.js +100 -0
- package/lib/{DeconzDiscovery.js → Deconz/Discovery.js} +4 -3
- package/lib/Deconz/Resource.js +1206 -0
- package/lib/{DeconzWsClient.js → Deconz/WsClient.js} +59 -44
- package/lib/Deconz/index.js +21 -0
- package/lib/DeconzAccessory/Contact.js +54 -0
- package/lib/DeconzAccessory/Gateway.js +316 -374
- package/lib/DeconzAccessory/Light.js +72 -0
- 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 +216 -0
- package/lib/DeconzPlatform.js +8 -3
- package/lib/DeconzService/AirPressure.js +43 -0
- package/lib/DeconzService/AirQuality.js +20 -10
- package/lib/DeconzService/Alarm.js +16 -9
- package/lib/DeconzService/Battery.js +43 -0
- package/lib/DeconzService/Button.js +12 -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 +13 -5
- package/lib/DeconzService/Flag.js +52 -0
- package/lib/DeconzService/GatewaySettings.js +8 -58
- package/lib/DeconzService/Humidity.js +37 -0
- package/lib/DeconzService/Leak.js +38 -0
- package/lib/DeconzService/Light.js +376 -0
- 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 +94 -0
- package/package.json +7 -4
- package/lib/DeconzAccessory/Device.js +0 -91
- package/lib/DeconzAccessory.js +0 -16
- package/lib/DeconzDevice.js +0 -245
- package/lib/DeconzService/Sensor.js +0 -58
- package/lib/DeconzService.js +0 -43
@@ -7,21 +7,27 @@
|
|
7
7
|
|
8
8
|
const DeconzService = require('../DeconzService')
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
/**
|
11
|
+
* @memberof DeconzService
|
12
|
+
*/
|
13
|
+
class AirQuality extends DeconzService.SensorsResource {
|
14
|
+
constructor (accessory, resource, params = {}) {
|
15
|
+
params.Service = accessory.Services.hap.AirQualitySensor
|
16
|
+
super(accessory, resource, params)
|
14
17
|
|
15
18
|
this.addCharacteristicDelegate({
|
16
19
|
key: 'airQuality',
|
17
20
|
Characteristic: this.Characteristics.hap.AirQuality
|
18
21
|
})
|
22
|
+
|
19
23
|
this.addCharacteristicDelegate({
|
20
24
|
key: 'vocDensity',
|
21
25
|
Characteristic: this.Characteristics.hap.VOCDensity
|
22
26
|
})
|
23
|
-
|
24
|
-
|
27
|
+
|
28
|
+
super.addCharacteristicDelegates()
|
29
|
+
|
30
|
+
this.update(resource.body)
|
25
31
|
}
|
26
32
|
|
27
33
|
airQualityValue (value) {
|
@@ -41,10 +47,14 @@ class AirQuality extends DeconzService.Sensor {
|
|
41
47
|
}
|
42
48
|
}
|
43
49
|
|
44
|
-
|
45
|
-
this.values.airQuality
|
46
|
-
|
47
|
-
|
50
|
+
updateState (state) {
|
51
|
+
if (this.values.airQuality != null) {
|
52
|
+
this.values.airQuality = this.airQualityValue(state.airquality)
|
53
|
+
}
|
54
|
+
if (this.values.vocDensity != null) {
|
55
|
+
this.values.vocDensity = Math.round(state.airqualityppb * 4.57)
|
56
|
+
}
|
57
|
+
super.updateState(state)
|
48
58
|
}
|
49
59
|
}
|
50
60
|
|
@@ -7,22 +7,29 @@
|
|
7
7
|
|
8
8
|
const DeconzService = require('../DeconzService')
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
/**
|
11
|
+
* @memberof DeconzService
|
12
|
+
*/
|
13
|
+
class Alarm extends DeconzService.SensorsResource {
|
14
|
+
constructor (accessory, resource, params = {}) {
|
15
|
+
params.Service = accessory.Services.my.Resource
|
16
|
+
super(accessory, resource, params)
|
14
17
|
|
15
18
|
this.addCharacteristicDelegate({
|
16
19
|
key: 'alarm',
|
17
|
-
Characteristic: this.Characteristics.
|
20
|
+
Characteristic: this.Characteristics.my.Alarm
|
18
21
|
})
|
22
|
+
|
19
23
|
super.addCharacteristicDelegates(params)
|
20
|
-
|
24
|
+
|
25
|
+
this.update(resource.body)
|
21
26
|
}
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
28
|
+
updateState (state) {
|
29
|
+
if (state.alarm != null || state.test != null) {
|
30
|
+
this.values.alarm = state.alarm || state.test
|
31
|
+
}
|
32
|
+
super.updateState(state)
|
26
33
|
}
|
27
34
|
}
|
28
35
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzService/Battery.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 Deconz = require('../Deconz')
|
10
|
+
|
11
|
+
// const { dateToString } = Deconz.ApiClient
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @memberof DeconzService
|
15
|
+
*/
|
16
|
+
class Battery extends homebridgeLib.ServiceDelegate.Battery {
|
17
|
+
constructor (accessory, resource, params = {}) {
|
18
|
+
super(accessory, {
|
19
|
+
name: accessory.name + ' Battery'
|
20
|
+
})
|
21
|
+
}
|
22
|
+
|
23
|
+
updateState (state) {
|
24
|
+
if (state.battery != null) {
|
25
|
+
this.values.batteryLevel = state.battery
|
26
|
+
}
|
27
|
+
if (state.charging != null) {
|
28
|
+
this.values.chargingState = state.charging
|
29
|
+
? this.Characteristics.hap.ChargingState.CHARGING
|
30
|
+
: this.Characteristics.hap.ChargingState.NOT_CHARGING
|
31
|
+
}
|
32
|
+
super.updateState(state)
|
33
|
+
}
|
34
|
+
|
35
|
+
updateConfig (config) {
|
36
|
+
if (config.battery != null) {
|
37
|
+
this.values.batteryLevel = config.battery
|
38
|
+
}
|
39
|
+
super.updateConfig(config)
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
module.exports = Battery
|
@@ -22,6 +22,9 @@ const deconzEvent = {
|
|
22
22
|
|
23
23
|
let homeKitEvent
|
24
24
|
|
25
|
+
/**
|
26
|
+
* @memberof DeconzService
|
27
|
+
*/
|
25
28
|
class Button extends homebridgeLib.ServiceDelegate {
|
26
29
|
static get SINGLE () { return 0x01 }
|
27
30
|
static get DOUBLE () { return 0x02 }
|
@@ -112,6 +115,12 @@ class Button extends homebridgeLib.ServiceDelegate {
|
|
112
115
|
Characteristic: this.Characteristics.hap.ProgrammableSwitchEvent,
|
113
116
|
props: this.props(params.events)
|
114
117
|
})
|
118
|
+
|
119
|
+
this.addCharacteristicDelegate({
|
120
|
+
key: 'index',
|
121
|
+
Characteristic: this.Characteristics.hap.ServiceLabelIndex,
|
122
|
+
value: params.button
|
123
|
+
})
|
115
124
|
}
|
116
125
|
|
117
126
|
homeKitValue (value, oldValue = 0, repeat = false) {
|
@@ -129,11 +138,12 @@ class Button extends homebridgeLib.ServiceDelegate {
|
|
129
138
|
case deconzEvent.SHORT_RELEASE:
|
130
139
|
return homeKitEvent.SINGLE_PRESS
|
131
140
|
case deconzEvent.HOLD:
|
132
|
-
case deconzEvent.LONG_RELEASE:
|
133
141
|
if (repeat) {
|
134
142
|
return homeKitEvent.SINGLE_PRESS
|
135
143
|
}
|
136
|
-
|
144
|
+
// falls through
|
145
|
+
case deconzEvent.LONG_RELEASE:
|
146
|
+
if (repeat || (button === oldButton && oldEvent === deconzEvent.HOLD)) {
|
137
147
|
// Already issued action on previous Hold.
|
138
148
|
return null
|
139
149
|
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzService/CarbonMonoxide.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 CarbonMonoxide extends DeconzService.SensorsResource {
|
14
|
+
constructor (accessory, resource, params = {}) {
|
15
|
+
params.Service = accessory.Services.hap.CarbonMonoxideSensor
|
16
|
+
super(accessory, resource, params)
|
17
|
+
|
18
|
+
this.addCharacteristicDelegate({
|
19
|
+
key: 'carbonmonoxide',
|
20
|
+
Characteristic: this.Characteristics.hap.CarbonMonoxideDetected
|
21
|
+
})
|
22
|
+
|
23
|
+
super.addCharacteristicDelegates(params)
|
24
|
+
|
25
|
+
this.update(resource.body)
|
26
|
+
}
|
27
|
+
|
28
|
+
updateState (state) {
|
29
|
+
if (state.carbonmonoxide != null || state.test != null) {
|
30
|
+
this.values.carbonmonoxide = state.carbonmonoxide || state.test
|
31
|
+
? this.Characteristics.hap.CarbonMonoxideDetected.CO_LEVELS_ABNORMAL
|
32
|
+
: this.Characteristics.hap.CarbonMonoxideDetected.CO_LEVELS_NORMAL
|
33
|
+
}
|
34
|
+
super.updateState(state)
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
module.exports = CarbonMonoxide
|
@@ -0,0 +1,65 @@
|
|
1
|
+
// homebridge-deconz/lib/DeconzService/Consumption.js
|
2
|
+
// Copyright © 2022 Erik Baauw. All rights reserved.
|
3
|
+
//
|
4
|
+
// Homebridge plugin for deCONZ.
|
5
|
+
|
6
|
+
'use strict'
|
7
|
+
|
8
|
+
const Deconz = require('../Deconz')
|
9
|
+
const DeconzService = require('../DeconzService')
|
10
|
+
|
11
|
+
const { dateToString } = Deconz.ApiClient
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @memberof DeconzService
|
15
|
+
*/
|
16
|
+
class Consumption extends DeconzService.SensorsResource {
|
17
|
+
static addResource (service, resource) {
|
18
|
+
service.addCharacteristicDelegate({
|
19
|
+
key: 'totalConsumption',
|
20
|
+
Characteristic: service.Characteristics.eve.TotalConsumption,
|
21
|
+
unit: ' kWh'
|
22
|
+
})
|
23
|
+
|
24
|
+
if (
|
25
|
+
resource.body.state.power !== undefined &&
|
26
|
+
service.values.currentConsumption === undefined
|
27
|
+
) {
|
28
|
+
service.addCharacteristicDelegate({
|
29
|
+
key: 'currentConsumption',
|
30
|
+
Characteristic: service.Characteristics.eve.CurrentConsumption,
|
31
|
+
unit: ' W'
|
32
|
+
})
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
static updateResourceState (service, state) {
|
37
|
+
if (state.consumption != null) {
|
38
|
+
service.values.totalConsumption = state.consumption / 1000
|
39
|
+
}
|
40
|
+
if (state.power != null) {
|
41
|
+
service.values.currentConsumption = state.power
|
42
|
+
}
|
43
|
+
if (state.lastupdated != null) {
|
44
|
+
service.values.lastUpdated = dateToString(state.lastupdated)
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
constructor (accessory, resource, params = {}) {
|
49
|
+
params.Service = accessory.Services.my.Resource
|
50
|
+
super(accessory, resource, params)
|
51
|
+
|
52
|
+
Consumption.addResource(this, resource)
|
53
|
+
|
54
|
+
super.addCharacteristicDelegates()
|
55
|
+
|
56
|
+
this.update(resource.body)
|
57
|
+
}
|
58
|
+
|
59
|
+
updateState (state) {
|
60
|
+
Consumption.updateResourceState(this.service, state)
|
61
|
+
super.updateState(state)
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
module.exports = Consumption
|
@@ -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
|
@@ -9,13 +9,15 @@ const homebridgeLib = require('homebridge-lib')
|
|
9
9
|
|
10
10
|
/** Delegate class for a DeconzDevice service.
|
11
11
|
* @extends ServiceDelegate
|
12
|
+
* @memberof DeconzService
|
12
13
|
*/
|
13
14
|
class DeviceSettings extends homebridgeLib.ServiceDelegate {
|
14
15
|
constructor (accessory, params = {}) {
|
15
16
|
params.Service = accessory.Services.my.DeconzDevice
|
16
|
-
params.primaryService = true
|
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
|
@@ -9,11 +9,13 @@ const homebridgeLib = require('homebridge-lib')
|
|
9
9
|
|
10
10
|
/** Delegate class for a DeconzGateway service.
|
11
11
|
* @extends ServiceDelegate
|
12
|
+
* @memberof DeconzService
|
12
13
|
*/
|
13
14
|
class GatewaySettings extends homebridgeLib.ServiceDelegate {
|
14
15
|
constructor (gateway, params = {}) {
|
15
16
|
params.Service = gateway.Services.my.DeconzGateway
|
16
17
|
super(gateway, params)
|
18
|
+
this.gateway = gateway
|
17
19
|
|
18
20
|
this.addCharacteristicDelegate({
|
19
21
|
key: 'expose',
|
@@ -69,10 +71,7 @@ class GatewaySettings extends homebridgeLib.ServiceDelegate {
|
|
69
71
|
this.addCharacteristicDelegate({
|
70
72
|
key: 'logLevel',
|
71
73
|
Characteristic: this.Characteristics.my.LogLevel,
|
72
|
-
value: gateway.platform.logLevel
|
73
|
-
silent: true
|
74
|
-
}).on('didSet', (value) => {
|
75
|
-
gateway.logLevel = value
|
74
|
+
value: gateway.platform.logLevel
|
76
75
|
})
|
77
76
|
|
78
77
|
this.addCharacteristicDelegate({
|
@@ -127,10 +126,11 @@ class GatewaySettings extends homebridgeLib.ServiceDelegate {
|
|
127
126
|
})
|
128
127
|
|
129
128
|
this.addCharacteristicDelegate({
|
130
|
-
key: '
|
129
|
+
key: 'transitionTime',
|
131
130
|
Characteristic: this.Characteristics.my.TransitionTime,
|
132
|
-
value:
|
131
|
+
value: this.gateway.defaultTransitionTime
|
133
132
|
})
|
133
|
+
this.values.transitionTime = this.gateway.defaultTransitionTime
|
134
134
|
|
135
135
|
this.addCharacteristicDelegate({
|
136
136
|
key: 'unlock',
|
@@ -153,72 +153,22 @@ class GatewaySettings extends homebridgeLib.ServiceDelegate {
|
|
153
153
|
} catch (error) { this.error(error) }
|
154
154
|
})
|
155
155
|
this.values.unlock = false
|
156
|
-
|
157
|
-
this.addCharacteristicDelegate({
|
158
|
-
key: 'host',
|
159
|
-
value: params.host,
|
160
|
-
silent: true
|
161
|
-
}).on('didSet', (value) => {
|
162
|
-
if (gateway.client != null) {
|
163
|
-
gateway.client.host = value
|
164
|
-
}
|
165
|
-
if (gateway.wsClient != null) {
|
166
|
-
gateway.wsClient.host = this.values.wsHost
|
167
|
-
}
|
168
|
-
})
|
169
|
-
this.values.host = params.host
|
170
|
-
|
171
|
-
this.addCharacteristicDelegate({
|
172
|
-
key: 'rtypes',
|
173
|
-
value: [],
|
174
|
-
silent: true
|
175
|
-
}).on('didSet', async () => {
|
176
|
-
gateway.pollNext = true
|
177
|
-
})
|
178
|
-
|
179
|
-
this.addCharacteristicDelegate({
|
180
|
-
key: 'username',
|
181
|
-
silent: true
|
182
|
-
}).on('didSet', (value) => {
|
183
|
-
gateway.client.username = value
|
184
|
-
})
|
185
|
-
|
186
|
-
Object.defineProperty(this.values, 'wsHost', {
|
187
|
-
configurable: true, // make sure we can delete it again
|
188
|
-
get () {
|
189
|
-
const { hostname } = homebridgeLib.OptionParser.toHost(
|
190
|
-
'host', this.host
|
191
|
-
)
|
192
|
-
return hostname + ':' + this.wsPort
|
193
|
-
}
|
194
|
-
})
|
195
|
-
|
196
|
-
this.addCharacteristicDelegate({
|
197
|
-
key: 'wsPort',
|
198
|
-
value: 443,
|
199
|
-
silent: true
|
200
|
-
}).on('didSet', (value) => {
|
201
|
-
if (gateway.wsClient != null) {
|
202
|
-
gateway.wsClient.host = this.values.wsHost
|
203
|
-
}
|
204
|
-
})
|
205
156
|
}
|
206
157
|
|
207
158
|
async updateRtypes (rtype, value) {
|
208
|
-
const rtypes = this.values.rtypes.slice()
|
159
|
+
const rtypes = this.gateway.values.rtypes.slice()
|
209
160
|
if (value) {
|
210
161
|
rtypes.push(rtype)
|
211
162
|
} else {
|
212
163
|
rtypes.splice(rtypes.indexOf(rtype), 1)
|
213
164
|
}
|
214
|
-
this.values.rtypes = rtypes
|
165
|
+
this.gateway.values.rtypes = rtypes
|
215
166
|
}
|
216
167
|
|
217
168
|
update (config) {
|
218
169
|
this.values.expose = true
|
219
170
|
this.values.lastUpdated = new Date().toString().slice(0, 24)
|
220
171
|
this.values.restart = false
|
221
|
-
this.values.wsPort = config.websocketport
|
222
172
|
}
|
223
173
|
}
|
224
174
|
|