homebridge-zencontrol-tpi 1.0.0 → 1.0.2

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.
@@ -224,12 +224,12 @@ export class ZencontrolLightPlatformAccessory {
224
224
  const brightness = arcLevel > 0 ? Math.max(1, Math.round(arcLevelToPercentage(arcLevel))) : 0;
225
225
  const on = arcLevel > 0;
226
226
  if (brightness !== this.knownBrightness) {
227
- this.platform.log.debug(`Received from controller: ${this.accessory.displayName} brightness to ${brightness}`);
227
+ this.platform.log.info(`Received from controller: ${this.accessory.displayName} brightness to ${brightness}`);
228
228
  this.knownBrightness = brightness;
229
229
  this.service.updateCharacteristic(this.platform.Characteristic.Brightness, brightness);
230
230
  }
231
231
  if (on !== this.knownOn) {
232
- this.platform.log.debug(`Received from controller: ${this.accessory.displayName} on/off to ${on ? 'on' : 'off'}`);
232
+ this.platform.log.info(`Received from controller: ${this.accessory.displayName} on/off to ${on ? 'on' : 'off'}`);
233
233
  this.knownOn = on;
234
234
  this.service.updateCharacteristic(this.platform.Characteristic.On, on);
235
235
  }
package/dist/platform.js CHANGED
@@ -205,7 +205,7 @@ export class ZencontrolTPIPlatform {
205
205
  let acc;
206
206
  if (existingAccessory) {
207
207
  // the accessory already exists
208
- this.log.info('Restoring existing light accessory from cache:', existingAccessory.displayName);
208
+ this.log.debug('Restoring existing light accessory from cache:', existingAccessory.displayName);
209
209
  this.updateAccessory(existingAccessory, { address, label, model, serial });
210
210
  // create the accessory handler for the restored accessory
211
211
  // this is imported from `platformAccessory.ts`
@@ -235,7 +235,7 @@ export class ZencontrolTPIPlatform {
235
235
  const existingAccessory = this.accessories.get(uuid);
236
236
  let acc;
237
237
  if (existingAccessory) {
238
- this.log.info('Restoring existing relay accessory from cache:', existingAccessory.displayName);
238
+ this.log.debug('Restoring existing relay accessory from cache:', existingAccessory.displayName);
239
239
  this.updateAccessory(existingAccessory, { address, label, model, serial });
240
240
  acc = new ZencontrolRelayPlatformAccessory(this, existingAccessory);
241
241
  }
@@ -254,7 +254,7 @@ export class ZencontrolTPIPlatform {
254
254
  const existingAccessory = this.accessories.get(uuid);
255
255
  let acc;
256
256
  if (existingAccessory) {
257
- this.log.info('Restoring existing temperature accessory from cache:', existingAccessory.displayName);
257
+ this.log.debug('Restoring existing temperature accessory from cache:', existingAccessory.displayName);
258
258
  this.updateAccessory(existingAccessory, { address, label, model, serial });
259
259
  acc = new ZencontrolTemperaturePlatformAccessory(this, existingAccessory);
260
260
  }
@@ -273,7 +273,7 @@ export class ZencontrolTPIPlatform {
273
273
  const existingAccessory = this.accessories.get(uuid);
274
274
  let acc;
275
275
  if (existingAccessory) {
276
- this.log.info('Restoring existing humidity accessory from cache:', existingAccessory.displayName);
276
+ this.log.debug('Restoring existing humidity accessory from cache:', existingAccessory.displayName);
277
277
  this.updateAccessory(existingAccessory, { address, label, model, serial });
278
278
  acc = new ZencontrolHumidityPlatformAccessory(this, existingAccessory);
279
279
  }
@@ -292,7 +292,7 @@ export class ZencontrolTPIPlatform {
292
292
  const existingAccessory = this.accessories.get(uuid);
293
293
  let acc;
294
294
  if (existingAccessory) {
295
- this.log.info('Restoring existing lux accessory from cache:', existingAccessory.displayName);
295
+ this.log.debug('Restoring existing lux accessory from cache:', existingAccessory.displayName);
296
296
  this.updateAccessory(existingAccessory, { address, label, model, serial });
297
297
  acc = new ZencontrolLuxPlatformAccessory(this, existingAccessory);
298
298
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-zencontrol-tpi",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -11,6 +11,8 @@
11
11
  "scripts": {
12
12
  "build": "tsc",
13
13
  "clean": "rm -rf dist",
14
+ "release": "$npm_execpath run clean && $npm_execpath run build && $npm_execpath publish && $npm_execpath exec changeset tag && $npm_execpath install",
15
+ "release:version": "$npm_execpath exec changeset version && $npm_execpath install",
14
16
  "test": "echo \"Error: no test specified\" && exit 1",
15
17
  "watch": "tsc --watch"
16
18
  },
@@ -32,7 +34,7 @@
32
34
  },
33
35
  "dependencies": {
34
36
  "homebridge-lib": "^7.1.8",
35
- "zencontrol-tpi-node": "file:../zencontrol-tpi-node"
37
+ "zencontrol-tpi-node": "^1.0.0"
36
38
  },
37
39
  "publishConfig": {
38
40
  "access": "public"
@@ -1,224 +0,0 @@
1
- import { arcLevelToPercentage, percentageToArcLevel, ZenColour } from 'zencontrol-tpi-node';
2
- /**
3
- * Platform Accessory
4
- * An instance of this class is created for each accessory your platform registers
5
- * Each accessory may expose multiple services of different service types.
6
- */
7
- export class ZencontrolTPIPlatformAccessory {
8
- constructor(platform, accessory, options = {}) {
9
- this.platform = platform;
10
- this.accessory = accessory;
11
- this.options = options;
12
- /**
13
- * Whether the light is on/off. Only updated by notification from the controller.
14
- */
15
- this.knownOn = false;
16
- /**
17
- * The brightness of the light in range 0-100. Only updated by notification from the controller.
18
- */
19
- this.knownBrightness = 0;
20
- this.requestBrightnessInstant = true;
21
- /**
22
- * The hue of the light in range 0-359.
23
- */
24
- this.knownHue = 0;
25
- /**
26
- * The saturation of the light in range 0-100
27
- */
28
- this.knownSaturation = 0;
29
- // set accessory information
30
- this.accessory.getService(this.platform.Service.AccessoryInformation)
31
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'Zencontrol')
32
- .setCharacteristic(this.platform.Characteristic.Model, accessory.context.model || 'Unknown')
33
- .setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.context.serial || 'Unknown');
34
- // get the LightBulb service if it exists, otherwise create a new LightBulb service
35
- // you can create multiple services for each accessory
36
- this.service = this.accessory.getService(this.platform.Service.Lightbulb) || this.accessory.addService(this.platform.Service.Lightbulb);
37
- // set the service name, this is what is displayed as the default name on the Home app
38
- // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
39
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
40
- // each service must implement at-minimum the "required characteristics" for the given service type
41
- // see https://developers.homebridge.io/#/service/Lightbulb
42
- // register handlers for the On/Off Characteristic
43
- this.service.getCharacteristic(this.platform.Characteristic.On)
44
- .onSet(this.setOn.bind(this)) // SET - bind to the `setOn` method below
45
- .onGet(this.getOn.bind(this)); // GET - bind to the `getOn` method below
46
- // register handlers for the Brightness Characteristic
47
- this.service.getCharacteristic(this.platform.Characteristic.Brightness)
48
- .onSet(this.setBrightness.bind(this)) // SET - bind to the `setBrightness` method below
49
- .onGet(this.getBrightness.bind(this));
50
- if (options.color) {
51
- this.service.getCharacteristic(this.platform.Characteristic.Hue)
52
- .onSet(this.setHue.bind(this))
53
- .onGet(this.getHue.bind(this));
54
- this.service.getCharacteristic(this.platform.Characteristic.Saturation)
55
- .onSet(this.setSaturation.bind(this))
56
- .onGet(this.getSaturation.bind(this));
57
- }
58
- /**
59
- * Creating multiple services of the same type.
60
- *
61
- * To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
62
- * when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
63
- * this.accessory.getService('NAME') || this.accessory.addService(this.platform.Service.Lightbulb, 'NAME', 'USER_DEFINED_SUBTYPE_ID');
64
- *
65
- * The USER_DEFINED_SUBTYPE must be unique to the platform accessory (if you platform exposes multiple accessories, each accessory
66
- * can use the same subtype id.)
67
- */
68
- // Example: add two "motion sensor" services to the accessory
69
- // const motionSensorOneService = this.accessory.getService('Motion Sensor One Name')
70
- // || this.accessory.addService(this.platform.Service.MotionSensor, 'Motion Sensor One Name', 'YourUniqueIdentifier-1')
71
- // const motionSensorTwoService = this.accessory.getService('Motion Sensor Two Name')
72
- // || this.accessory.addService(this.platform.Service.MotionSensor, 'Motion Sensor Two Name', 'YourUniqueIdentifier-2')
73
- /**
74
- * Updating characteristics values asynchronously.
75
- *
76
- * Example showing how to update the state of a Characteristic asynchronously instead
77
- * of using the `on('get')` handlers.
78
- * Here we change update the motion sensor trigger states on and off every 10 seconds
79
- * the `updateCharacteristic` method.
80
- *
81
- */
82
- // let motionDetected = false
83
- // setInterval(() => {
84
- // // EXAMPLE - inverse the trigger
85
- // motionDetected = !motionDetected
86
- // // push the new value to HomeKit
87
- // motionSensorOneService.updateCharacteristic(this.platform.Characteristic.MotionDetected, motionDetected)
88
- // motionSensorTwoService.updateCharacteristic(this.platform.Characteristic.MotionDetected, !motionDetected)
89
- // this.platform.log.debug('Triggering motionSensorOneService:', motionDetected)
90
- // this.platform.log.debug('Triggering motionSensorTwoService:', !motionDetected)
91
- // }, 10000)
92
- }
93
- get displayName() {
94
- return this.accessory.displayName;
95
- }
96
- /**
97
- * Handle "SET" requests from HomeKit
98
- * These are sent when the user changes the state of an accessory, for example, turning on a Light bulb.
99
- */
100
- async setOn(value) {
101
- const on = value;
102
- this.platform.log.debug(`Set ${this.accessory.displayName} to ${on ? 'on' : 'off'}`);
103
- if (on) {
104
- /* Brightness is always set at the same time, so we don't need to do anything for "on" requests */
105
- return;
106
- }
107
- else {
108
- this.requestBrightness = 0;
109
- }
110
- this.requestBrightnessInstant = false;
111
- this.updateState();
112
- }
113
- /**
114
- * Handle the "GET" requests from HomeKit
115
- * These are sent when HomeKit wants to know the current state of the accessory, for example, checking if a Light bulb is on.
116
- *
117
- * GET requests should return as fast as possible. A long delay here will result in
118
- * HomeKit being unresponsive and a bad user experience in general.
119
- *
120
- * If your device takes time to respond you should update the status of your device
121
- * asynchronously instead using the `updateCharacteristic` method instead.
122
- * In this case, you may decide not to implement `onGet` handlers, which may speed up
123
- * the responsiveness of your device in the Home app.
124
-
125
- * @example
126
- * this.service.updateCharacteristic(this.platform.Characteristic.On, true)
127
- */
128
- async getOn() {
129
- // this.platform.log.debug(`Get on/off of ${this.accessory.displayName}: ${this.on}`)
130
- return this.knownOn;
131
- }
132
- /**
133
- * Handle "SET" requests from HomeKit
134
- * These are sent when the user changes the state of an accessory, for example, changing the Brightness
135
- */
136
- async setBrightness(value) {
137
- const brightness = value;
138
- this.platform.log.debug(`Set ${this.accessory.displayName} brightness to ${brightness}`);
139
- this.requestBrightness = brightness;
140
- /* If the light was already on, then use instant fading - otherwise if we're turning it on or off use the default fade time */
141
- this.requestBrightnessInstant = brightness > 0 && (this.requestBrightness ?? this.knownBrightness) > 0;
142
- this.updateState();
143
- }
144
- async getBrightness() {
145
- return this.knownBrightness;
146
- }
147
- async setHue(value) {
148
- const hue = value;
149
- this.requestHue = hue;
150
- this.updateState();
151
- }
152
- async getHue() {
153
- return this.knownHue;
154
- }
155
- async setSaturation(value) {
156
- const saturation = value;
157
- this.requestSaturation = saturation;
158
- this.updateState();
159
- }
160
- updateState() {
161
- clearTimeout(this.updateDebounceTimeout);
162
- if (!this.options.color) {
163
- this.updateDebounceTimeout = setTimeout(this.updateBrightness.bind(this), 200);
164
- }
165
- else {
166
- this.updateDebounceTimeout = setTimeout(this.updateColor.bind(this), 200);
167
- }
168
- }
169
- async updateBrightness() {
170
- this.platform.log.info(`Updating ${this.displayName} brightness to ${this.requestBrightness}`);
171
- try {
172
- await this.platform.sendArcLevel(this.accessory.context.id, percentageToArcLevel(this.requestBrightness), this.requestBrightnessInstant);
173
- }
174
- catch (error) {
175
- this.platform.log.warn(`Failed to update brightness for ${this.accessory.displayName}`, error);
176
- }
177
- }
178
- async updateColor() {
179
- const brightness = this.requestBrightness ?? this.knownBrightness;
180
- const color = this.daliColor();
181
- this.platform.log.info(`Updating ${this.displayName} color to ${this.requestHue ?? this.knownHue}°, ${this.requestSaturation ?? this.knownSaturation}%, ${brightness}%`);
182
- try {
183
- await this.platform.sendColor(this.accessory.context.id, color, percentageToArcLevel(brightness), this.requestBrightnessInstant);
184
- }
185
- catch (error) {
186
- this.platform.log.warn(`Failed to update color for ${this.accessory.displayName}`, error);
187
- }
188
- }
189
- async getSaturation() {
190
- return this.knownSaturation;
191
- }
192
- daliColor() {
193
- /* Convert HSV to RGBWAF */
194
- const h = this.requestHue ?? this.knownHue;
195
- const s = (this.requestSaturation ?? this.knownSaturation) / 100;
196
- const v = 1; /* We control the brightness separately, so don't include it in the colour conversion */
197
- return ZenColour.fromHsv(h, s, v);
198
- }
199
- async receiveDaliBrightness(daliArcLevel) {
200
- if (daliArcLevel === 255) {
201
- /* A stop fade; ignore */
202
- return;
203
- }
204
- const brightness = Math.round(arcLevelToPercentage(daliArcLevel));
205
- const on = daliArcLevel > 0;
206
- if (brightness !== this.knownBrightness) {
207
- this.platform.log.debug(`Controller updated ${this.accessory.displayName} brightness to ${brightness}`);
208
- this.knownBrightness = brightness;
209
- this.service.updateCharacteristic(this.platform.Characteristic.Brightness, brightness);
210
- }
211
- if (on !== this.knownOn) {
212
- this.platform.log.debug(`Controller updated ${this.accessory.displayName} on/off to ${on ? 'on' : 'off'}`);
213
- this.knownOn = on;
214
- this.service.updateCharacteristic(this.platform.Characteristic.On, on);
215
- }
216
- }
217
- async receiveDaliColor(color) {
218
- const { h, s } = color.toHsv();
219
- this.knownHue = h;
220
- this.knownSaturation = Math.round(s * 100);
221
- this.service.updateCharacteristic(this.platform.Characteristic.Hue, h);
222
- this.service.updateCharacteristic(this.platform.Characteristic.Saturation, s);
223
- }
224
- }