homebridge-deconz 1.0.1 → 1.0.3

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.
@@ -46,45 +46,108 @@ class Light extends DeconzAccessory {
46
46
  }
47
47
 
48
48
  const params = {}
49
- if (this.values.serviceName === 'Outlet') {
50
- this.service.addCharacteristicDelegate({
51
- key: 'lockPhysicalControls',
52
- Characteristic: this.Characteristics.hap.LockPhysicalControls
53
- })
54
- params.onDelegate = this.service.characteristicDelegate('on')
55
- params.lastOnDelegate = this.service.addCharacteristicDelegate({
49
+
50
+ if (this.values.serviceName === 'Valve') {
51
+ // No history
52
+ } else if (
53
+ this.servicesByServiceName[this.values.serviceName].length > 1 ||
54
+ this.values.serviceName === 'Light'
55
+ ) {
56
+ params.lightOnDelegate = this.service.characteristicDelegate('on')
57
+ params.lastLightOnDelegate = this.service.addCharacteristicDelegate({
56
58
  key: 'lastActivation',
57
59
  Characteristic: this.Characteristics.eve.LastActivation,
58
60
  silent: true
59
61
  })
60
- } else if (this.values.serviceName !== 'Valve') {
61
- params.lightOnDelegate = this.service.characteristicDelegate('on')
62
- params.lastLightOnDelegate = this.service.addCharacteristicDelegate({
62
+ } else { // Outlet or Switch
63
+ if (this.values.serviceName === 'Outlet') {
64
+ this.service.addCharacteristicDelegate({
65
+ key: 'lockPhysicalControls',
66
+ Characteristic: this.Characteristics.hap.LockPhysicalControls
67
+ })
68
+ }
69
+ params.onDelegate = this.service.characteristicDelegate('on')
70
+ params.lastOnDelegate = this.service.addCharacteristicDelegate({
63
71
  key: 'lastActivation',
64
72
  Characteristic: this.Characteristics.eve.LastActivation,
65
73
  silent: true
66
74
  })
67
75
  }
68
- if (this.service.characteristicDelegate('totalConsumption') != null) {
69
- params.totalConsumptionDelegate = this.service.characteristicDelegate('totalConsumption')
70
- if (this.service.values.consumption === undefined) {
76
+
77
+ if (this.servicesByServiceName.Consumption?.length === 1) {
78
+ const service = this.servicesByServiceName.Consumption[0]
79
+ params.totalConsumptionDelegate = service.characteristicDelegate('totalConsumption')
80
+ if (service.values.consumption === undefined) {
71
81
  // Power to be computed by history if not exposed by device
72
- params.computedConsumptionDelegate = this.service.addCharacteristicDelegate({
82
+ params.computedConsumptionDelegate = service.addCharacteristicDelegate({
73
83
  key: 'consumption',
74
84
  Characteristic: this.Characteristics.eve.Consumption,
75
85
  unit: ' W'
76
86
  })
77
87
  }
78
- } else if (this.service.characteristicDelegate('consumption') != null) {
79
- params.consumptionDelegate = this.service.characteristicDelegate('consumption')
88
+ } else if (this.servicesByServiceName.Power?.length === 1) {
89
+ const service = this.servicesByServiceName.Power[0]
90
+ params.consumptionDelegate = service.characteristicDelegate('consumption')
80
91
  // Total Consumption to be computed by history
81
- params.computedTotalConsumptionDelegate = this.service.addCharacteristicDelegate({
92
+ params.computedTotalConsumptionDelegate = service.addCharacteristicDelegate({
82
93
  key: 'totalConsumption',
83
94
  Characteristic: this.Characteristics.eve.TotalConsumption,
84
95
  unit: ' kWh'
85
96
  })
86
97
  }
87
- this.historyService = new ServiceDelegate.History(this, params)
98
+
99
+ if (Object.keys(params).length > 0) {
100
+ this.historyService = new ServiceDelegate.History(this, params)
101
+ }
102
+
103
+ if (this.servicesByServiceName[this.values.serviceName].length === 1) {
104
+ if (
105
+ this.values.serviceName === 'Outlet' &&
106
+ this.servicesByServiceName.Consumption == null &&
107
+ this.servicesByServiceName.Power == null
108
+ ) {
109
+ // Dumb Outlet
110
+ const service = new ServiceDelegate(this, {
111
+ name: this.name + ' Consumption',
112
+ Service: this.Services.eve.Consumption,
113
+ hidden: true
114
+ })
115
+ service.addCharacteristicDelegate({
116
+ key: 'dummyTotalConsumption',
117
+ Characteristic: this.Characteristics.eve.TotalConsumption,
118
+ props: {
119
+ perms: [
120
+ this.Characteristic.Perms.PAIRED_READ,
121
+ this.Characteristic.Perms.NOTIFY,
122
+ this.Characteristic.Perms.HIDDEN
123
+ ]
124
+ },
125
+ silent: true,
126
+ value: 0
127
+ })
128
+ }
129
+ } else {
130
+ for (const i in this.servicesByServiceName[this.values.serviceName]) {
131
+ const service = this.servicesByServiceName[this.values.serviceName][i]
132
+ service.addCharacteristicDelegate({
133
+ key: 'index',
134
+ Characteristic: this.Characteristics.hap.ServiceLabelIndex,
135
+ silent: true,
136
+ value: Number(i)
137
+ })
138
+ if (i === '0') {
139
+ continue
140
+ }
141
+ this.historyService?.addLastOnDelegate(
142
+ service.characteristicDelegate('on'),
143
+ service.addCharacteristicDelegate({
144
+ key: 'lastActivation',
145
+ Characteristic: this.Characteristics.eve.LastActivation,
146
+ silent: true
147
+ })
148
+ )
149
+ }
150
+ }
88
151
 
89
152
  setImmediate(() => {
90
153
  this.debug('initialised')
@@ -106,10 +106,10 @@ class Sensor extends DeconzAccessory {
106
106
  params.vocDensityDelegate = service.characteristicDelegate('vocDensity')
107
107
  }
108
108
  }
109
- if (this.servicesByServiceName.Flag != null) {
109
+ if (this.servicesByServiceName.Flag?.length === 1) {
110
110
  const service = this.servicesByServiceName.Flag[0]
111
- params.switchOnDelegate = service.characteristicDelegate('on')
112
- params.lastSwitchOnDelegate = service.addCharacteristicDelegate({
111
+ params.onDelegate = service.characteristicDelegate('on')
112
+ params.lastOnDelegate = service.addCharacteristicDelegate({
113
113
  key: 'lastActivation',
114
114
  Characteristic: this.Characteristics.eve.LastActivation,
115
115
  silent: true
@@ -35,8 +35,8 @@ class WarningDevice extends DeconzAccessory {
35
35
 
36
36
  const params = {}
37
37
  if (this.servicesByServiceName.WarningDevice?.length === 1) {
38
- params.switchOnDelegate = this.service.characteristicDelegate('on')
39
- params.lastSwitchOnDelegate = this.service.addCharacteristicDelegate({
38
+ params.onDelegate = this.service.characteristicDelegate('on')
39
+ params.lastOnDelegate = this.service.addCharacteristicDelegate({
40
40
  key: 'lastActivation',
41
41
  Characteristic: this.Characteristics.eve.LastActivation,
42
42
  silent: true
@@ -164,16 +164,12 @@ class DeconzAccessory extends AccessoryDelegate {
164
164
  } else if (params.serviceName === 'Battery') {
165
165
  service = this.servicesByServiceName.Battery?.[0]
166
166
  } else if (params.serviceName === 'Consumption') {
167
- service = this.servicesByServiceName.Outlet?.[0] ||
168
- this.servicesByServiceName.Light?.[0] ||
169
- this.servicesByServiceName.Power?.[0]
167
+ service = this.servicesByServiceName.Power?.[0]
170
168
  if (service != null) {
171
169
  service.addResource(resource)
172
170
  }
173
171
  } else if (params.serviceName === 'Power') {
174
- service = this.servicesByServiceName.Outlet?.[0] ||
175
- this.servicesByServiceName.Light?.[0] ||
176
- this.servicesByServiceName.Consumption?.[0]
172
+ service = this.servicesByServiceName.Consumption?.[0]
177
173
  if (service != null) {
178
174
  service.addResource(resource)
179
175
  }
@@ -223,17 +219,6 @@ class DeconzAccessory extends AccessoryDelegate {
223
219
  return service
224
220
  }
225
221
 
226
- settings = {
227
- anyOn: { service: 'Lightbulb', type: 'bool' },
228
- buttonRepeat: { service: 'Button', type: 'boolMap' },
229
- effects: { service: 'Light', type: 'boolMap' },
230
- expose: { type: 'bool' },
231
- logLevel: { type: 'int', min: 0, max: 3 },
232
- lowBatteryThreshold: { service: 'Battery', type: 'int', min: 10, max: 100, factor: 100 },
233
- offset: { service: 'Temperature', type: 'number', min: -5, max: 5 },
234
- splitLight: { service: 'Light' }
235
- }
236
-
237
222
  onUiGet (details = false) {
238
223
  const resource = this.device.resourceBySubtype[this.device.primary]
239
224
  const body = {
@@ -56,7 +56,9 @@ class Consumption extends DeconzService.SensorsResource {
56
56
  }
57
57
 
58
58
  constructor (accessory, resource, params = {}) {
59
- params.Service = accessory.Services.my.Resource
59
+ params.name = accessory.name + ' Consumption'
60
+ params.Service = accessory.Services.eve.Consumption
61
+ params.exposeConfiguredName = true
60
62
  super(accessory, resource, params)
61
63
 
62
64
  Consumption.addResource(this, resource)
@@ -66,7 +66,9 @@ class Power extends DeconzService.SensorsResource {
66
66
  }
67
67
 
68
68
  constructor (accessory, resource, params = {}) {
69
- params.Service = accessory.Services.my.Resource
69
+ params.name = accessory.name + ' Consumption'
70
+ params.Service = accessory.Services.eve.Consumption
71
+ params.exposeConfiguredName = true
70
72
  super(accessory, resource, params)
71
73
 
72
74
  Power.addResource(this, resource)
@@ -6,6 +6,7 @@
6
6
  'use strict'
7
7
 
8
8
  const DeconzService = require('../DeconzService')
9
+ const { timeout } = require('homebridge-lib')
9
10
 
10
11
  class WarningDevice extends DeconzService.LightsResource {
11
12
  constructor (accessory, resource, params = {}) {
@@ -33,11 +34,10 @@ class WarningDevice extends DeconzService.LightsResource {
33
34
  body = { alert: 'lselect', ontime: onTime }
34
35
  }
35
36
  }
36
- this.put(body)
37
+ await this.put(this.statePath, body)
37
38
  if (value) {
38
- this.timer = setTimeout(() => {
39
- this.values.on = false
40
- }, onTime * 1000)
39
+ await timeout(onTime * 1000)
40
+ this.values.on = false
41
41
  }
42
42
  }
43
43
  })
@@ -5,8 +5,8 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- const { timeout } = require('homebridge-lib')
9
8
  const DeconzService = require('../DeconzService')
9
+ const { timeout } = require('homebridge-lib')
10
10
 
11
11
  class WindowCovering extends DeconzService.LightsResource {
12
12
  constructor (accessory, resource, params = {}) {
@@ -34,7 +34,7 @@ class WindowCovering extends DeconzService.LightsResource {
34
34
  return
35
35
  }
36
36
  this.values.targetPosition = Math.round(this.values.targetPosition / 5) * 5
37
- await this.setPosition()
37
+ return this.setPosition()
38
38
  })
39
39
 
40
40
  this.addCharacteristicDelegate({
@@ -46,8 +46,8 @@ class WindowCovering extends DeconzService.LightsResource {
46
46
  this.addCharacteristicDelegate({
47
47
  key: 'holdPosition',
48
48
  Characteristic: this.Characteristics.hap.HoldPosition
49
- }).on('didSet', () => {
50
- this.put({ stop: true })
49
+ }).on('didSet', async () => {
50
+ await this.put(this.statePath, { stop: true })
51
51
  this.values.positionState = this.Characteristics.hap.PositionState.STOPPED
52
52
  })
53
53
 
@@ -60,7 +60,7 @@ class WindowCovering extends DeconzService.LightsResource {
60
60
  return
61
61
  }
62
62
  if (this.values.currentPosition !== 100) {
63
- await this.setPosition()
63
+ return this.setPosition()
64
64
  }
65
65
  })
66
66
  }
@@ -80,7 +80,7 @@ class WindowCovering extends DeconzService.LightsResource {
80
80
  if (!fromHomeKit) {
81
81
  return
82
82
  }
83
- await this.put({ speed: value })
83
+ await this.put('/config', { speed: value })
84
84
  })
85
85
  }
86
86
 
@@ -90,7 +90,7 @@ class WindowCovering extends DeconzService.LightsResource {
90
90
  Characteristic: this.Characteristics.my.PositionChange
91
91
  }).on('didSet', async (value) => {
92
92
  if (value !== 0) {
93
- this.put({ lift_inc: -value })
93
+ await this.put(this.statePath, { lift_inc: -value })
94
94
  await timeout(this.platform.config.waitTimeReset)
95
95
  this.values.positionChange = 0
96
96
  }
@@ -120,7 +120,7 @@ class WindowCovering extends DeconzService.LightsResource {
120
120
  ? this.Characteristics.hap.PositionState.INCREASING
121
121
  : this.Characteristics.hap.PositionState.DECREASING
122
122
  this.moving = new Date()
123
- await this.put({ lift })
123
+ return this.put(this.statePath, { lift })
124
124
  }
125
125
 
126
126
  updateState (state) {
@@ -49,7 +49,7 @@ class DeconzService extends ServiceDelegate {
49
49
  constructor (accessory, resource, params) {
50
50
  super(accessory, {
51
51
  id: resource.id,
52
- name: resource.body.name,
52
+ name: params.name ?? resource.body.name,
53
53
  Service: params.Service,
54
54
  subtype: resource.subtype,
55
55
  primaryService: params.primaryService,
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": "1.0.1",
7
+ "version": "1.0.3",
8
8
  "keywords": [
9
9
  "homebridge-plugin",
10
10
  "homekit",
@@ -24,11 +24,11 @@
24
24
  "engines": {
25
25
  "deCONZ": "2.23.1",
26
26
  "homebridge": "^1.6.1",
27
- "node": "20.7.0||^20||^18"
27
+ "node": "20.8.0||^20||^18"
28
28
  },
29
29
  "dependencies": {
30
- "hb-deconz-tools": "~1.0.7",
31
- "homebridge-lib": "~6.5.1"
30
+ "hb-deconz-tools": "~1.0.8",
31
+ "homebridge-lib": "~6.6.1"
32
32
  },
33
33
  "scripts": {
34
34
  "prepare": "standard && rm -rf out && jsdoc -c jsdoc.json",