homebridge-deconz 0.1.4 → 0.1.7
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 +47 -43
- package/cli/ui.js +419 -0
- package/jsdoc.json +1 -0
- package/lib/Deconz/ApiClient.js +23 -23
- package/lib/Deconz/ApiError.js +2 -2
- package/lib/Deconz/ApiResponse.js +2 -2
- package/lib/Deconz/Discovery.js +6 -6
- package/lib/Deconz/Resource.js +4 -4
- package/lib/Deconz/WsClient.js +4 -4
- package/lib/DeconzAccessory/Gateway.js +26 -63
- package/lib/DeconzAccessory/Light.js +2 -4
- package/lib/DeconzAccessory/Sensor.js +6 -7
- package/lib/DeconzAccessory/Thermostat.js +2 -4
- package/lib/DeconzAccessory/WarningDevice.js +0 -3
- package/lib/DeconzAccessory/index.js +2 -3
- package/lib/DeconzPlatform.js +5 -5
- package/lib/DeconzService/Battery.js +2 -2
- package/lib/DeconzService/Button.js +2 -2
- package/lib/DeconzService/Gateway.js +2 -2
- package/lib/DeconzService/Light.js +6 -7
- package/lib/DeconzService/LightsResource.js +1 -2
- package/lib/DeconzService/WindowCovering.js +1 -3
- package/lib/DeconzService/index.js +2 -2
- package/package.json +5 -5
- package/cli/ui.sh +0 -83
package/lib/DeconzPlatform.js
CHANGED
@@ -6,11 +6,11 @@
|
|
6
6
|
'use strict'
|
7
7
|
|
8
8
|
const events = require('events')
|
9
|
-
const
|
9
|
+
const { HttpClient, OptionParser, Platform, timeout } = require('homebridge-lib')
|
10
10
|
const Deconz = require('./Deconz')
|
11
11
|
const DeconzAccessory = require('./DeconzAccessory')
|
12
12
|
|
13
|
-
class DeconzPlatform extends
|
13
|
+
class DeconzPlatform extends Platform {
|
14
14
|
constructor (log, configJson, homebridge, bridge) {
|
15
15
|
super(log, configJson, homebridge)
|
16
16
|
this.parseConfigJson(configJson)
|
@@ -38,7 +38,7 @@ class DeconzPlatform extends homebridgeLib.Platform {
|
|
38
38
|
waitTimeReset: 500,
|
39
39
|
waitTimeUpdate: 100
|
40
40
|
}
|
41
|
-
const optionParser = new
|
41
|
+
const optionParser = new OptionParser(this.config, true)
|
42
42
|
optionParser
|
43
43
|
.on('userInputError', (message) => {
|
44
44
|
this.warn('config.json: %s', message)
|
@@ -71,7 +71,7 @@ class DeconzPlatform extends homebridgeLib.Platform {
|
|
71
71
|
})
|
72
72
|
this.discovery
|
73
73
|
.on('error', (error) => {
|
74
|
-
if (error instanceof
|
74
|
+
if (error instanceof HttpClient.HttpError) {
|
75
75
|
this.log(
|
76
76
|
'%s: request %d: %s %s', error.request.name,
|
77
77
|
error.request.id, error.request.method, error.request.resource
|
@@ -123,7 +123,7 @@ class DeconzPlatform extends homebridgeLib.Platform {
|
|
123
123
|
await this.foundGateway(host, config)
|
124
124
|
} catch (error) {
|
125
125
|
this.warn('%s: %s - retrying in 60s', host, error)
|
126
|
-
await
|
126
|
+
await timeout(60000)
|
127
127
|
return this.findHost(host)
|
128
128
|
}
|
129
129
|
}
|
@@ -6,13 +6,13 @@
|
|
6
6
|
'use strict'
|
7
7
|
|
8
8
|
const Deconz = require('../Deconz')
|
9
|
-
const
|
9
|
+
const { ServiceDelegate } = require('homebridge-lib')
|
10
10
|
const { dateToString } = Deconz.ApiClient
|
11
11
|
|
12
12
|
/**
|
13
13
|
* @memberof DeconzService
|
14
14
|
*/
|
15
|
-
class Battery extends
|
15
|
+
class Battery extends ServiceDelegate.Battery {
|
16
16
|
constructor (accessory, resource, params = {}) {
|
17
17
|
super(accessory, {
|
18
18
|
name: accessory.name + ' Battery',
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
'use strict'
|
7
7
|
|
8
|
-
const
|
8
|
+
const { ServiceDelegate } = require('homebridge-lib')
|
9
9
|
|
10
10
|
const deconzEvent = {
|
11
11
|
PRESS: 0,
|
@@ -25,7 +25,7 @@ let homeKitEvent
|
|
25
25
|
/**
|
26
26
|
* @memberof DeconzService
|
27
27
|
*/
|
28
|
-
class Button extends
|
28
|
+
class Button extends ServiceDelegate {
|
29
29
|
static get SINGLE () { return 0x01 }
|
30
30
|
static get DOUBLE () { return 0x02 }
|
31
31
|
static get LONG () { return 0x04 }
|
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
'use strict'
|
7
7
|
|
8
|
-
const
|
8
|
+
const { ServiceDelegate } = require('homebridge-lib')
|
9
9
|
|
10
10
|
/** Delegate class for a DeconzGateway service.
|
11
11
|
* @extends ServiceDelegate
|
12
12
|
* @memberof DeconzService
|
13
13
|
*/
|
14
|
-
class Gateway extends
|
14
|
+
class Gateway extends ServiceDelegate {
|
15
15
|
constructor (gateway, params = {}) {
|
16
16
|
params.Service = gateway.Services.my.DeconzGateway
|
17
17
|
params.exposeConfiguredName = true
|
@@ -5,12 +5,11 @@
|
|
5
5
|
|
6
6
|
'use strict'
|
7
7
|
|
8
|
-
const
|
8
|
+
const { AdaptiveLighting, Colour, ServiceDelegate, timeout } = require('homebridge-lib')
|
9
9
|
const DeconzService = require('../DeconzService')
|
10
10
|
|
11
|
-
const {
|
12
|
-
const {
|
13
|
-
const { xyToHsv, hsvToXy, ctToXy } = homebridgeLib.Colour
|
11
|
+
const { xyToHsv, hsvToXy, ctToXy } = Colour
|
12
|
+
const { History } = ServiceDelegate
|
14
13
|
|
15
14
|
class Light extends DeconzService.LightsResource {
|
16
15
|
constructor (accessory, resource, params = {}) {
|
@@ -291,7 +290,7 @@ class Light extends DeconzService.LightsResource {
|
|
291
290
|
})
|
292
291
|
for (const id in this.capabilities.effects) {
|
293
292
|
const effect = this.capabilities.effects[id]
|
294
|
-
const service = new
|
293
|
+
const service = new ServiceDelegate(this.accessoryDelegate, {
|
295
294
|
name: this.resource.body.name + ' ' + effect,
|
296
295
|
Service: this.Services.hap.Lightbulb,
|
297
296
|
subtype: (this.subtype == null ? 'E' : this.subtype + '-E') + id
|
@@ -461,7 +460,7 @@ class Light extends DeconzService.LightsResource {
|
|
461
460
|
for (const scene of scenes) {
|
462
461
|
sceneById[scene.id] = scene
|
463
462
|
if (this.sceneServices[scene.id] == null) {
|
464
|
-
const service = new
|
463
|
+
const service = new ServiceDelegate(this.accessoryDelegate, {
|
465
464
|
name: this.resource.body.name + ' ' + scene.name,
|
466
465
|
Service: this.Services.hap.Lightbulb,
|
467
466
|
subtype: this.subtype + '-S' + scene.id,
|
@@ -504,7 +503,7 @@ class Light extends DeconzService.LightsResource {
|
|
504
503
|
initAdaptiveLighting () {
|
505
504
|
if (this.adaptiveLightingNotInitialised) {
|
506
505
|
delete this.adaptiveLightingNotInitialised
|
507
|
-
this.adaptiveLighting = new
|
506
|
+
this.adaptiveLighting = new AdaptiveLighting(
|
508
507
|
this.brightnessDelegate, this.colorTemperatureDelegate
|
509
508
|
)
|
510
509
|
if (this.values.activeTransitionCount > 0) {
|
@@ -5,12 +5,11 @@
|
|
5
5
|
|
6
6
|
'use strict'
|
7
7
|
|
8
|
-
const
|
8
|
+
const { timeout } = require('homebridge-lib')
|
9
9
|
const Deconz = require('../Deconz')
|
10
10
|
const DeconzService = require('../DeconzService')
|
11
11
|
|
12
12
|
const { HttpError } = Deconz.ApiClient
|
13
|
-
const { timeout } = homebridgeLib
|
14
13
|
|
15
14
|
class LightsResource extends DeconzService {
|
16
15
|
constructor (accessory, resource, params) {
|
@@ -5,11 +5,9 @@
|
|
5
5
|
|
6
6
|
'use strict'
|
7
7
|
|
8
|
-
const
|
8
|
+
const { timeout } = require('homebridge-lib')
|
9
9
|
const DeconzService = require('../DeconzService')
|
10
10
|
|
11
|
-
const { timeout } = homebridgeLib
|
12
|
-
|
13
11
|
class WindowCovering extends DeconzService.LightsResource {
|
14
12
|
constructor (accessory, resource, params = {}) {
|
15
13
|
params.Service = accessory.Services.hap.WindowCovering
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
'use strict'
|
7
7
|
|
8
|
-
const
|
8
|
+
const { ServiceDelegate } = require('homebridge-lib')
|
9
9
|
const Deconz = require('../Deconz')
|
10
10
|
|
11
11
|
const { dateToString } = Deconz.ApiClient
|
@@ -13,7 +13,7 @@ const { dateToString } = Deconz.ApiClient
|
|
13
13
|
/** Service delegates.
|
14
14
|
* @extends ServiceDelegate
|
15
15
|
*/
|
16
|
-
class DeconzService extends
|
16
|
+
class DeconzService extends ServiceDelegate {
|
17
17
|
static get AirPressure () { return require('./AirPressure') }
|
18
18
|
static get AirPurifier () { return require('./AirPurifier') }
|
19
19
|
static get AirQuality () { return require('./AirQuality') }
|
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.1.
|
7
|
+
"version": "0.1.7",
|
8
8
|
"keywords": [
|
9
9
|
"homebridge-plugin",
|
10
10
|
"homekit",
|
@@ -18,16 +18,16 @@
|
|
18
18
|
"main": "index.js",
|
19
19
|
"bin": {
|
20
20
|
"deconz": "cli/deconz.js",
|
21
|
-
"ui": "cli/ui.
|
21
|
+
"ui": "cli/ui.js"
|
22
22
|
},
|
23
23
|
"engines": {
|
24
24
|
"deCONZ": "2.19.3",
|
25
25
|
"homebridge": "^1.6.0",
|
26
|
-
"node": "^18.14.
|
26
|
+
"node": "^18.14.1"
|
27
27
|
},
|
28
28
|
"dependencies": {
|
29
|
-
"homebridge-lib": "~6.3.
|
30
|
-
"ws": "^8.12.
|
29
|
+
"homebridge-lib": "~6.3.10",
|
30
|
+
"ws": "^8.12.1",
|
31
31
|
"xml2js": "~0.4.23"
|
32
32
|
},
|
33
33
|
"scripts": {
|
package/cli/ui.sh
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
# homebridge-deconz/cli/ui.sh
|
4
|
-
# Copyright © 2023 Erik Baauw. All rights reserved.
|
5
|
-
#
|
6
|
-
# Command line interface to Homebridge deCONZ UI Server.
|
7
|
-
|
8
|
-
me=$(basename "$0")
|
9
|
-
|
10
|
-
function fatal() {
|
11
|
-
echo "${me}: $1" >&2
|
12
|
-
exit 1
|
13
|
-
}
|
14
|
-
|
15
|
-
if [ -z "${HOMEBRIDGE_DIR}" ] ; then
|
16
|
-
if [ -d /var/lib/homebridge ] ; then
|
17
|
-
HOMEBRIDGE_DIR=/var/lib/homebridge
|
18
|
-
elif [ -d ~/.homebridge ] ; then
|
19
|
-
HOMEBRIDGE_DIR=~/.homebridge
|
20
|
-
else
|
21
|
-
fatal "cannot find Homebridge directory - set HOMEBRIDGE_DIR"
|
22
|
-
fi
|
23
|
-
fi
|
24
|
-
|
25
|
-
if [ ! -f "${HOMEBRIDGE_DIR}/config.json" ] ; then
|
26
|
-
fatal "${HOMEBRIDGE_DIR|}/config.json: no such file"
|
27
|
-
fi
|
28
|
-
|
29
|
-
platformId=$(json -alp /platforms "${HOMEBRIDGE_DIR}/config.json" | grep /platform:\"deCONZ\" | cut -d / -f 2)
|
30
|
-
if [ -z "${platformId}" ] ; then
|
31
|
-
fatal "${HOMEBRIDGE_DIR}/config.json: cannot find deCONZ platform"
|
32
|
-
fi
|
33
|
-
|
34
|
-
username=$(json -alp /platforms/${platformId}/_bridge "${HOMEBRIDGE_DIR}/config.json" | grep /username: | cut -d \" -f 2 | sed -e "s/://g")
|
35
|
-
if [ -z "${username}" ] ; then
|
36
|
-
# Main Homebridge instance
|
37
|
-
cachedAccessories="${HOMEBRIDGE_DIR}/accessories/cachedAccessories"
|
38
|
-
else
|
39
|
-
# Child bridge instance
|
40
|
-
cachedAccessories="${HOMEBRIDGE_DIR}/accessories/cachedAccessories.${username}"
|
41
|
-
fi
|
42
|
-
if [ ! -f "${cachedAccessories}" ] ; then
|
43
|
-
fatal "${cachedAccessories}: no such file"
|
44
|
-
exit 1
|
45
|
-
fi
|
46
|
-
|
47
|
-
uiPort=$(json -alp /${platformId}/context "${cachedAccessories}" | grep /uiPort: | cut -d : -f 2)
|
48
|
-
gateway=$(json -alp /${platformId}/context "${cachedAccessories}" | grep /gid: | cut -d \" -f 2)
|
49
|
-
|
50
|
-
url="http://127.0.0.1:${uiPort}"
|
51
|
-
|
52
|
-
if [ "$(curl -s ${url}/ping)" != '"pong"' ] ; then
|
53
|
-
fatal "${url}: cannot connect to UI server"
|
54
|
-
fi
|
55
|
-
|
56
|
-
if [ -z "${1}" ] ; then
|
57
|
-
cat - >&2 <<+
|
58
|
-
Usage: ${me} command [arguments]
|
59
|
-
|
60
|
-
Commands:
|
61
|
-
get Get gateway details.
|
62
|
-
put body Update gateway settings.
|
63
|
-
getDevices Get list of devices.
|
64
|
-
getDevice id Get device details.
|
65
|
-
putDevice id body Update device settings.
|
66
|
-
getAccessories Get list of accessories
|
67
|
-
getAccessory id Get accessory details
|
68
|
-
putAccessory id body Update accessory settings.
|
69
|
-
+
|
70
|
-
exit 1
|
71
|
-
fi
|
72
|
-
|
73
|
-
case "$1" in
|
74
|
-
get) curl -s ${url}/gateways/${gateway} | json ;;
|
75
|
-
put) curl -s -X PUT -d "${2}" ${url}/gateways/${gateway}/settings | json ;;
|
76
|
-
getDevices) curl -s ${url}/gateways/${gateway}/devices | json ;;
|
77
|
-
getDevice) curl -s ${url}/gateways/${gateway}/devices/${1} | json ;;
|
78
|
-
putDevice) curl -s -X PUT -d "${2}" ${url}/gateways/${gateway}/devices/${1}/settings | json ;;
|
79
|
-
getAccessories) curl -s ${url}/gateways/${gateway}/accessories | json ;;
|
80
|
-
getAccessory) curl -s ${url}/gateways/${gateway}/accessories/${1} | json ;;
|
81
|
-
putAccessory) curl -s -X PUT -d "${2}" ${url}/gateways/${gateway}/accessories/${1}/settings | json ;;
|
82
|
-
*) fatal "${1}: invalid command" ;;
|
83
|
-
esac
|