homebridge-zencontrol-tpi 1.1.0-next.2 → 1.1.0-next.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # homebridge-zencontrol-tpi
2
2
 
3
+ ## 1.1.0-next.4
4
+
5
+ ### Minor Changes
6
+
7
+ - 86419e7: Add blind controller support
8
+
9
+ ## 1.1.0-next.3
10
+
11
+ ### Patch Changes
12
+
13
+ - d96d82d: Upgrade zencontrol-tpi-node to fix treatement of unused system variables
14
+
3
15
  ## 1.1.0-next.2
4
16
 
5
17
  ### Minor Changes
@@ -9,10 +9,18 @@
9
9
  "title": "Name",
10
10
  "required": true
11
11
  },
12
+ "blinds": {
13
+ "type": "array",
14
+ "title": "Blinds",
15
+ "description": "The names of the Blind Controller relays on your controllers.",
16
+ "items": {
17
+ "type": "string"
18
+ }
19
+ },
12
20
  "relays": {
13
21
  "type": "array",
14
- "title": "Relays",
15
- "description": "The names of the relays on your controllers that should be includes in HomeKit",
22
+ "title": "Switches",
23
+ "description": "The names of the relays on your controllers that should be represented as Switches.",
16
24
  "items": {
17
25
  "type": "string"
18
26
  }
@@ -57,7 +65,7 @@
57
65
  "type": "integer",
58
66
  "title": "CO2 Abnormal Level",
59
67
  "required": false,
60
- "default": 1000
68
+ "default": 2000
61
69
  },
62
70
  "debug": {
63
71
  "type": "boolean",
@@ -0,0 +1,56 @@
1
+ export class ZencontrolBlindPlatformAccessory {
2
+ constructor(platform, accessory) {
3
+ this.platform = platform;
4
+ this.accessory = accessory;
5
+ this.currentPosition = 0; /* 0 = open, 100 = closed */
6
+ this.accessory.getService(this.platform.Service.AccessoryInformation)
7
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'Zencontrol')
8
+ .setCharacteristic(this.platform.Characteristic.Model, accessory.context.model || 'Unknown')
9
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.context.serial || 'Unknown');
10
+ this.service = this.accessory.getService(this.platform.Service.WindowCovering) || this.accessory.addService(this.platform.Service.WindowCovering);
11
+ this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
12
+ // https://developers.homebridge.io/#/service/WindowCovering
13
+ this.service.getCharacteristic(this.platform.Characteristic.CurrentPosition)
14
+ .onGet(this.getCurrentPosition.bind(this));
15
+ this.service.getCharacteristic(this.platform.Characteristic.TargetPosition)
16
+ .onGet(this.getTargetPosition.bind(this))
17
+ .onSet(this.setTargetPosition.bind(this));
18
+ this.service.getCharacteristic(this.platform.Characteristic.PositionState)
19
+ .onGet(this.getPositionState.bind(this));
20
+ }
21
+ get displayName() {
22
+ return this.accessory.displayName;
23
+ }
24
+ async getCurrentPosition() {
25
+ return this.currentPosition;
26
+ }
27
+ async getTargetPosition() {
28
+ return this.targetPosition ?? 0;
29
+ }
30
+ async setTargetPosition(value) {
31
+ const targetPosition = value;
32
+ this.platform.log.debug(`Set blind ${this.accessory.displayName} (${this.accessory.context.address}) to ${targetPosition}`);
33
+ this.targetPosition = targetPosition;
34
+ try {
35
+ await this.platform.sendArcLevel(this.accessory.context.address, this.targetPosition ? 254 : 0, false);
36
+ }
37
+ catch (error) {
38
+ this.platform.log.warn(`Failed to update state for ${this.accessory.displayName}`, error);
39
+ }
40
+ }
41
+ async getPositionState() {
42
+ return this.platform.Characteristic.PositionState.STOPPED;
43
+ }
44
+ async receiveArcLevel(arcLevel) {
45
+ if (arcLevel === 255) {
46
+ /* A stop fade; ignore */
47
+ return;
48
+ }
49
+ const value = arcLevel > 0 ? 100 : 0;
50
+ if (value !== this.currentPosition) {
51
+ this.platform.log.debug(`Controller updated blind ${this.accessory.displayName} to ${value}`);
52
+ this.currentPosition = value;
53
+ this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, value);
54
+ }
55
+ }
56
+ }
package/dist/platform.js CHANGED
@@ -4,6 +4,7 @@ import { ZenController, ZenProtocol, ZenAddress, ZenAddressType, ZenControlGearT
4
4
  import { ZencontrolTemperaturePlatformAccessory } from './temperatureAccessory.js';
5
5
  import { ZencontrolHumidityPlatformAccessory } from './humidityAccessory.js';
6
6
  import { ZencontrolRelayPlatformAccessory } from './relayAccessory.js';
7
+ import { ZencontrolBlindPlatformAccessory } from './blindAccessory.js';
7
8
  import { ZencontrolLuxPlatformAccessory } from './luxAccessory.js';
8
9
  import { ZencontrolCO2PlatformAccessory } from './co2Accessory.js';
9
10
  /**
@@ -14,7 +15,6 @@ import { ZencontrolCO2PlatformAccessory } from './co2Accessory.js';
14
15
  export class ZencontrolTPIPlatform {
15
16
  constructor(log, config, api) {
16
17
  this.log = log;
17
- this.config = config;
18
18
  this.api = api;
19
19
  // this is used to track restored cached accessories
20
20
  this.accessories = new Map();
@@ -23,6 +23,7 @@ export class ZencontrolTPIPlatform {
23
23
  this.accessoryNeedsRegister = [];
24
24
  this.accessoryNeedsUpdate = [];
25
25
  this.lastSentDAPC = new Map();
26
+ this.config = config;
26
27
  this.Service = api.hap.Service;
27
28
  this.Characteristic = api.hap.Characteristic;
28
29
  const debug = !!config.debug;
@@ -124,15 +125,34 @@ export class ZencontrolTPIPlatform {
124
125
  if (!label) {
125
126
  return;
126
127
  }
127
- if ((this.config.relays ?? []).indexOf(label) === -1) {
128
+ if ((this.config.relays ?? []).indexOf(label) !== -1) {
129
+ const acc = this.addRelayAccessory({
130
+ address: addressToString(ecg),
131
+ label,
132
+ model: 'Relay',
133
+ serial: `${controller.id}.${ecg.ecg()}`,
134
+ });
135
+ const level = await this.zc.daliQueryLevel(ecg);
136
+ if (level !== null) {
137
+ acc.receiveArcLevel(level);
138
+ }
139
+ }
140
+ else if ((this.config.blinds ?? []).indexOf(label) !== -1) {
141
+ const acc = this.addBlindAccessory({
142
+ address: addressToString(ecg),
143
+ label,
144
+ model: 'Relay',
145
+ serial: `${controller.id}.${ecg.ecg()}`,
146
+ });
147
+ const level = await this.zc.daliQueryLevel(ecg);
148
+ if (level !== null) {
149
+ acc.receiveArcLevel(level);
150
+ }
151
+ }
152
+ else {
128
153
  this.log.debug(`Ignoring relay "${label}" as it is not listed in the config`);
129
154
  return;
130
155
  }
131
- const acc = this.addRelayAccessory({ address: addressToString(ecg), label, model: 'Relay', serial: `${controller.id}.${ecg.ecg()}` });
132
- const level = await this.zc.daliQueryLevel(ecg);
133
- if (level !== null) {
134
- acc.receiveArcLevel(level);
135
- }
136
156
  }
137
157
  }
138
158
  }));
@@ -275,6 +295,25 @@ export class ZencontrolTPIPlatform {
275
295
  this.discoveredCacheUUIDs.push(uuid);
276
296
  return acc;
277
297
  }
298
+ addBlindAccessory({ address, label, model, serial }) {
299
+ const uuid = this.api.hap.uuid.generate(`relay @ ${address}`);
300
+ const existingAccessory = this.accessories.get(uuid);
301
+ let acc;
302
+ if (existingAccessory) {
303
+ this.log.debug('Restoring existing blind accessory from cache:', existingAccessory.displayName);
304
+ this.updateAccessory(existingAccessory, { address, label, model, serial });
305
+ acc = new ZencontrolBlindPlatformAccessory(this, existingAccessory);
306
+ }
307
+ else {
308
+ this.log.info('Adding new blind accessory:', label);
309
+ const accessory = new this.api.platformAccessory(label, uuid);
310
+ this.setupAccessory(accessory, { address, label, model, serial });
311
+ acc = new ZencontrolBlindPlatformAccessory(this, accessory);
312
+ }
313
+ this.accessoriesByAddress.set(address, acc);
314
+ this.discoveredCacheUUIDs.push(uuid);
315
+ return acc;
316
+ }
278
317
  addTemperatureAccessory({ address, label, model, serial }) {
279
318
  const uuid = this.api.hap.uuid.generate(`temperature @ ${address}`);
280
319
  const existingAccessory = this.accessories.get(uuid);
@@ -403,7 +442,7 @@ export class ZencontrolTPIPlatform {
403
442
  this.zc.levelChangeCallback = (address, arcLevel) => {
404
443
  const accessoryId = addressToString(address);
405
444
  const acc = this.accessoriesByAddress.get(accessoryId);
406
- if (acc instanceof ZencontrolLightPlatformAccessory || acc instanceof ZencontrolRelayPlatformAccessory) {
445
+ if (acc instanceof ZencontrolLightPlatformAccessory || acc instanceof ZencontrolRelayPlatformAccessory || acc instanceof ZencontrolBlindPlatformAccessory) {
407
446
  acc.receiveArcLevel(arcLevel).catch((reason) => {
408
447
  this.log.warn(`Failed to update accessory "${acc.displayName}" brightness: ${reason}`);
409
448
  });
@@ -23,7 +23,7 @@ export class ZencontrolRelayPlatformAccessory {
23
23
  */
24
24
  async setOn(value) {
25
25
  const on = value;
26
- this.platform.log.debug(`Set ${this.accessory.displayName} (${this.accessory.context.address}) to ${on ? 'on' : 'off'}`);
26
+ this.platform.log.debug(`Set relay ${this.accessory.displayName} (${this.accessory.context.address}) to ${on ? 'on' : 'off'}`);
27
27
  this.requestOn = !!on;
28
28
  try {
29
29
  await this.platform.sendArcLevel(this.accessory.context.address, this.requestOn ? 254 : 0, false);
@@ -42,7 +42,7 @@ export class ZencontrolRelayPlatformAccessory {
42
42
  }
43
43
  const on = arcLevel > 0;
44
44
  if (on !== this.knownOn) {
45
- this.platform.log.debug(`Controller updated ${this.accessory.displayName} on/off to ${on ? 'on' : 'off'}`);
45
+ this.platform.log.debug(`Controller updated relay ${this.accessory.displayName} on/off to ${on ? 'on' : 'off'}`);
46
46
  this.knownOn = on;
47
47
  this.service.updateCharacteristic(this.platform.Characteristic.On, on);
48
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-zencontrol-tpi",
3
- "version": "1.1.0-next.2",
3
+ "version": "1.1.0-next.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "homebridge-lib": "^7.2.0",
37
- "zencontrol-tpi-node": "^1.0.0"
37
+ "zencontrol-tpi-node": "^1.1.0"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"