@switchbot/homebridge-switchbot 2.0.0-beta.9 → 2.0.0
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 +10 -1
- package/README.md +3 -2
- package/config.schema.json +91 -19
- package/dist/device/bot.d.ts +34 -28
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +657 -648
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +137 -0
- package/dist/device/ceilinglight.d.ts.map +1 -0
- package/dist/device/ceilinglight.js +1127 -0
- package/dist/device/ceilinglight.js.map +1 -0
- package/dist/device/colorbulb.d.ts +36 -14
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +472 -297
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +18 -8
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +306 -237
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +23 -16
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +566 -502
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +24 -18
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +453 -369
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +27 -8
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +305 -148
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +22 -16
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +367 -267
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +24 -12
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +381 -213
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +18 -8
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +279 -216
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +27 -17
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +295 -251
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +43 -19
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +506 -262
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +9 -12
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +278 -230
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -3
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +154 -104
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +11 -8
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +133 -86
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +10 -7
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +160 -109
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +11 -8
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +137 -103
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +11 -8
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +145 -98
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +12 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +143 -93
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +9 -10
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +132 -89
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -9
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +132 -89
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +13 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +524 -418
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +19 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/homebridge-ui/public/index.html +1 -0
- package/package.json +11 -9
- package/src/device/bot.ts +656 -659
- package/src/device/ceilinglight.ts +1208 -0
- package/src/device/colorbulb.ts +482 -334
- package/src/device/contact.ts +309 -241
- package/src/device/curtain.ts +571 -516
- package/src/device/humidifier.ts +456 -403
- package/src/device/lock.ts +314 -149
- package/src/device/meter.ts +378 -280
- package/src/device/meterplus.ts +391 -219
- package/src/device/motion.ts +285 -222
- package/src/device/plug.ts +299 -260
- package/src/device/striplight.ts +522 -289
- package/src/irdevice/airconditioner.ts +282 -241
- package/src/irdevice/airpurifier.ts +151 -103
- package/src/irdevice/camera.ts +131 -85
- package/src/irdevice/fan.ts +157 -106
- package/src/irdevice/light.ts +135 -103
- package/src/irdevice/other.ts +143 -97
- package/src/irdevice/tv.ts +142 -93
- package/src/irdevice/vacuumcleaner.ts +131 -89
- package/src/irdevice/waterheater.ts +130 -89
- package/src/platform.ts +522 -446
- package/src/settings.ts +20 -11
- package/.github/npm-version-script.js +0 -81
|
@@ -7,6 +7,7 @@ exports.StripLight = void 0;
|
|
|
7
7
|
const https_1 = __importDefault(require("https"));
|
|
8
8
|
const crypto_1 = __importDefault(require("crypto"));
|
|
9
9
|
const rxjs_1 = require("rxjs");
|
|
10
|
+
const super_stringify_1 = __importDefault(require("super-stringify"));
|
|
10
11
|
const operators_1 = require("rxjs/operators");
|
|
11
12
|
const settings_1 = require("../settings");
|
|
12
13
|
/**
|
|
@@ -19,25 +20,18 @@ class StripLight {
|
|
|
19
20
|
this.platform = platform;
|
|
20
21
|
this.accessory = accessory;
|
|
21
22
|
this.device = device;
|
|
23
|
+
// Connection
|
|
24
|
+
this.BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
|
|
25
|
+
this.OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
|
|
22
26
|
// default placeholders
|
|
23
27
|
this.logs(device);
|
|
24
28
|
this.scan(device);
|
|
25
29
|
this.refreshRate(device);
|
|
26
30
|
this.config(device);
|
|
27
|
-
|
|
28
|
-
this.On = false;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
this.On = this.accessory.context.On;
|
|
32
|
-
}
|
|
33
|
-
this.Hue = 0;
|
|
34
|
-
this.Brightness = 0;
|
|
35
|
-
this.Saturation = 0;
|
|
36
|
-
this.minKelvin = 2000;
|
|
37
|
-
this.maxKelvin = 9000;
|
|
31
|
+
this.context();
|
|
38
32
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
33
|
+
this.doStripLightUpdate = new rxjs_1.Subject();
|
|
34
|
+
this.stripLightUpdateInProgress = false;
|
|
41
35
|
// Retrieve initial values and updateHomekit
|
|
42
36
|
this.refreshStatus();
|
|
43
37
|
// set accessory information
|
|
@@ -52,7 +46,13 @@ class StripLight {
|
|
|
52
46
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
53
47
|
// you can create multiple services for each accessory
|
|
54
48
|
(this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
|
|
55
|
-
`${accessory.displayName}
|
|
49
|
+
`${accessory.displayName} ${device.deviceType}`;
|
|
50
|
+
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
51
|
+
this.accessory.removeService(this.lightBulbService);
|
|
52
|
+
this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
53
|
+
this.accessory.context.adaptiveLighting = false;
|
|
54
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
55
|
+
}
|
|
56
56
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
57
57
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
58
58
|
// accessory.getService('NAME') ?? accessory.addService(this.platform.Service.Outlet, 'NAME', 'USER_DEFINED_SUBTYPE');
|
|
@@ -74,6 +74,18 @@ class StripLight {
|
|
|
74
74
|
return this.Brightness;
|
|
75
75
|
})
|
|
76
76
|
.onSet(this.BrightnessSet.bind(this));
|
|
77
|
+
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
78
|
+
this.lightBulbService
|
|
79
|
+
.getCharacteristic(this.platform.Characteristic.ColorTemperature)
|
|
80
|
+
.setProps({
|
|
81
|
+
minValue: 140,
|
|
82
|
+
maxValue: 500,
|
|
83
|
+
validValueRanges: [140, 500],
|
|
84
|
+
})
|
|
85
|
+
.onGet(() => {
|
|
86
|
+
return this.ColorTemperature;
|
|
87
|
+
})
|
|
88
|
+
.onSet(this.ColorTemperatureSet.bind(this));
|
|
77
89
|
// handle Hue events using the Hue characteristic
|
|
78
90
|
this.lightBulbService
|
|
79
91
|
.getCharacteristic(this.platform.Characteristic.Hue)
|
|
@@ -98,44 +110,65 @@ class StripLight {
|
|
|
98
110
|
return this.Saturation;
|
|
99
111
|
})
|
|
100
112
|
.onSet(this.SaturationSet.bind(this));
|
|
113
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
114
|
+
if (this.adaptiveLightingShift !== -1) {
|
|
115
|
+
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.lightBulbService, {
|
|
116
|
+
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
117
|
+
});
|
|
118
|
+
this.accessory.configureController(this.AdaptiveLightingController);
|
|
119
|
+
this.accessory.context.adaptiveLighting = true;
|
|
120
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
121
|
+
` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
122
|
+
}
|
|
101
123
|
// Update Homekit
|
|
102
124
|
this.updateHomeKitCharacteristics();
|
|
103
125
|
// Start an update interval
|
|
104
126
|
(0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
|
|
105
|
-
.pipe((0, operators_1.skipWhile)(() => this.
|
|
127
|
+
.pipe((0, operators_1.skipWhile)(() => this.stripLightUpdateInProgress))
|
|
106
128
|
.subscribe(async () => {
|
|
107
129
|
await this.refreshStatus();
|
|
108
130
|
});
|
|
109
131
|
// Watch for Bulb change events
|
|
110
|
-
// We put in a debounce of
|
|
111
|
-
this.
|
|
132
|
+
// We put in a debounce of 1000ms so we don't make duplicate calls
|
|
133
|
+
this.doStripLightUpdate
|
|
112
134
|
.pipe((0, operators_1.tap)(() => {
|
|
113
|
-
this.
|
|
135
|
+
this.stripLightUpdateInProgress = true;
|
|
114
136
|
}), (0, operators_1.debounceTime)(this.platform.config.options.pushRate * 1000))
|
|
115
137
|
.subscribe(async () => {
|
|
116
138
|
try {
|
|
117
139
|
await this.pushChanges();
|
|
118
140
|
}
|
|
119
141
|
catch (e) {
|
|
120
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges`);
|
|
121
|
-
if (this.deviceLogging.includes('debug')) {
|
|
122
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
123
|
-
}
|
|
124
142
|
this.apiError(e);
|
|
143
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
144
|
+
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
125
145
|
}
|
|
126
|
-
this.
|
|
146
|
+
this.stripLightUpdateInProgress = false;
|
|
147
|
+
// Refresh the status from the API
|
|
148
|
+
(0, rxjs_1.interval)(15000)
|
|
149
|
+
.pipe((0, operators_1.skipWhile)(() => this.stripLightUpdateInProgress))
|
|
150
|
+
.pipe((0, operators_1.take)(1))
|
|
151
|
+
.subscribe(async () => {
|
|
152
|
+
await this.refreshStatus();
|
|
153
|
+
});
|
|
127
154
|
});
|
|
128
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Parse the device status from the SwitchBot api
|
|
158
|
+
*/
|
|
129
159
|
async parseStatus() {
|
|
130
|
-
if (this.
|
|
160
|
+
/*if (this.BLE) {
|
|
161
|
+
await this.BLEparseStatus();
|
|
162
|
+
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
131
163
|
await this.openAPIparseStatus();
|
|
132
164
|
}
|
|
133
165
|
else {
|
|
134
|
-
|
|
166
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
167
|
+
+ ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
135
168
|
}
|
|
136
169
|
}
|
|
137
170
|
async BLEparseStatus() {
|
|
138
|
-
this.debugLog(
|
|
171
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
139
172
|
// State
|
|
140
173
|
switch (this.state) {
|
|
141
174
|
case 'on':
|
|
@@ -144,9 +177,10 @@ class StripLight {
|
|
|
144
177
|
default:
|
|
145
178
|
this.On = false;
|
|
146
179
|
}
|
|
147
|
-
this.debugLog(
|
|
180
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
148
181
|
}
|
|
149
182
|
async openAPIparseStatus() {
|
|
183
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
150
184
|
switch (this.power) {
|
|
151
185
|
case 'on':
|
|
152
186
|
this.On = true;
|
|
@@ -154,44 +188,51 @@ class StripLight {
|
|
|
154
188
|
default:
|
|
155
189
|
this.On = false;
|
|
156
190
|
}
|
|
157
|
-
this.debugLog(
|
|
191
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
158
192
|
// Brightness
|
|
159
193
|
this.Brightness = Number(this.brightness);
|
|
160
|
-
this.debugLog(
|
|
194
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
161
195
|
// Color, Hue & Brightness
|
|
162
196
|
if (this.color) {
|
|
163
|
-
this.debugLog(
|
|
197
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${(0, super_stringify_1.default)(this.color)}`);
|
|
164
198
|
const [red, green, blue] = this.color.split(':');
|
|
165
|
-
this.debugLog(
|
|
166
|
-
this.debugLog(
|
|
167
|
-
this.debugLog(
|
|
199
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${(0, super_stringify_1.default)(red)}`);
|
|
200
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${(0, super_stringify_1.default)(green)}`);
|
|
201
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${(0, super_stringify_1.default)(blue)}`);
|
|
168
202
|
const [hue, saturation] = (0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue));
|
|
169
|
-
this.debugLog(
|
|
203
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
204
|
+
+ ` hs: ${(0, super_stringify_1.default)((0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue)))}`);
|
|
170
205
|
// Hue
|
|
171
206
|
this.Hue = hue;
|
|
172
|
-
this.debugLog(
|
|
207
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
173
208
|
// Saturation
|
|
174
209
|
this.Saturation = saturation;
|
|
175
|
-
this.debugLog(
|
|
210
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
176
211
|
}
|
|
177
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Asks the SwitchBot API for the latest device information
|
|
215
|
+
*/
|
|
178
216
|
async refreshStatus() {
|
|
179
|
-
if (this.
|
|
180
|
-
|
|
217
|
+
/*if (this.BLE) {
|
|
218
|
+
await this.BLERefreshStatus();
|
|
219
|
+
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
220
|
+
await this.openAPIRefreshStatus();
|
|
181
221
|
}
|
|
182
222
|
else {
|
|
183
|
-
|
|
223
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
224
|
+
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
184
225
|
}
|
|
185
226
|
}
|
|
186
227
|
async BLERefreshStatus() {
|
|
187
|
-
this.debugLog(
|
|
228
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
188
229
|
const switchbot = await this.platform.connectBLE();
|
|
189
230
|
// Convert to BLE Address
|
|
190
231
|
this.device.bleMac = this.device
|
|
191
232
|
.deviceId.match(/.{1,2}/g)
|
|
192
233
|
.join(':')
|
|
193
234
|
.toLowerCase();
|
|
194
|
-
this.debugLog(
|
|
235
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
195
236
|
this.getCustomBLEAddress(switchbot);
|
|
196
237
|
// Start to monitor advertisement packets
|
|
197
238
|
if (switchbot !== false) {
|
|
@@ -204,13 +245,9 @@ class StripLight {
|
|
|
204
245
|
// Set an event hander
|
|
205
246
|
switchbot.onadvertisement = (ad) => {
|
|
206
247
|
this.address = ad.address;
|
|
207
|
-
|
|
208
|
-
this.
|
|
209
|
-
|
|
210
|
-
this.infoLog(`Strip Light: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
211
|
-
this.infoLog(`Strip Light: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
212
|
-
}
|
|
213
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
248
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
249
|
+
+ ` BLE Address Found: ${this.address}`);
|
|
250
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
|
|
214
251
|
this.serviceData = ad.serviceData;
|
|
215
252
|
//this.state = ad.serviceData.state;
|
|
216
253
|
//this.delay = ad.serviceData.delay;
|
|
@@ -219,19 +256,19 @@ class StripLight {
|
|
|
219
256
|
//this.wifiRssi = ad.serviceData.wifiRssi;
|
|
220
257
|
//this.overload = ad.serviceData.overload;
|
|
221
258
|
//this.currentPower = ad.serviceData.currentPower;
|
|
222
|
-
this.debugLog(
|
|
259
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
|
|
223
260
|
/*this.debugLog(
|
|
224
|
-
|
|
261
|
+
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
225
262
|
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
226
263
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
227
264
|
);*/
|
|
228
265
|
if (this.serviceData) {
|
|
229
266
|
this.connected = true;
|
|
230
|
-
this.debugLog(
|
|
267
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
231
268
|
}
|
|
232
269
|
else {
|
|
233
270
|
this.connected = false;
|
|
234
|
-
this.debugLog(
|
|
271
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
235
272
|
}
|
|
236
273
|
};
|
|
237
274
|
// Wait 2 seconds
|
|
@@ -241,69 +278,33 @@ class StripLight {
|
|
|
241
278
|
// Stop to monitor
|
|
242
279
|
switchbot.stopScan();
|
|
243
280
|
if (this.connected) {
|
|
244
|
-
this.
|
|
281
|
+
this.BLEparseStatus();
|
|
245
282
|
this.updateHomeKitCharacteristics();
|
|
246
283
|
}
|
|
247
284
|
else {
|
|
248
|
-
this.
|
|
249
|
-
if (this.platform.config.credentials?.token) {
|
|
250
|
-
this.warnLog(`Strip Light: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
251
|
-
this.SwitchToOpenAPI = true;
|
|
252
|
-
await this.openAPIRefreshStatus();
|
|
253
|
-
}
|
|
285
|
+
await this.BLERefreshConnection(switchbot);
|
|
254
286
|
}
|
|
255
287
|
})
|
|
256
288
|
.catch(async (e) => {
|
|
257
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
258
|
-
if (this.deviceLogging.includes('debug')) {
|
|
259
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
260
|
-
}
|
|
261
|
-
if (this.platform.config.credentials?.token) {
|
|
262
|
-
this.warnLog(`Strip Light: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
263
|
-
this.SwitchToOpenAPI = true;
|
|
264
|
-
await this.openAPIRefreshStatus();
|
|
265
|
-
}
|
|
266
289
|
this.apiError(e);
|
|
290
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
291
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
292
|
+
await this.BLERefreshConnection(switchbot);
|
|
267
293
|
});
|
|
268
294
|
}
|
|
269
295
|
else {
|
|
270
|
-
await this.
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
async getCustomBLEAddress(switchbot) {
|
|
274
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
275
|
-
this.debugLog(`Strip Light: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
|
|
276
|
-
(async () => {
|
|
277
|
-
// Start to monitor advertisement packets
|
|
278
|
-
await switchbot.startScan({
|
|
279
|
-
model: 'r',
|
|
280
|
-
});
|
|
281
|
-
// Set an event handler
|
|
282
|
-
switchbot.onadvertisement = (ad) => {
|
|
283
|
-
this.warnLog(`Strip Light: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
284
|
-
};
|
|
285
|
-
await switchbot.wait(10000);
|
|
286
|
-
// Stop to monitor
|
|
287
|
-
switchbot.stopScan();
|
|
288
|
-
})();
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
async BLEconnection(switchbot) {
|
|
292
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
293
|
-
if (this.platform.config.credentials?.token) {
|
|
294
|
-
this.warnLog(`Strip Light: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
295
|
-
this.SwitchToOpenAPI = true;
|
|
296
|
-
await this.openAPIRefreshStatus();
|
|
296
|
+
await this.BLERefreshConnection(switchbot);
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
299
|
async openAPIRefreshStatus() {
|
|
300
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
300
301
|
try {
|
|
301
302
|
const t = Date.now();
|
|
302
303
|
const nonce = 'requestID';
|
|
303
304
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
304
305
|
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
305
306
|
const sign = signTerm.toString('base64');
|
|
306
|
-
this.debugLog(
|
|
307
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
307
308
|
const options = {
|
|
308
309
|
hostname: settings_1.HostDomain,
|
|
309
310
|
port: 443,
|
|
@@ -318,38 +319,37 @@ class StripLight {
|
|
|
318
319
|
},
|
|
319
320
|
};
|
|
320
321
|
const req = https_1.default.request(options, (res) => {
|
|
321
|
-
this.debugLog(
|
|
322
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
323
|
+
this.statusCode({ res });
|
|
322
324
|
let rawData = '';
|
|
323
325
|
res.on('data', (d) => {
|
|
324
326
|
rawData += d;
|
|
325
|
-
this.debugLog(
|
|
327
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
326
328
|
});
|
|
327
329
|
res.on('end', () => {
|
|
328
330
|
try {
|
|
329
331
|
this.deviceStatus = JSON.parse(rawData);
|
|
330
|
-
this.debugLog(
|
|
332
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
|
|
331
333
|
this.power = this.deviceStatus.body.power;
|
|
332
334
|
this.color = this.deviceStatus.body.color;
|
|
333
335
|
this.brightness = this.deviceStatus.body.brightness;
|
|
334
|
-
this.
|
|
336
|
+
this.openAPIparseStatus();
|
|
335
337
|
this.updateHomeKitCharacteristics();
|
|
336
338
|
}
|
|
337
339
|
catch (e) {
|
|
338
|
-
this.errorLog(
|
|
340
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
339
341
|
}
|
|
340
342
|
});
|
|
341
343
|
});
|
|
342
344
|
req.on('error', (e) => {
|
|
343
|
-
this.errorLog(
|
|
345
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
344
346
|
});
|
|
345
347
|
req.end();
|
|
346
348
|
}
|
|
347
349
|
catch (e) {
|
|
348
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
349
|
-
if (this.deviceLogging.includes('debug')) {
|
|
350
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
351
|
-
}
|
|
352
350
|
this.apiError(e);
|
|
351
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
352
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
355
|
/**
|
|
@@ -363,8 +363,61 @@ class StripLight {
|
|
|
363
363
|
*
|
|
364
364
|
*/
|
|
365
365
|
async pushChanges() {
|
|
366
|
+
/*if (this.BLE) {
|
|
367
|
+
await this.BLEpushChanges();
|
|
368
|
+
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
369
|
+
await this.openAPIpushChanges();
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
373
|
+
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
374
|
+
}
|
|
375
|
+
(0, rxjs_1.interval)(5000)
|
|
376
|
+
.pipe((0, operators_1.take)(1))
|
|
377
|
+
.subscribe(async () => {
|
|
378
|
+
await this.refreshStatus();
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
async BLEpushChanges() {
|
|
382
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
|
|
383
|
+
if (this.On !== this.accessory.context.On) {
|
|
384
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
385
|
+
const switchbot = await this.platform.connectBLE();
|
|
386
|
+
// Convert to BLE Address
|
|
387
|
+
this.device.bleMac = this.device
|
|
388
|
+
.deviceId.match(/.{1,2}/g)
|
|
389
|
+
.join(':')
|
|
390
|
+
.toLowerCase();
|
|
391
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
392
|
+
switchbot
|
|
393
|
+
.discover({
|
|
394
|
+
model: 'r',
|
|
395
|
+
id: this.device.bleMac,
|
|
396
|
+
})
|
|
397
|
+
.then((device_list) => {
|
|
398
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
399
|
+
return this.turnOnOff(device_list);
|
|
400
|
+
})
|
|
401
|
+
.then(() => {
|
|
402
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
403
|
+
this.On = false;
|
|
404
|
+
})
|
|
405
|
+
.catch(async (e) => {
|
|
406
|
+
this.apiError(e);
|
|
407
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
408
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
409
|
+
await this.BLEPushConnection();
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
|
|
414
|
+
+ `OnCached: ${this.accessory.context.On}`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
async openAPIpushChanges() {
|
|
366
418
|
try {
|
|
367
|
-
|
|
419
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
420
|
+
if (this.On !== this.accessory.context.On) {
|
|
368
421
|
// Make Push On request to the API
|
|
369
422
|
const t = Date.now();
|
|
370
423
|
const nonce = 'requestID';
|
|
@@ -373,7 +426,7 @@ class StripLight {
|
|
|
373
426
|
.update(Buffer.from(data, 'utf-8'))
|
|
374
427
|
.digest();
|
|
375
428
|
const sign = signTerm.toString('base64');
|
|
376
|
-
this.debugLog(
|
|
429
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
377
430
|
let command = '';
|
|
378
431
|
if (this.On) {
|
|
379
432
|
command = 'turnOn';
|
|
@@ -381,12 +434,12 @@ class StripLight {
|
|
|
381
434
|
else {
|
|
382
435
|
command = 'turnOff';
|
|
383
436
|
}
|
|
384
|
-
const body =
|
|
437
|
+
const body = (0, super_stringify_1.default)({
|
|
385
438
|
'command': `${command}`,
|
|
386
439
|
'parameter': 'default',
|
|
387
440
|
'commandType': 'command',
|
|
388
441
|
});
|
|
389
|
-
this.infoLog(
|
|
442
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
390
443
|
const options = {
|
|
391
444
|
hostname: settings_1.HostDomain,
|
|
392
445
|
port: 443,
|
|
@@ -402,20 +455,22 @@ class StripLight {
|
|
|
402
455
|
},
|
|
403
456
|
};
|
|
404
457
|
const req = https_1.default.request(options, res => {
|
|
405
|
-
this.debugLog(
|
|
458
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
|
|
406
459
|
this.statusCode({ res });
|
|
407
460
|
res.on('data', d => {
|
|
408
|
-
this.debugLog(
|
|
461
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
409
462
|
});
|
|
410
463
|
});
|
|
411
464
|
req.on('error', (e) => {
|
|
412
|
-
this.errorLog(
|
|
465
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
413
466
|
});
|
|
414
467
|
req.write(body);
|
|
415
468
|
req.end();
|
|
416
|
-
this.debugLog(
|
|
417
|
-
|
|
418
|
-
|
|
469
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges: ${(0, super_stringify_1.default)(req)}`);
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
|
|
473
|
+
+ `OnCached: ${this.accessory.context.On}`);
|
|
419
474
|
}
|
|
420
475
|
// Push Brightness Update
|
|
421
476
|
if (this.On) {
|
|
@@ -427,20 +482,19 @@ class StripLight {
|
|
|
427
482
|
}
|
|
428
483
|
}
|
|
429
484
|
catch (e) {
|
|
430
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
431
|
-
if (this.deviceLogging.includes('debug')) {
|
|
432
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
433
|
-
}
|
|
434
485
|
this.apiError(e);
|
|
486
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
487
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
435
488
|
}
|
|
436
489
|
}
|
|
437
490
|
async pushHueSaturationChanges() {
|
|
438
491
|
try {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
this.debugLog(
|
|
492
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges`);
|
|
493
|
+
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
494
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${(0, super_stringify_1.default)(this.Hue)}`);
|
|
495
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${(0, super_stringify_1.default)(this.Saturation)}`);
|
|
442
496
|
const [red, green, blue] = (0, settings_1.hs2rgb)(Number(this.Hue), Number(this.Saturation));
|
|
443
|
-
this.debugLog(
|
|
497
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${(0, super_stringify_1.default)([red, green, blue])}`);
|
|
444
498
|
// Make Push On request to the API
|
|
445
499
|
const t = Date.now();
|
|
446
500
|
const nonce = 'requestID';
|
|
@@ -449,13 +503,13 @@ class StripLight {
|
|
|
449
503
|
.update(Buffer.from(data, 'utf-8'))
|
|
450
504
|
.digest();
|
|
451
505
|
const sign = signTerm.toString('base64');
|
|
452
|
-
this.debugLog(
|
|
453
|
-
const body =
|
|
506
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
507
|
+
const body = (0, super_stringify_1.default)({
|
|
454
508
|
'command': 'setColor',
|
|
455
509
|
'parameter': `${red}:${green}:${blue}`,
|
|
456
510
|
'commandType': 'command',
|
|
457
511
|
});
|
|
458
|
-
this.infoLog(
|
|
512
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
459
513
|
const options = {
|
|
460
514
|
hostname: settings_1.HostDomain,
|
|
461
515
|
port: 443,
|
|
@@ -471,38 +525,34 @@ class StripLight {
|
|
|
471
525
|
},
|
|
472
526
|
};
|
|
473
527
|
const req = https_1.default.request(options, res => {
|
|
474
|
-
this.debugLog(
|
|
528
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges statusCode: ${res.statusCode}`);
|
|
475
529
|
this.statusCode({ res });
|
|
476
530
|
res.on('data', d => {
|
|
477
|
-
this.debugLog(
|
|
531
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
478
532
|
});
|
|
479
533
|
});
|
|
480
534
|
req.on('error', (e) => {
|
|
481
|
-
this.errorLog(
|
|
535
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
482
536
|
});
|
|
483
537
|
req.write(body);
|
|
484
538
|
req.end();
|
|
485
|
-
this.debugLog(
|
|
486
|
-
this.HueCached = this.Hue;
|
|
487
|
-
this.SaturationCached = this.Saturation;
|
|
539
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges: ${(0, super_stringify_1.default)(req)}`);
|
|
488
540
|
}
|
|
489
541
|
else {
|
|
490
|
-
this.debugLog(
|
|
491
|
-
`
|
|
542
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, `
|
|
543
|
+
+ `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
492
544
|
}
|
|
493
545
|
}
|
|
494
546
|
catch (e) {
|
|
495
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushHueSaturationChanges with OpenAPI Connection`);
|
|
496
|
-
if (this.deviceLogging.includes('debug')) {
|
|
497
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushHueSaturationChanges with OpenAPI Connection,`
|
|
498
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
499
|
-
}
|
|
500
547
|
this.apiError(e);
|
|
548
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}`
|
|
549
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
501
550
|
}
|
|
502
551
|
}
|
|
503
552
|
async pushBrightnessChanges() {
|
|
504
553
|
try {
|
|
505
|
-
|
|
554
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
|
|
555
|
+
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
506
556
|
// Make Push On request to the API
|
|
507
557
|
const t = Date.now();
|
|
508
558
|
const nonce = 'requestID';
|
|
@@ -511,13 +561,13 @@ class StripLight {
|
|
|
511
561
|
.update(Buffer.from(data, 'utf-8'))
|
|
512
562
|
.digest();
|
|
513
563
|
const sign = signTerm.toString('base64');
|
|
514
|
-
this.debugLog(
|
|
515
|
-
const body =
|
|
564
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
565
|
+
const body = (0, super_stringify_1.default)({
|
|
516
566
|
'command': 'setBrightness',
|
|
517
567
|
'parameter': `${this.Brightness}`,
|
|
518
568
|
'commandType': 'command',
|
|
519
569
|
});
|
|
520
|
-
this.infoLog(
|
|
570
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
521
571
|
const options = {
|
|
522
572
|
hostname: settings_1.HostDomain,
|
|
523
573
|
port: 443,
|
|
@@ -533,101 +583,291 @@ class StripLight {
|
|
|
533
583
|
},
|
|
534
584
|
};
|
|
535
585
|
const req = https_1.default.request(options, res => {
|
|
536
|
-
this.debugLog(
|
|
586
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges statusCode: ${res.statusCode}`);
|
|
537
587
|
this.statusCode({ res });
|
|
538
588
|
res.on('data', d => {
|
|
539
|
-
this.debugLog(
|
|
589
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
540
590
|
});
|
|
541
591
|
});
|
|
542
592
|
req.on('error', (e) => {
|
|
543
|
-
this.errorLog(
|
|
593
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
544
594
|
});
|
|
545
595
|
req.write(body);
|
|
546
596
|
req.end();
|
|
547
|
-
this.debugLog(
|
|
548
|
-
this.BrightnessCached = this.Brightness;
|
|
597
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges: ${(0, super_stringify_1.default)(req)}`);
|
|
549
598
|
}
|
|
550
599
|
else {
|
|
551
|
-
this.debugLog(
|
|
600
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
|
|
601
|
+
+ `BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
552
602
|
}
|
|
553
603
|
}
|
|
554
604
|
catch (e) {
|
|
555
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushBrightnessChanges with OpenAPI Connection`);
|
|
556
|
-
if (this.deviceLogging.includes('debug')) {
|
|
557
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushBrightnessChanges with OpenAPI Connection,`
|
|
558
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
559
|
-
}
|
|
560
605
|
this.apiError(e);
|
|
606
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}`
|
|
607
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
561
608
|
}
|
|
562
609
|
}
|
|
610
|
+
/**
|
|
611
|
+
* Handle requests to set the value of the "On" characteristic
|
|
612
|
+
*/
|
|
613
|
+
async OnSet(value) {
|
|
614
|
+
if (this.On === this.accessory.context.On) {
|
|
615
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set On: ${value}`);
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
|
|
619
|
+
}
|
|
620
|
+
this.On = value;
|
|
621
|
+
this.doStripLightUpdate.next();
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Handle requests to set the value of the "Brightness" characteristic
|
|
625
|
+
*/
|
|
626
|
+
async BrightnessSet(value) {
|
|
627
|
+
if (this.Brightness === this.accessory.context.Brightness) {
|
|
628
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Brightness: ${value}`);
|
|
629
|
+
}
|
|
630
|
+
else if (this.On) {
|
|
631
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
635
|
+
}
|
|
636
|
+
this.Brightness = value;
|
|
637
|
+
this.doStripLightUpdate.next();
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
641
|
+
*/
|
|
642
|
+
async ColorTemperatureSet(value) {
|
|
643
|
+
if (this.ColorTemperature === this.accessory.context.ColorTemperature) {
|
|
644
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set ColorTemperature: ${value}`);
|
|
645
|
+
}
|
|
646
|
+
else if (this.On) {
|
|
647
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
|
|
651
|
+
}
|
|
652
|
+
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
653
|
+
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
654
|
+
// Check and increase/decrease kelvin to range of device
|
|
655
|
+
const k = Math.min(Math.max(kelvin, this.minKelvin), this.maxKelvin);
|
|
656
|
+
if (!this.accessory.context.On || this.cacheKelvin === k) {
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
660
|
+
const hs = (0, settings_1.m2hs)(value);
|
|
661
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, hs[0]);
|
|
662
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
|
|
663
|
+
this.ColorTemperature = value;
|
|
664
|
+
this.doStripLightUpdate.next();
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Handle requests to set the value of the "Hue" characteristic
|
|
668
|
+
*/
|
|
669
|
+
async HueSet(value) {
|
|
670
|
+
if (this.Hue === this.accessory.context.Hue) {
|
|
671
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Hue: ${value}`);
|
|
672
|
+
}
|
|
673
|
+
else if (this.On) {
|
|
674
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
678
|
+
}
|
|
679
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
680
|
+
this.Hue = value;
|
|
681
|
+
this.doStripLightUpdate.next();
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Handle requests to set the value of the "Saturation" characteristic
|
|
685
|
+
*/
|
|
686
|
+
async SaturationSet(value) {
|
|
687
|
+
if (this.Saturation === this.accessory.context.Saturation) {
|
|
688
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Saturation: ${value}`);
|
|
689
|
+
}
|
|
690
|
+
else if (this.On) {
|
|
691
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
695
|
+
}
|
|
696
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
697
|
+
this.Saturation = value;
|
|
698
|
+
this.doStripLightUpdate.next();
|
|
699
|
+
}
|
|
563
700
|
async updateHomeKitCharacteristics() {
|
|
564
701
|
if (this.On === undefined) {
|
|
565
|
-
this.debugLog(
|
|
702
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
566
703
|
}
|
|
567
704
|
else {
|
|
705
|
+
this.accessory.context.On = this.On;
|
|
568
706
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
569
|
-
this.debugLog(
|
|
707
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
570
708
|
}
|
|
571
709
|
if (this.Brightness === undefined) {
|
|
572
|
-
this.debugLog(
|
|
710
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
573
711
|
}
|
|
574
712
|
else {
|
|
713
|
+
this.accessory.context.Brightness = this.Brightness;
|
|
575
714
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
|
|
576
|
-
this.debugLog(
|
|
715
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
716
|
+
}
|
|
717
|
+
if (this.ColorTemperature === undefined) {
|
|
718
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
this.accessory.context.ColorTemperature = this.ColorTemperature;
|
|
722
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
723
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
577
724
|
}
|
|
578
725
|
if (this.Hue === undefined) {
|
|
579
|
-
this.debugLog(
|
|
726
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
580
727
|
}
|
|
581
728
|
else {
|
|
729
|
+
this.accessory.context.Hue = this.Hue;
|
|
582
730
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
|
|
583
|
-
this.debugLog(
|
|
731
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
584
732
|
}
|
|
585
733
|
if (this.Saturation === undefined) {
|
|
586
|
-
this.debugLog(
|
|
734
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
587
735
|
}
|
|
588
736
|
else {
|
|
737
|
+
this.accessory.context.Saturation = this.Saturation;
|
|
589
738
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
590
|
-
this.debugLog(
|
|
739
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
591
740
|
}
|
|
592
741
|
}
|
|
593
|
-
|
|
594
|
-
this.
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
742
|
+
async getCustomBLEAddress(switchbot) {
|
|
743
|
+
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
744
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
|
|
745
|
+
(async () => {
|
|
746
|
+
// Start to monitor advertisement packets
|
|
747
|
+
await switchbot.startScan({
|
|
748
|
+
model: 'r',
|
|
749
|
+
});
|
|
750
|
+
// Set an event handler
|
|
751
|
+
switchbot.onadvertisement = (ad) => {
|
|
752
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${(0, super_stringify_1.default)(ad, null, ' ')}`);
|
|
753
|
+
};
|
|
754
|
+
await switchbot.wait(10000);
|
|
755
|
+
// Stop to monitor
|
|
756
|
+
switchbot.stopScan();
|
|
757
|
+
})();
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
async BLEPushConnection() {
|
|
761
|
+
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
762
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
|
763
|
+
await this.openAPIpushChanges();
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
async BLERefreshConnection(switchbot) {
|
|
767
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
768
|
+
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
769
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
|
|
770
|
+
await this.openAPIRefreshStatus();
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
async turnOnOff(device_list) {
|
|
774
|
+
return await this.retry({
|
|
775
|
+
max: await this.maxRetry(),
|
|
776
|
+
fn: () => {
|
|
777
|
+
if (this.On) {
|
|
778
|
+
return device_list[0].turnOn({ id: this.device.bleMac });
|
|
779
|
+
}
|
|
780
|
+
else {
|
|
781
|
+
return device_list[0].turnOff({ id: this.device.bleMac });
|
|
782
|
+
}
|
|
783
|
+
},
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
async retry({ max, fn }) {
|
|
787
|
+
return fn().catch(async (err) => {
|
|
788
|
+
if (max === 0) {
|
|
789
|
+
throw err;
|
|
790
|
+
}
|
|
791
|
+
this.infoLog(err);
|
|
792
|
+
this.infoLog('Retrying');
|
|
793
|
+
await this.switchbot.wait(1000);
|
|
794
|
+
return this.retry({ max: max - 1, fn });
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
async maxRetry() {
|
|
798
|
+
let maxRetry;
|
|
799
|
+
if (this.device.bot?.maxRetry) {
|
|
800
|
+
maxRetry = this.device.bot?.maxRetry;
|
|
801
|
+
}
|
|
802
|
+
else {
|
|
803
|
+
maxRetry = 5;
|
|
804
|
+
}
|
|
805
|
+
return maxRetry;
|
|
806
|
+
}
|
|
807
|
+
minStep(device) {
|
|
808
|
+
if (device.colorbulb?.set_minStep) {
|
|
809
|
+
this.set_minStep = device.colorbulb?.set_minStep;
|
|
810
|
+
}
|
|
811
|
+
else {
|
|
812
|
+
this.set_minStep = 1;
|
|
813
|
+
}
|
|
814
|
+
return this.set_minStep;
|
|
815
|
+
}
|
|
816
|
+
async adaptiveLighting(device) {
|
|
817
|
+
if (device.colorbulb?.adaptiveLightingShift) {
|
|
818
|
+
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
|
819
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
this.adaptiveLightingShift = 0;
|
|
823
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
async scan(device) {
|
|
827
|
+
if (device.scanDuration) {
|
|
828
|
+
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
829
|
+
if (this.BLE) {
|
|
830
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
else {
|
|
834
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
835
|
+
if (this.BLE) {
|
|
836
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
599
839
|
}
|
|
600
840
|
async statusCode({ res }) {
|
|
601
841
|
switch (res.statusCode) {
|
|
602
842
|
case 151:
|
|
603
|
-
this.errorLog(
|
|
843
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
604
844
|
break;
|
|
605
845
|
case 152:
|
|
606
|
-
this.errorLog(
|
|
846
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
607
847
|
break;
|
|
608
848
|
case 160:
|
|
609
|
-
this.errorLog(
|
|
849
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
610
850
|
break;
|
|
611
851
|
case 161:
|
|
612
|
-
this.errorLog(
|
|
852
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
613
853
|
this.offlineOff();
|
|
614
854
|
break;
|
|
615
855
|
case 171:
|
|
616
|
-
this.errorLog(
|
|
856
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
617
857
|
this.offlineOff();
|
|
618
858
|
break;
|
|
619
859
|
case 190:
|
|
620
|
-
this.errorLog(
|
|
621
|
-
` Or command: ${
|
|
860
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
861
|
+
` Or command: ${(0, super_stringify_1.default)(res)} format is invalid`);
|
|
622
862
|
break;
|
|
623
863
|
case 100:
|
|
624
864
|
if (this.platform.debugMode) {
|
|
625
|
-
this.debugLog(
|
|
865
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
626
866
|
}
|
|
627
867
|
break;
|
|
628
868
|
default:
|
|
629
869
|
if (this.platform.debugMode) {
|
|
630
|
-
this.debugLog(
|
|
870
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
631
871
|
}
|
|
632
872
|
}
|
|
633
873
|
}
|
|
@@ -635,47 +875,86 @@ class StripLight {
|
|
|
635
875
|
if (this.device.offline) {
|
|
636
876
|
this.On = false;
|
|
637
877
|
this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
878
|
+
await this.updateHomeKitCharacteristics();
|
|
638
879
|
}
|
|
639
880
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
this.
|
|
645
|
-
this.On = value;
|
|
646
|
-
this.doColorBulbUpdate.next();
|
|
881
|
+
apiError(e) {
|
|
882
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
883
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, e);
|
|
884
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, e);
|
|
885
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, e);
|
|
647
886
|
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
this.debugLog(
|
|
653
|
-
this.
|
|
654
|
-
|
|
887
|
+
FirmwareRevision(accessory, device) {
|
|
888
|
+
let FirmwareRevision;
|
|
889
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
890
|
+
+ `accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
891
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
892
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
893
|
+
if (accessory.context.FirmwareRevision) {
|
|
894
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
895
|
+
}
|
|
896
|
+
else if (device.firmware) {
|
|
897
|
+
FirmwareRevision = device.firmware;
|
|
898
|
+
}
|
|
899
|
+
else {
|
|
900
|
+
FirmwareRevision = this.platform.version;
|
|
901
|
+
}
|
|
902
|
+
return FirmwareRevision;
|
|
655
903
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
904
|
+
async context() {
|
|
905
|
+
if (this.On === undefined) {
|
|
906
|
+
this.On = false;
|
|
907
|
+
}
|
|
908
|
+
else {
|
|
909
|
+
this.On = this.accessory.context.On;
|
|
910
|
+
}
|
|
911
|
+
if (this.Hue === undefined) {
|
|
912
|
+
this.Hue = 0;
|
|
913
|
+
}
|
|
914
|
+
else {
|
|
915
|
+
this.Hue = this.accessory.context.Hue;
|
|
916
|
+
}
|
|
917
|
+
if (this.Brightness === undefined) {
|
|
918
|
+
this.Brightness = 0;
|
|
919
|
+
}
|
|
920
|
+
else {
|
|
921
|
+
this.Brightness = this.accessory.context.Brightness;
|
|
922
|
+
}
|
|
923
|
+
if (this.Brightness === undefined) {
|
|
924
|
+
this.Saturation = 0;
|
|
925
|
+
}
|
|
926
|
+
else {
|
|
927
|
+
this.Saturation = this.accessory.context.Saturation;
|
|
928
|
+
}
|
|
929
|
+
if (this.ColorTemperature === undefined) {
|
|
930
|
+
this.ColorTemperature = 140;
|
|
931
|
+
}
|
|
932
|
+
else {
|
|
933
|
+
this.ColorTemperature = this.accessory.context.ColorTemperature;
|
|
934
|
+
}
|
|
935
|
+
this.minKelvin = 2000;
|
|
936
|
+
this.maxKelvin = 9000;
|
|
663
937
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
this.
|
|
670
|
-
|
|
938
|
+
async refreshRate(device) {
|
|
939
|
+
if (device.refreshRate) {
|
|
940
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
941
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
942
|
+
}
|
|
943
|
+
else if (this.platform.config.options.refreshRate) {
|
|
944
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
945
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
946
|
+
}
|
|
671
947
|
}
|
|
672
948
|
async config(device) {
|
|
673
949
|
let config = {};
|
|
674
950
|
if (device.colorbulb) {
|
|
675
951
|
config = device.colorbulb;
|
|
676
952
|
}
|
|
677
|
-
if (device.
|
|
678
|
-
config['
|
|
953
|
+
if (device.connectionType !== undefined) {
|
|
954
|
+
config['connectionType'] = device.connectionType;
|
|
955
|
+
}
|
|
956
|
+
if (device.external !== undefined) {
|
|
957
|
+
config['external'] = device.external;
|
|
679
958
|
}
|
|
680
959
|
if (device.logging !== undefined) {
|
|
681
960
|
config['logging'] = device.logging;
|
|
@@ -690,76 +969,27 @@ class StripLight {
|
|
|
690
969
|
config['offline'] = device.offline;
|
|
691
970
|
}
|
|
692
971
|
if (Object.entries(config).length !== 0) {
|
|
693
|
-
this.infoLog(
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
async refreshRate(device) {
|
|
697
|
-
if (device.refreshRate) {
|
|
698
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
699
|
-
this.debugLog(`Strip Light: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
700
|
-
}
|
|
701
|
-
else if (this.platform.config.options.refreshRate) {
|
|
702
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
703
|
-
this.debugLog(`Strip Light: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
async scan(device) {
|
|
707
|
-
if (device.scanDuration) {
|
|
708
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
709
|
-
if (device.ble) {
|
|
710
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
else {
|
|
714
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
715
|
-
if (this.device.ble) {
|
|
716
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
717
|
-
}
|
|
972
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${(0, super_stringify_1.default)(config)}`);
|
|
718
973
|
}
|
|
719
974
|
}
|
|
720
975
|
async logs(device) {
|
|
721
976
|
if (this.platform.debugMode) {
|
|
722
977
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
723
|
-
this.debugLog(
|
|
978
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
724
979
|
}
|
|
725
980
|
else if (device.logging) {
|
|
726
981
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
727
|
-
this.debugLog(
|
|
982
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
728
983
|
}
|
|
729
984
|
else if (this.platform.config.options?.logging) {
|
|
730
985
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
731
|
-
this.debugLog(
|
|
986
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
732
987
|
}
|
|
733
988
|
else {
|
|
734
989
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
735
|
-
this.debugLog(
|
|
990
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
736
991
|
}
|
|
737
992
|
}
|
|
738
|
-
FirmwareRevision(accessory, device) {
|
|
739
|
-
let FirmwareRevision;
|
|
740
|
-
this.debugLog(`Strip Light: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
741
|
-
this.debugLog(`Strip Light: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
742
|
-
this.debugLog(`Strip Light: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
743
|
-
if (accessory.context.FirmwareRevision) {
|
|
744
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
745
|
-
}
|
|
746
|
-
else if (device.firmware) {
|
|
747
|
-
FirmwareRevision = device.firmware;
|
|
748
|
-
}
|
|
749
|
-
else {
|
|
750
|
-
FirmwareRevision = this.platform.version;
|
|
751
|
-
}
|
|
752
|
-
return FirmwareRevision;
|
|
753
|
-
}
|
|
754
|
-
minStep(device) {
|
|
755
|
-
if (device.colorbulb?.set_minStep) {
|
|
756
|
-
this.set_minStep = device.colorbulb?.set_minStep;
|
|
757
|
-
}
|
|
758
|
-
else {
|
|
759
|
-
this.set_minStep = 1;
|
|
760
|
-
}
|
|
761
|
-
return this.set_minStep;
|
|
762
|
-
}
|
|
763
993
|
/**
|
|
764
994
|
* Logging for Device
|
|
765
995
|
*/
|
|
@@ -773,11 +1003,25 @@ class StripLight {
|
|
|
773
1003
|
this.platform.log.warn(String(...log));
|
|
774
1004
|
}
|
|
775
1005
|
}
|
|
1006
|
+
debugWarnLog(...log) {
|
|
1007
|
+
if (this.enablingDeviceLogging()) {
|
|
1008
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
1009
|
+
this.platform.log.warn('[DEBUG]', String(...log));
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
776
1013
|
errorLog(...log) {
|
|
777
1014
|
if (this.enablingDeviceLogging()) {
|
|
778
1015
|
this.platform.log.error(String(...log));
|
|
779
1016
|
}
|
|
780
1017
|
}
|
|
1018
|
+
debugErrorLog(...log) {
|
|
1019
|
+
if (this.enablingDeviceLogging()) {
|
|
1020
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
1021
|
+
this.platform.log.error('[DEBUG]', String(...log));
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
781
1025
|
debugLog(...log) {
|
|
782
1026
|
if (this.enablingDeviceLogging()) {
|
|
783
1027
|
if (this.deviceLogging === 'debug') {
|