homebridge-deconz 1.0.2 → 1.0.4

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.
@@ -33,101 +33,122 @@ class Light extends DeconzAccessory {
33
33
  serviceName: this.values.serviceName
34
34
  })
35
35
 
36
+ for (const subtype in device.resourceBySubtype) {
37
+ const resource = device.resourceBySubtype[subtype]
38
+ if (subtype === device.primary) {
39
+ continue
40
+ }
41
+ if (resource.rtype === 'lights') {
42
+ this.createService(resource, { serviceName: this.values.serviceName })
43
+ } else {
44
+ this.createService(resource)
45
+ }
46
+ }
47
+
36
48
  const params = {}
37
49
 
38
- if (this.values.serviceName === 'Outlet') {
39
- this.service.addCharacteristicDelegate({
40
- key: 'lockPhysicalControls',
41
- Characteristic: this.Characteristics.hap.LockPhysicalControls
42
- })
43
- params.onDelegate = this.service.characteristicDelegate('on')
44
- params.lastOnDelegate = this.service.addCharacteristicDelegate({
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({
45
58
  key: 'lastActivation',
46
59
  Characteristic: this.Characteristics.eve.LastActivation,
47
60
  silent: true
48
61
  })
49
- } else if (this.values.serviceName === 'Switch') {
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
+ }
50
69
  params.onDelegate = this.service.characteristicDelegate('on')
51
70
  params.lastOnDelegate = this.service.addCharacteristicDelegate({
52
71
  key: 'lastActivation',
53
72
  Characteristic: this.Characteristics.eve.LastActivation,
54
73
  silent: true
55
74
  })
56
- } else if (this.values.serviceName === 'Light') {
57
- params.lightOnDelegate = this.service.characteristicDelegate('on')
58
- params.lastLightOnDelegate = this.service.addCharacteristicDelegate({
59
- key: 'lastActivation',
60
- Characteristic: this.Characteristics.eve.LastActivation,
61
- silent: true
62
- })
63
75
  }
64
76
 
65
- if (this.service.characteristicDelegate('totalConsumption') != null) {
66
- params.totalConsumptionDelegate = this.service.characteristicDelegate('totalConsumption')
67
- if (this.service.values.consumption === undefined) {
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) {
68
81
  // Power to be computed by history if not exposed by device
69
- params.computedConsumptionDelegate = this.service.addCharacteristicDelegate({
82
+ params.computedConsumptionDelegate = service.addCharacteristicDelegate({
70
83
  key: 'consumption',
71
84
  Characteristic: this.Characteristics.eve.Consumption,
72
85
  unit: ' W'
73
86
  })
74
87
  }
75
- } else if (this.service.characteristicDelegate('consumption') != null) {
76
- 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')
77
91
  // Total Consumption to be computed by history
78
- params.computedTotalConsumptionDelegate = this.service.addCharacteristicDelegate({
92
+ params.computedTotalConsumptionDelegate = service.addCharacteristicDelegate({
79
93
  key: 'totalConsumption',
80
94
  Characteristic: this.Characteristics.eve.TotalConsumption,
81
95
  unit: ' kWh'
82
96
  })
83
97
  }
84
- this.historyService = new ServiceDelegate.History(this, params)
85
98
 
86
- for (const subtype in device.resourceBySubtype) {
87
- const resource = device.resourceBySubtype[subtype]
88
- if (subtype === device.primary) {
89
- continue
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
+ })
90
128
  }
91
- if (resource.rtype === 'lights') {
92
- const service = this.createService(resource, { serviceName: this.values.serviceName })
93
- if (this.values.serviceName !== 'Valve') {
94
- this.historyService.addLastOnDelegate(
95
- service.characteristicDelegate('on'),
96
- service.addCharacteristicDelegate({
97
- key: 'lastActivation',
98
- Characteristic: this.Characteristics.eve.LastActivation,
99
- silent: true
100
- })
101
- )
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
102
140
  }
103
- } else {
104
- this.createService(resource)
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
+ )
105
149
  }
106
150
  }
107
151
 
108
- if (
109
- this.values.serviceName === 'Outlet' &&
110
- this.service.characteristicDelegate('totalConsumption') == null &&
111
- this.service.characteristicDelegate('consumption') == null &&
112
- this.servicesByServiceName.Outlet?.length === 1
113
- ) {
114
- // Dumb Outlet
115
- this.warn('dumb outlet')
116
- this.service.addCharacteristicDelegate({
117
- key: 'dummyTotalConsumption',
118
- Characteristic: this.Characteristics.eve.TotalConsumption,
119
- props: {
120
- perms: [
121
- this.Characteristic.Perms.PAIRED_READ,
122
- this.Characteristic.Perms.NOTIFY,
123
- this.Characteristic.Perms.HIDDEN
124
- ]
125
- },
126
- silent: true,
127
- value: 0
128
- })
129
- }
130
-
131
152
  setImmediate(() => {
132
153
  this.debug('initialised')
133
154
  this.emit('initialised')
@@ -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
  }
@@ -203,11 +199,11 @@ class DeconzAccessory extends AccessoryDelegate {
203
199
  service = new DeconzService[params.serviceName](this, resource, {
204
200
  primaryService: params.primaryService
205
201
  })
206
- if (this.servicesByServiceName[params.serviceName] == null) {
207
- this.servicesByServiceName[params.serviceName] = [service]
208
- } else {
209
- this.servicesByServiceName[params.serviceName].push(service)
210
- }
202
+ }
203
+ if (this.servicesByServiceName[params.serviceName] == null) {
204
+ this.servicesByServiceName[params.serviceName] = [service]
205
+ } else {
206
+ this.servicesByServiceName[params.serviceName].push(service)
211
207
  }
212
208
  if (params.serviceName === 'Label') {
213
209
  service.createButtonServices(resource, params)
@@ -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)
@@ -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.2",
7
+ "version": "1.0.4",
8
8
  "keywords": [
9
9
  "homebridge-plugin",
10
10
  "homekit",
@@ -22,13 +22,13 @@
22
22
  "ui": "cli/ui.js"
23
23
  },
24
24
  "engines": {
25
- "deCONZ": "2.23.1",
25
+ "deCONZ": "2.23.2",
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.6.0"
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",