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.
Files changed (58) hide show
  1. package/README.md +8 -0
  2. package/cli/deconz.js +980 -0
  3. package/config.schema.json +1 -1
  4. package/lib/Client/ApiError.js +42 -0
  5. package/lib/{DeconzClient.js → Deconz/ApiClient.js} +82 -158
  6. package/lib/Deconz/ApiError.js +42 -0
  7. package/lib/Deconz/ApiResponse.js +54 -0
  8. package/lib/Deconz/Device.js +100 -0
  9. package/lib/{DeconzDiscovery.js → Deconz/Discovery.js} +4 -3
  10. package/lib/Deconz/Resource.js +1206 -0
  11. package/lib/{DeconzWsClient.js → Deconz/WsClient.js} +59 -44
  12. package/lib/Deconz/index.js +21 -0
  13. package/lib/DeconzAccessory/Contact.js +54 -0
  14. package/lib/DeconzAccessory/Gateway.js +316 -374
  15. package/lib/DeconzAccessory/Light.js +72 -0
  16. package/lib/DeconzAccessory/Motion.js +51 -0
  17. package/lib/DeconzAccessory/Sensor.js +35 -0
  18. package/lib/DeconzAccessory/Temperature.js +63 -0
  19. package/lib/DeconzAccessory/Thermostat.js +50 -0
  20. package/lib/DeconzAccessory/WarningDevice.js +56 -0
  21. package/lib/DeconzAccessory/WindowCovering.js +47 -0
  22. package/lib/DeconzAccessory/index.js +216 -0
  23. package/lib/DeconzPlatform.js +8 -3
  24. package/lib/DeconzService/AirPressure.js +43 -0
  25. package/lib/DeconzService/AirQuality.js +20 -10
  26. package/lib/DeconzService/Alarm.js +16 -9
  27. package/lib/DeconzService/Battery.js +43 -0
  28. package/lib/DeconzService/Button.js +12 -2
  29. package/lib/DeconzService/CarbonMonoxide.js +38 -0
  30. package/lib/DeconzService/Consumption.js +65 -0
  31. package/lib/DeconzService/Contact.js +60 -0
  32. package/lib/DeconzService/Daylight.js +132 -0
  33. package/lib/DeconzService/DeviceSettings.js +13 -5
  34. package/lib/DeconzService/Flag.js +52 -0
  35. package/lib/DeconzService/GatewaySettings.js +8 -58
  36. package/lib/DeconzService/Humidity.js +37 -0
  37. package/lib/DeconzService/Leak.js +38 -0
  38. package/lib/DeconzService/Light.js +376 -0
  39. package/lib/DeconzService/LightLevel.js +54 -0
  40. package/lib/DeconzService/LightsResource.js +112 -0
  41. package/lib/DeconzService/Motion.js +101 -0
  42. package/lib/DeconzService/Outlet.js +76 -0
  43. package/lib/DeconzService/Power.js +83 -0
  44. package/lib/DeconzService/SensorsResource.js +96 -0
  45. package/lib/DeconzService/Smoke.js +38 -0
  46. package/lib/DeconzService/Status.js +53 -0
  47. package/lib/DeconzService/Switch.js +93 -0
  48. package/lib/DeconzService/Temperature.js +63 -0
  49. package/lib/DeconzService/Thermostat.js +175 -0
  50. package/lib/DeconzService/WarningDevice.js +68 -0
  51. package/lib/DeconzService/WindowCovering.js +139 -0
  52. package/lib/DeconzService/index.js +94 -0
  53. package/package.json +7 -4
  54. package/lib/DeconzAccessory/Device.js +0 -91
  55. package/lib/DeconzAccessory.js +0 -16
  56. package/lib/DeconzDevice.js +0 -245
  57. package/lib/DeconzService/Sensor.js +0 -58
  58. package/lib/DeconzService.js +0 -43
@@ -1,245 +0,0 @@
1
- // homebridge-deconz/lib/DeconzDevice.js
2
- // Copyright © 2022 Erik Baauw. All rights reserved.
3
- //
4
- // Homebridge plugin for deCONZ.
5
-
6
- 'use strict'
7
-
8
- /** A Zigbee or virtual devices exposed by the gateway.
9
- */
10
- class DeconzDevice {
11
- static get Resource () { return Resource }
12
- static get ResourceAttributes () { return ResourceAttributes }
13
- static get TypeAttributes () { return TypeAttributes }
14
-
15
- /** Instantiate a Device from a gayeway resource.
16
- *
17
- * @param {string} rtype - The type of the resource:
18
- * `config`, `group`, `light`, or `sensor`.
19
- * @param {integer} rid - The resource ID of the resource.
20
- * @param {object} body - The body of the resource.
21
- * @params {DeconzDevice.ResourceAttributes} attrs - Derived
22
- * resource attributes.
23
- */
24
- constructor (rtype, rid, body, attrs) {
25
- /** The device ID.
26
- *
27
- * For Zigbee devices, the device ID is based on the Zigbee mac address
28
- * of the device.
29
- * For virtual devices, the device ID is based on the Zigbee mac address
30
- * of the gayeway and the resource.
31
- * The UUID of the associated HomeKit accessory is based on the device ID.
32
- * @type {string}
33
- */
34
- this.id = attrs.id
35
-
36
- /** Zigbee device vs virtual device.
37
- * @type {boolean}
38
- */
39
- this.zigbee = attrs.zigbee
40
-
41
- /** A map of Resource by subtype.
42
- * @type {Object.<string, DeconzDevice.Resource>}
43
- */
44
- this.resourceBySubtype = {}
45
- }
46
-
47
- /** The primary resource.
48
- * @type {DeconzDevice.Resource}
49
- */
50
- get resource () { return this.resourceBySubtype[this.primary] }
51
-
52
- /** List of resource paths of associated resources in order of priority.
53
- * @type {string[]}
54
- */
55
- get rpaths () {
56
- return Object.keys(this.resourceBySubtype || {}).map((subtype) => {
57
- return this.resourceBySubtype[subtype].rpath
58
- })
59
- }
60
-
61
- /** Add a Resource from a gayeway resource.
62
- *
63
- * @param {string} rtype - The type of the resource:
64
- * `config`, `group`, `light`, or `sensor`.
65
- * @param {integer} rid - The resource ID of the resource.
66
- * @param {object} body - The body of the resource.
67
- * @params {DeconzDevice.ResourceAttributes} - Derived resource
68
- * attributes.
69
- */
70
- addResource (rtype, rid, body, attrs) {
71
- const { id, subtype, zigbee } = attrs
72
- if (this.resourceBySubtype[subtype] != null) {
73
- const r = this.resourceBySubtype[subtype]
74
- throw new Error(
75
- `${attrs.resource}: duplicate uniqueid ${body.uniqueid} in ${r.attrs.resource}`
76
- )
77
- }
78
- if (zigbee !== this.zigbee || (zigbee && id !== this.id)) {
79
- const r = this.resourceBySubtype[subtype]
80
- throw new SyntaxError(
81
- `${attrs.resource}: cannot combine ${r.attrs.resource}`
82
- )
83
- }
84
- this.resourceBySubtype[subtype] = new Resource(rtype, rid, body, attrs)
85
- if (
86
- this.primary == null || (
87
- this.resource.rtype === rtype && this.resource.attrs.prio < attrs.prio
88
- )
89
- ) {
90
- /** The subtype of the primary
91
- * {@link DeconzDevice.Resource Resource}.
92
- *
93
- * @type {string}
94
- */
95
- this.primary = subtype
96
- }
97
- return this.resourceBySubtype[subtype]
98
- }
99
- }
100
-
101
- /** A resource exposed by the gateway.
102
- *
103
- * @memberof DeconzDevice
104
- */
105
- class Resource {
106
- /** Instantiate a Resource from a gayeway resource.
107
- *
108
- * @param {string} rtype - The type of the resource:
109
- * `config`, `group`, `light`, or `sensor`.
110
- * @param {integer} rid - The resource ID of the resource.
111
- * @param {object} body - The body of the resource.
112
- * @params {DeconzDevice.ResourceAttributes} attrs - Derived
113
- * resource attributes.
114
- */
115
- constructor (rtype, rid, body, attrs) {
116
- /** The resource type: `groups`, `lights`, or `sensors`.
117
- * @type {string}
118
- */
119
- this.rtype = rtype
120
-
121
- /** The resource ID.
122
- * @type {integer}
123
- */
124
- this.rid = rid
125
-
126
- /** The resource body.
127
- * @param {object}
128
- */
129
- this.body = body
130
-
131
- this.attrs = attrs
132
- }
133
-
134
- /** The associated HomeKit Accessory category.
135
- * `null` for unknown types.
136
- * @type {?Accessory.Category}
137
- */
138
- get category () { return this.attrs.type.category }
139
-
140
- /** The associated device ID.
141
- *
142
- * For Zigbee devices, the device ID is based on the Zigbee mac address
143
- * of the device.
144
- * For virtual devices, the device ID is based on the Zigbee mac address
145
- * of the gayeway and the resource.
146
- * The UUID of the associated HomeKit accessory is based on the device ID.
147
- * @type {string}
148
- */
149
- get id () { return this.attrs.id }
150
-
151
- /** The priority of the resource type when determining the primary service.
152
- * @type {integer}
153
- */
154
- get prio () { return this.attrs.type.prio }
155
-
156
- /** The resource exposed by the gateway, e.g. `/lights/1`
157
- * @type {string}
158
- */
159
- get rpath () { return '/' + this.rtype + '/' + this.rid }
160
-
161
- /** The name of the DeconzService to expose the resouce type.
162
- * `null` for unsupported types.
163
- * @type {string}
164
- */
165
- get serviceName () { return this.attrs.type.serviceName }
166
-
167
- /** The subtype of the associated HomeKit service.
168
- *
169
- * For Zigbee devices, the subtype is based on the Zigbee endpoint and
170
- * cluster, corresponding to the resouce.
171
- * For virtual devices, the subtype is based on the resource.
172
- * @type {string[]}
173
- */
174
- get subtype () { return this.attrs.subtype }
175
-
176
- /** Zigbee device vs virtual device.
177
- * @type {boolean}
178
- */
179
- get zigbee () { return this.attrs.zigbee }
180
- }
181
-
182
- /** Derived attributes of a resource.
183
- * @hideconstructor
184
- * @memberof DeconzDevice
185
- */
186
- class ResourceAttributes {
187
- constructor (id, subtype, type, zigbee) {
188
- /** The associated device ID.
189
- *
190
- * For Zigbee devices, the device ID is based on the Zigbee mac address
191
- * of the device.
192
- * For virtual devices, the device ID is based on the Zigbee mac address
193
- * of the gayeway and the resource.
194
- * The UUID of the associated HomeKit accessory is based on the device ID.
195
- * @type {string}
196
- */
197
- this.id = id
198
-
199
- /** The subtype of the associated HomeKit service.
200
- *
201
- * For Zigbee devices, the subtype is based on the Zigbee endpoint and
202
- * cluster, corresponding to the resouce.
203
- * For virtual devices, the subtype is based on the resource.
204
- * @type {string}
205
- */
206
- this.subtype = subtype
207
-
208
- /** The derviced attributes of the resource type.
209
- * @type {DeconzDevice.TypeAttributes}
210
- */
211
- this.type = type
212
-
213
- /** Zigbee device vs virtual device.
214
- * @type {boolean}
215
- */
216
- this.zigbee = zigbee
217
- }
218
- }
219
-
220
- /** Derived attributes of a resource type.
221
- * @hideconstructor
222
- * @memberof DeconzDevice
223
- */
224
- class TypeAttributes {
225
- constructor (category, serviceName, prio = 0) {
226
- /** The associated HomeKit Accessory category.
227
- * `null` for unknown types.
228
- * @type {?Accessory.Category}
229
- */
230
- this.category = category
231
-
232
- /** The name of the {@link DeconzService} to expose the resouce type.
233
- * `null` for unsupported types.
234
- * @type {string}
235
- */
236
- this.serviceName = serviceName
237
-
238
- /** The priority of the resource type when determining the primary service.
239
- * @type {integer}
240
- */
241
- this.prio = prio
242
- }
243
- }
244
-
245
- module.exports = DeconzDevice
@@ -1,58 +0,0 @@
1
- // homebridge-deconz/lib/DeconzService/Sensor.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 deconzClient = require('../deconzClient')
10
-
11
- class Sensor extends homebridgeLib.ServiceDelegate {
12
- constructor (device, params = {}) {
13
- super(device, params)
14
- this.id = params.id
15
- this.platform = device.platform
16
- this.gateway = device.gateway
17
- this.client = device.client
18
- this.rtype = '/sensors'
19
- this.rid = params.rid
20
- this.resouce = this.rtype + '/' + this.rid
21
- }
22
-
23
- addCharacteristicDelegates (params = {}) {
24
- this.addCharacteristicDelegate({
25
- key: 'lastUpdated',
26
- Characteristic: this.Characteristics.my.LastUpdated,
27
- silent: true
28
- })
29
- this.addCharacteristicDelegate({
30
- key: 'enabled',
31
- Characteristic: this.Characteristics.my.Enabled
32
- }).on('didSet', (value) => {
33
- this.values.statusActive = value
34
- })
35
- this.addCharacteristicDelegate({
36
- key: 'statusActive',
37
- Characteristic: this.Characteristics.hap.StatusActive
38
- })
39
- this.addCharacteristicDelegate({
40
- key: 'statusFault',
41
- Characteristic: this.Characteristics.hap.StatusFault
42
- })
43
- }
44
-
45
- update (sensor) {
46
- this.values.lastUpdated = deconzClient.dateToString(sensor.state.lastupdated)
47
- this.values.enabled = sensor.config.on
48
- this.values.statusFault = sensor.config.reachable === false
49
- ? this.Characteristics.hap.StatusFault.GENERAL_FAULT
50
- : this.Characteristics.hap.StatusFault.NO_FAULT
51
- }
52
-
53
- async put (resource, body) {
54
- return this.client.put(this.resource + resource, body)
55
- }
56
- }
57
-
58
- module.exports = Sensor
@@ -1,43 +0,0 @@
1
- // homebridge-deconz/lib/DeconzService.js
2
- // Copyright © 2022 Erik Baauw. All rights reserved.
3
- //
4
- // Homebridge plugin for deCONZ.
5
-
6
- 'use strict'
7
-
8
- /** Service delegates.
9
- * @hideconstructor
10
- */
11
- class DeconzService {
12
- static get AirQuality () { return require('./DeconzService/AirQuality') }
13
- static get Alarm () { return require('./DeconzService/Alarm') }
14
- // static get Battery () { return require('./DeconzService/Battery') }
15
- static get Button () { return require('./DeconzService/Button') }
16
- // static get CarbonMonoxide () { return require('./DeconzService/CarbonMonoxide') }
17
- // static get Consumption () { return require('./DeconzService/Consumption') }
18
- // static get Daylight () { return require('./DeconzService/Daylight') }
19
- static get DeviceSettings () { return require('./DeconzService/DeviceSettings') }
20
- // static get Flag () { return require('./DeconzService/Flag') }
21
- // static get Fire () { return require('./DeconzService/Fire') }
22
- static get GatewaySettings () { return require('./DeconzService/GatewaySettings') }
23
- // static get Humidity () { return require('./DeconzService/Humidity') }
24
- // static get Light () { return require('./DeconzService/Light') }
25
- // static get LightBulb () { return require('./DeconzService/LightBulb') }
26
- // static get LightLevel () { return require('./DeconzService/LightLevel') }
27
- // static get Outlet () { return require('./DeconzService/Outlet') }
28
- // static get OpenClose () { return require('./DeconzService/OpenClose') }
29
- // static get Power () { return require('./DeconzService/Power') }
30
- // static get Presence () { return require('./DeconzService/Presence') }
31
- // static get Pressure () { return require('./DeconzService/Pressure') }
32
- static get Sensor () { return require('./DeconzService/Sensor') }
33
- // static get Status () { return require('./DeconzService/Status') }
34
- // static get Switch () { return require('./DeconzService/Switch') }
35
- // static get Temperature () { return require('./DeconzService/Temperature') }
36
- // static get Thermostat () { return require('./DeconzService/Thermostat') }
37
- // static get Vibration () { return require('./DeconzService/Vibration') }
38
- // static get Water () { return require('./DeconzService/Water') }
39
- // static get WarningDevice () { return require('./DeconzService/WarningDevice') }
40
- // static get WindowCovering () { return require('./DeconzService/WindowCovering') }
41
- }
42
-
43
- module.exports = DeconzService