@switchbot/homebridge-switchbot 3.5.0-beta.3 → 3.5.0-beta.30
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 +4 -1
- package/config.schema.json +147 -9
- package/dist/device/blindtilt.d.ts +21 -94
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +347 -756
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -71
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +582 -759
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -67
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +209 -587
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -74
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +250 -632
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -65
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +204 -531
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -86
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +335 -786
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +59 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +646 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +51 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +499 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +15 -59
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +242 -596
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -65
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +207 -571
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +174 -584
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -68
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +252 -568
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -62
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +210 -542
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -63
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +170 -577
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -64
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +159 -577
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +136 -518
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +82 -452
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -62
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +140 -451
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -70
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +121 -664
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -48
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +309 -419
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +7 -38
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +72 -304
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +6 -35
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +34 -278
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +6 -39
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +67 -311
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +40 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +509 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +6 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -272
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -47
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +352 -546
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -39
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -321
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -35
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -284
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -35
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +42 -287
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +237 -94
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +40 -10
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +0 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +638 -1
- package/dist/utils.js.map +1 -1
- package/package.json +16 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +373 -782
- package/src/device/bot.ts +616 -844
- package/src/device/ceilinglight.ts +222 -607
- package/src/device/colorbulb.ts +264 -656
- package/src/device/contact.ts +229 -553
- package/src/device/curtain.ts +355 -810
- package/src/device/device.ts +673 -0
- package/src/device/fan.ts +548 -0
- package/src/device/hub.ts +268 -623
- package/src/device/humidifier.ts +237 -618
- package/src/device/iosensor.ts +200 -610
- package/src/device/lightstrip.ts +273 -596
- package/src/device/lock.ts +247 -582
- package/src/device/meter.ts +196 -601
- package/src/device/meterplus.ts +184 -602
- package/src/device/motion.ts +156 -541
- package/src/device/plug.ts +92 -480
- package/src/device/robotvacuumcleaner.ts +161 -477
- package/src/device/waterdetector.ts +139 -689
- package/src/index.ts +1 -1
- package/src/irdevice/airconditioner.ts +330 -446
- package/src/irdevice/airpurifier.ts +89 -321
- package/src/irdevice/camera.ts +42 -293
- package/src/irdevice/fan.ts +78 -327
- package/src/irdevice/irdevice.ts +526 -0
- package/src/irdevice/light.ts +32 -287
- package/src/irdevice/other.ts +396 -615
- package/src/irdevice/tv.ts +100 -339
- package/src/irdevice/vacuumcleaner.ts +49 -305
- package/src/irdevice/waterheater.ts +50 -310
- package/src/platform.ts +247 -102
- package/src/settings.ts +56 -565
- package/src/utils.ts +642 -1
|
@@ -1,107 +1,58 @@
|
|
|
1
1
|
import { request } from 'undici';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { interval, skipWhile, Subject } from 'rxjs';
|
|
3
|
+
import { deviceBase } from './device.js';
|
|
4
|
+
import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
|
|
5
|
+
import { debounceTime, take, tap } from 'rxjs/operators';
|
|
6
|
+
import { Devices } from '../settings.js';
|
|
6
7
|
/**
|
|
7
8
|
* Platform Accessory
|
|
8
9
|
* An instance of this class is created for each accessory your platform registers
|
|
9
10
|
* Each accessory may expose multiple services of different service types.
|
|
10
11
|
*/
|
|
11
|
-
export class StripLight {
|
|
12
|
+
export class StripLight extends deviceBase {
|
|
12
13
|
platform;
|
|
13
|
-
accessory;
|
|
14
|
-
device;
|
|
15
|
-
api;
|
|
16
|
-
log;
|
|
17
|
-
config;
|
|
18
|
-
hap;
|
|
19
14
|
// Services
|
|
20
|
-
|
|
21
|
-
// Characteristic Values
|
|
22
|
-
On;
|
|
23
|
-
Hue;
|
|
24
|
-
Saturation;
|
|
25
|
-
Brightness;
|
|
26
|
-
FirmwareRevision;
|
|
27
|
-
ColorTemperature;
|
|
28
|
-
// OpenAPI Status
|
|
29
|
-
OpenAPI_On;
|
|
30
|
-
OpenAPI_RGB;
|
|
31
|
-
OpenAPI_Brightness;
|
|
32
|
-
OpenAPI_FirmwareRevision;
|
|
33
|
-
// BLE Status
|
|
34
|
-
BLE_On;
|
|
35
|
-
BLE_Brightness;
|
|
36
|
-
// BLE Others
|
|
37
|
-
BLE_IsConnected;
|
|
38
|
-
// Config
|
|
39
|
-
set_minStep;
|
|
40
|
-
scanDuration;
|
|
41
|
-
deviceLogging;
|
|
42
|
-
deviceRefreshRate;
|
|
43
|
-
adaptiveLightingShift;
|
|
15
|
+
LightBulb;
|
|
44
16
|
// Adaptive Lighting
|
|
45
17
|
AdaptiveLightingController;
|
|
46
|
-
|
|
47
|
-
maxKelvin;
|
|
48
|
-
// Others
|
|
49
|
-
cacheKelvin;
|
|
50
|
-
change;
|
|
18
|
+
adaptiveLightingShift;
|
|
51
19
|
// Updates
|
|
52
20
|
stripLightUpdateInProgress;
|
|
53
21
|
doStripLightUpdate;
|
|
54
|
-
// Connection
|
|
55
|
-
OpenAPI;
|
|
56
|
-
BLE;
|
|
57
22
|
constructor(platform, accessory, device) {
|
|
23
|
+
super(platform, accessory, device);
|
|
58
24
|
this.platform = platform;
|
|
59
|
-
this.
|
|
60
|
-
this.device = device;
|
|
61
|
-
this.api = this.platform.api;
|
|
62
|
-
this.log = this.platform.log;
|
|
63
|
-
this.config = this.platform.config;
|
|
64
|
-
this.hap = this.api.hap;
|
|
65
|
-
// Connection
|
|
66
|
-
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
67
|
-
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
68
|
-
// default placeholders
|
|
69
|
-
this.deviceLogs(device);
|
|
70
|
-
this.scan(device);
|
|
71
|
-
this.refreshRate(device);
|
|
72
|
-
this.deviceContext();
|
|
73
|
-
this.deviceConfig(device);
|
|
25
|
+
this.adaptiveLighting(device);
|
|
74
26
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
75
27
|
this.doStripLightUpdate = new Subject();
|
|
76
28
|
this.stripLightUpdateInProgress = false;
|
|
29
|
+
// Initialize the LightBulb property
|
|
30
|
+
this.LightBulb = {
|
|
31
|
+
Service: accessory.getService(this.hap.Service.Lightbulb),
|
|
32
|
+
On: accessory.context.On || false,
|
|
33
|
+
Hue: accessory.context.Hue || 0,
|
|
34
|
+
Saturation: accessory.context.Saturation || 0,
|
|
35
|
+
Brightness: accessory.context.Brightness || 0,
|
|
36
|
+
ColorTemperature: accessory.context.ColorTemperature || 140,
|
|
37
|
+
};
|
|
77
38
|
// Retrieve initial values and updateHomekit
|
|
78
39
|
this.refreshStatus();
|
|
79
|
-
// set accessory information
|
|
80
|
-
accessory
|
|
81
|
-
.getService(this.hap.Service.AccessoryInformation)
|
|
82
|
-
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
83
|
-
.setCharacteristic(this.hap.Characteristic.Model, 'W1701100')
|
|
84
|
-
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
85
|
-
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
86
40
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
87
41
|
// you can create multiple services for each accessory
|
|
88
|
-
const
|
|
89
|
-
(this.
|
|
90
|
-
|| accessory.addService(this.hap.Service.Lightbulb)),
|
|
42
|
+
const LightBulbService = `${accessory.displayName} ${device.deviceType}`;
|
|
43
|
+
(this.LightBulb.Service = accessory.getService(this.hap.Service.Lightbulb)
|
|
44
|
+
|| accessory.addService(this.hap.Service.Lightbulb)), LightBulbService;
|
|
91
45
|
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
92
|
-
this.accessory.removeService(this.
|
|
93
|
-
this.
|
|
46
|
+
this.accessory.removeService(this.LightBulb.Service);
|
|
47
|
+
this.LightBulb.Service = this.accessory.addService(this.hap.Service.Lightbulb);
|
|
94
48
|
this.accessory.context.adaptiveLighting = false;
|
|
95
49
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
96
50
|
}
|
|
97
|
-
this.
|
|
98
|
-
if (!this.lightBulbService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
99
|
-
this.lightBulbService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
100
|
-
}
|
|
51
|
+
this.LightBulb.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
101
52
|
// handle on / off events using the On characteristic
|
|
102
|
-
this.
|
|
53
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
103
54
|
// handle Brightness events using the Brightness characteristic
|
|
104
|
-
this.
|
|
55
|
+
this.LightBulb.Service
|
|
105
56
|
.getCharacteristic(this.hap.Characteristic.Brightness)
|
|
106
57
|
.setProps({
|
|
107
58
|
minStep: this.minStep(device),
|
|
@@ -110,11 +61,11 @@ export class StripLight {
|
|
|
110
61
|
validValueRanges: [0, 100],
|
|
111
62
|
})
|
|
112
63
|
.onGet(() => {
|
|
113
|
-
return this.Brightness;
|
|
64
|
+
return this.LightBulb.Brightness;
|
|
114
65
|
})
|
|
115
66
|
.onSet(this.BrightnessSet.bind(this));
|
|
116
67
|
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
117
|
-
this.
|
|
68
|
+
this.LightBulb.Service
|
|
118
69
|
.getCharacteristic(this.hap.Characteristic.ColorTemperature)
|
|
119
70
|
.setProps({
|
|
120
71
|
minValue: 140,
|
|
@@ -122,11 +73,11 @@ export class StripLight {
|
|
|
122
73
|
validValueRanges: [140, 500],
|
|
123
74
|
})
|
|
124
75
|
.onGet(() => {
|
|
125
|
-
return this.ColorTemperature;
|
|
76
|
+
return this.LightBulb.ColorTemperature;
|
|
126
77
|
})
|
|
127
78
|
.onSet(this.ColorTemperatureSet.bind(this));
|
|
128
79
|
// handle Hue events using the Hue characteristic
|
|
129
|
-
this.
|
|
80
|
+
this.LightBulb.Service
|
|
130
81
|
.getCharacteristic(this.hap.Characteristic.Hue)
|
|
131
82
|
.setProps({
|
|
132
83
|
minValue: 0,
|
|
@@ -134,11 +85,11 @@ export class StripLight {
|
|
|
134
85
|
validValueRanges: [0, 360],
|
|
135
86
|
})
|
|
136
87
|
.onGet(() => {
|
|
137
|
-
return this.Hue;
|
|
88
|
+
return this.LightBulb.Hue;
|
|
138
89
|
})
|
|
139
90
|
.onSet(this.HueSet.bind(this));
|
|
140
91
|
// handle Hue events using the Hue characteristic
|
|
141
|
-
this.
|
|
92
|
+
this.LightBulb.Service
|
|
142
93
|
.getCharacteristic(this.hap.Characteristic.Saturation)
|
|
143
94
|
.setProps({
|
|
144
95
|
minValue: 0,
|
|
@@ -146,12 +97,12 @@ export class StripLight {
|
|
|
146
97
|
validValueRanges: [0, 100],
|
|
147
98
|
})
|
|
148
99
|
.onGet(() => {
|
|
149
|
-
return this.Saturation;
|
|
100
|
+
return this.LightBulb.Saturation;
|
|
150
101
|
})
|
|
151
102
|
.onSet(this.SaturationSet.bind(this));
|
|
152
103
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
153
104
|
if (this.adaptiveLightingShift !== -1) {
|
|
154
|
-
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.
|
|
105
|
+
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
|
|
155
106
|
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
156
107
|
});
|
|
157
108
|
this.accessory.configureController(this.AdaptiveLightingController);
|
|
@@ -168,19 +119,33 @@ export class StripLight {
|
|
|
168
119
|
await this.refreshStatus();
|
|
169
120
|
});
|
|
170
121
|
//regisiter webhook event handler
|
|
171
|
-
if (
|
|
172
|
-
this.
|
|
122
|
+
if (device.webhook) {
|
|
123
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
173
124
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
174
125
|
try {
|
|
175
126
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
176
127
|
const { powerState, brightness, color, colorTemperature } = context;
|
|
177
|
-
const { On, Brightness, Hue, Saturation, ColorTemperature } = this;
|
|
128
|
+
const { On, Brightness, Hue, Saturation, ColorTemperature } = this.LightBulb;
|
|
178
129
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
179
130
|
'(powerState, brightness, color, colorTemperature) = ' +
|
|
180
131
|
`Webhook:(${powerState}, ${brightness}, ${color}, ${colorTemperature}), ` +
|
|
181
132
|
`current:(${On}, ${Brightness}, ${Hue}, ${Saturation}, ${ColorTemperature})`);
|
|
182
|
-
|
|
183
|
-
this.
|
|
133
|
+
// On
|
|
134
|
+
this.LightBulb.On = powerState === 'ON' ? true : false;
|
|
135
|
+
if (this.accessory.context.Brightness !== this.LightBulb.On) {
|
|
136
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
140
|
+
}
|
|
141
|
+
// Brightness
|
|
142
|
+
this.LightBulb.Brightness = brightness;
|
|
143
|
+
if (this.accessory.context.Brightness !== this.LightBulb.Brightness) {
|
|
144
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
148
|
+
}
|
|
184
149
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(color)}`);
|
|
185
150
|
const [red, green, blue] = color.split(':');
|
|
186
151
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
@@ -189,11 +154,29 @@ export class StripLight {
|
|
|
189
154
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
190
155
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
191
156
|
// Hue
|
|
192
|
-
this.Hue = hue;
|
|
193
|
-
|
|
157
|
+
this.LightBulb.Hue = hue;
|
|
158
|
+
if (this.accessory.context.Hue !== this.LightBulb.Hue) {
|
|
159
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
163
|
+
}
|
|
194
164
|
// Saturation
|
|
195
|
-
this.Saturation = saturation;
|
|
196
|
-
|
|
165
|
+
this.LightBulb.Saturation = saturation;
|
|
166
|
+
if (this.accessory.context.Saturation !== this.LightBulb.Saturation) {
|
|
167
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
171
|
+
}
|
|
172
|
+
// ColorTemperature
|
|
173
|
+
this.LightBulb.ColorTemperature = colorTemperature;
|
|
174
|
+
if (this.accessory.context.ColorTemperature !== this.LightBulb.ColorTemperature) {
|
|
175
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
179
|
+
}
|
|
197
180
|
this.updateHomeKitCharacteristics();
|
|
198
181
|
}
|
|
199
182
|
catch (e) {
|
|
@@ -220,68 +203,77 @@ export class StripLight {
|
|
|
220
203
|
this.stripLightUpdateInProgress = false;
|
|
221
204
|
});
|
|
222
205
|
}
|
|
223
|
-
|
|
224
|
-
* Parse the device status from the SwitchBot api
|
|
225
|
-
*/
|
|
226
|
-
async parseStatus() {
|
|
227
|
-
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
228
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
229
|
-
}
|
|
230
|
-
else if (this.BLE) {
|
|
231
|
-
await this.BLEparseStatus();
|
|
232
|
-
}
|
|
233
|
-
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
234
|
-
await this.openAPIparseStatus();
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
await this.offlineOff();
|
|
238
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
async BLEparseStatus() {
|
|
206
|
+
async BLEparseStatus(serviceData) {
|
|
242
207
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
243
208
|
// State
|
|
244
|
-
switch (
|
|
209
|
+
switch (serviceData.state) {
|
|
245
210
|
case 'on':
|
|
246
|
-
this.On = true;
|
|
211
|
+
this.LightBulb.On = true;
|
|
247
212
|
break;
|
|
248
213
|
default:
|
|
249
|
-
this.On = false;
|
|
214
|
+
this.LightBulb.On = false;
|
|
215
|
+
}
|
|
216
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
217
|
+
// Brightness
|
|
218
|
+
this.LightBulb.Brightness = Number(serviceData.brightness);
|
|
219
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
220
|
+
// Color, Hue & Brightness
|
|
221
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${serviceData.red}`);
|
|
222
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${serviceData.green}`);
|
|
223
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${serviceData.blue}`);
|
|
224
|
+
const [hue, saturation] = rgb2hs(Number(serviceData.red), Number(serviceData.green), Number(serviceData.blue));
|
|
225
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
226
|
+
` hs: ${JSON.stringify(rgb2hs(Number(serviceData.red), Number(serviceData.green), Number(serviceData.blue)))}`);
|
|
227
|
+
// Hue
|
|
228
|
+
this.LightBulb.Hue = hue;
|
|
229
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
230
|
+
// Saturation
|
|
231
|
+
this.LightBulb.Saturation = saturation;
|
|
232
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
233
|
+
// ColorTemperature
|
|
234
|
+
if (serviceData.color_temperature) {
|
|
235
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${serviceData.color_temperature}`);
|
|
236
|
+
this.LightBulb.ColorTemperature = serviceData.color_temperature;
|
|
237
|
+
this.LightBulb.ColorTemperature = Math.max(Math.min(this.LightBulb.ColorTemperature, 500), 140);
|
|
238
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
250
239
|
}
|
|
251
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
252
240
|
}
|
|
253
|
-
async openAPIparseStatus() {
|
|
241
|
+
async openAPIparseStatus(deviceStatus) {
|
|
254
242
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
255
|
-
switch (
|
|
243
|
+
switch (deviceStatus.body.power) {
|
|
256
244
|
case 'on':
|
|
257
|
-
this.On = true;
|
|
245
|
+
this.LightBulb.On = true;
|
|
258
246
|
break;
|
|
259
247
|
default:
|
|
260
|
-
this.On = false;
|
|
248
|
+
this.LightBulb.On = false;
|
|
261
249
|
}
|
|
262
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
250
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
263
251
|
// Brightness
|
|
264
|
-
this.Brightness = Number(
|
|
265
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
252
|
+
this.LightBulb.Brightness = Number(deviceStatus.body.brightness);
|
|
253
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
266
254
|
// Color, Hue & Brightness
|
|
267
|
-
if (
|
|
268
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(
|
|
269
|
-
const [red, green, blue] =
|
|
255
|
+
if (deviceStatus.body.color) {
|
|
256
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(deviceStatus.body.color)}`);
|
|
257
|
+
const [red, green, blue] = deviceStatus.body.color.split(':');
|
|
270
258
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
271
259
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
272
260
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
273
261
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
274
262
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
275
263
|
// Hue
|
|
276
|
-
this.Hue = hue;
|
|
277
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
264
|
+
this.LightBulb.Hue = hue;
|
|
265
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
278
266
|
// Saturation
|
|
279
|
-
this.Saturation = saturation;
|
|
280
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
267
|
+
this.LightBulb.Saturation = saturation;
|
|
268
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
281
269
|
}
|
|
282
270
|
// FirmwareRevision
|
|
283
|
-
this.FirmwareRevision =
|
|
284
|
-
this.accessory
|
|
271
|
+
this.accessory.context.FirmwareRevision = deviceStatus.body.version;
|
|
272
|
+
this.accessory
|
|
273
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
274
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.FirmwareRevision)
|
|
275
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
276
|
+
.updateValue(this.accessory.context.FirmwareRevision);
|
|
285
277
|
}
|
|
286
278
|
/**
|
|
287
279
|
* Asks the SwitchBot API for the latest device information
|
|
@@ -315,96 +307,42 @@ export class StripLight {
|
|
|
315
307
|
// Start to monitor advertisement packets
|
|
316
308
|
(async () => {
|
|
317
309
|
// Start to monitor advertisement packets
|
|
318
|
-
await switchbot.startScan({
|
|
319
|
-
model: 'r',
|
|
320
|
-
id: this.device.bleMac,
|
|
321
|
-
});
|
|
310
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
322
311
|
// Set an event handler
|
|
323
312
|
switchbot.onadvertisement = (ad) => {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
313
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
314
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
315
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
327
316
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
328
317
|
}
|
|
329
318
|
else {
|
|
330
319
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
331
320
|
}
|
|
332
321
|
};
|
|
333
|
-
// Wait
|
|
322
|
+
// Wait 10 seconds
|
|
334
323
|
await switchbot.wait(this.scanDuration * 1000);
|
|
335
324
|
// Stop to monitor
|
|
336
325
|
await switchbot.stopScan();
|
|
337
326
|
// Update HomeKit
|
|
338
|
-
await this.BLEparseStatus();
|
|
327
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
339
328
|
await this.updateHomeKitCharacteristics();
|
|
340
329
|
})();
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
model: 'r',
|
|
345
|
-
id: this.device.bleMac,
|
|
346
|
-
})
|
|
347
|
-
.then(async () => {
|
|
348
|
-
// Set an event handler
|
|
349
|
-
switchbot.onadvertisement = async (ad: ad) => {
|
|
350
|
-
this.debugLog(
|
|
351
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
352
|
-
` BLE Address Found: ${ad.address}`,
|
|
353
|
-
);
|
|
354
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
355
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
356
|
-
this.debugLog(
|
|
357
|
-
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
358
|
-
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
359
|
-
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
360
|
-
);
|
|
361
|
-
|
|
362
|
-
if (ad.serviceData) {
|
|
363
|
-
this.BLE_IsConnected = true;
|
|
364
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
365
|
-
await this.stopScanning(switchbot);
|
|
366
|
-
} else {
|
|
367
|
-
this.BLE_IsConnected = false;
|
|
368
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
// Wait
|
|
372
|
-
return await sleep(this.scanDuration * 1000);
|
|
373
|
-
})
|
|
374
|
-
.then(async () => {
|
|
375
|
-
// Stop to monitor
|
|
376
|
-
await this.stopScanning(switchbot);
|
|
377
|
-
})
|
|
378
|
-
.catch(async (e: any) => {
|
|
379
|
-
this.apiError(e);
|
|
380
|
-
this.errorLog(
|
|
381
|
-
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
382
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
383
|
-
);
|
|
384
|
-
await this.BLERefreshConnection(switchbot);
|
|
385
|
-
});
|
|
386
|
-
} else {
|
|
387
|
-
await this.BLERefreshConnection(switchbot);
|
|
388
|
-
}*/
|
|
330
|
+
if (switchbot === undefined) {
|
|
331
|
+
await this.BLERefreshConnection(switchbot);
|
|
332
|
+
}
|
|
389
333
|
}
|
|
390
334
|
async openAPIRefreshStatus() {
|
|
391
335
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
392
336
|
try {
|
|
393
|
-
const { body, statusCode } = await
|
|
394
|
-
headers: this.platform.generateHeaders(),
|
|
395
|
-
});
|
|
337
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries, `${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
396
338
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
397
339
|
const deviceStatus = await body.json();
|
|
398
340
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
399
341
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
400
342
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
401
|
-
this.
|
|
343
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
402
344
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
403
|
-
this.
|
|
404
|
-
this.OpenAPI_RGB = deviceStatus.body.color;
|
|
405
|
-
this.OpenAPI_Brightness = deviceStatus.body.brightness;
|
|
406
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
407
|
-
this.openAPIparseStatus();
|
|
345
|
+
this.openAPIparseStatus(deviceStatus);
|
|
408
346
|
this.updateHomeKitCharacteristics();
|
|
409
347
|
}
|
|
410
348
|
else {
|
|
@@ -451,8 +389,9 @@ export class StripLight {
|
|
|
451
389
|
}
|
|
452
390
|
async BLEpushChanges() {
|
|
453
391
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
|
|
454
|
-
if (this.On !== this.accessory.context.On) {
|
|
455
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges
|
|
392
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
393
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`
|
|
394
|
+
+ ` On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`);
|
|
456
395
|
const switchbot = await this.platform.connectBLE();
|
|
457
396
|
// Convert to BLE Address
|
|
458
397
|
this.device.bleMac = this.device
|
|
@@ -466,11 +405,11 @@ export class StripLight {
|
|
|
466
405
|
id: this.device.bleMac,
|
|
467
406
|
})
|
|
468
407
|
.then(async (device_list) => {
|
|
469
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
470
|
-
return await this.
|
|
471
|
-
max: this.
|
|
408
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
409
|
+
return await this.retryBLE({
|
|
410
|
+
max: await this.maxRetryBLE(),
|
|
472
411
|
fn: async () => {
|
|
473
|
-
if (this.On) {
|
|
412
|
+
if (this.LightBulb.On) {
|
|
474
413
|
return await device_list[0].turnOn({ id: this.device.bleMac });
|
|
475
414
|
}
|
|
476
415
|
else {
|
|
@@ -481,7 +420,9 @@ export class StripLight {
|
|
|
481
420
|
})
|
|
482
421
|
.then(() => {
|
|
483
422
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
484
|
-
this.
|
|
423
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
424
|
+
+ `On: ${this.LightBulb.On} sent over BLE, sent successfully`);
|
|
425
|
+
this.LightBulb.On = false;
|
|
485
426
|
})
|
|
486
427
|
.catch(async (e) => {
|
|
487
428
|
this.apiError(e);
|
|
@@ -490,21 +431,30 @@ export class StripLight {
|
|
|
490
431
|
await this.BLEPushConnection();
|
|
491
432
|
});
|
|
492
433
|
// Push Brightness Update
|
|
493
|
-
if (this.On) {
|
|
434
|
+
if (this.LightBulb.On) {
|
|
494
435
|
await this.BLEpushBrightnessChanges();
|
|
495
436
|
}
|
|
496
437
|
// Push Hue & Saturation Update
|
|
497
|
-
if (this.On) {
|
|
438
|
+
if (this.LightBulb.On) {
|
|
498
439
|
await this.BLEpushRGBChanges();
|
|
499
440
|
}
|
|
441
|
+
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
442
|
+
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
|
|
443
|
+
this.accessory.context.kelvin = kelvin;
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.`
|
|
447
|
+
+ `ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
448
|
+
}
|
|
500
449
|
}
|
|
501
450
|
else {
|
|
502
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges
|
|
451
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges,`
|
|
452
|
+
+ ` On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
503
453
|
}
|
|
504
454
|
}
|
|
505
455
|
async BLEpushBrightnessChanges() {
|
|
506
456
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushBrightnessChanges`);
|
|
507
|
-
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
457
|
+
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
508
458
|
const switchbot = await this.platform.connectBLE();
|
|
509
459
|
// Convert to BLE Address
|
|
510
460
|
this.device.bleMac = this.device
|
|
@@ -518,12 +468,12 @@ export class StripLight {
|
|
|
518
468
|
id: this.device.bleMac,
|
|
519
469
|
})
|
|
520
470
|
.then(async (device_list) => {
|
|
521
|
-
this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.Brightness}`);
|
|
522
|
-
return await device_list[0].setBrightness(this.Brightness);
|
|
471
|
+
this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.LightBulb.Brightness}`);
|
|
472
|
+
return await device_list[0].setBrightness(this.LightBulb.Brightness);
|
|
523
473
|
})
|
|
524
474
|
.then(() => {
|
|
525
475
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
526
|
-
this.On = false;
|
|
476
|
+
this.LightBulb.On = false;
|
|
527
477
|
})
|
|
528
478
|
.catch(async (e) => {
|
|
529
479
|
this.apiError(e);
|
|
@@ -534,16 +484,16 @@ export class StripLight {
|
|
|
534
484
|
}
|
|
535
485
|
else {
|
|
536
486
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` +
|
|
537
|
-
`Brightness: ${this.Brightness}, ` +
|
|
487
|
+
`Brightness: ${this.LightBulb.Brightness}, ` +
|
|
538
488
|
`BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
539
489
|
}
|
|
540
490
|
}
|
|
541
491
|
async BLEpushRGBChanges() {
|
|
542
492
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushRGBChanges`);
|
|
543
|
-
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
544
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
545
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
546
|
-
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
493
|
+
if (this.LightBulb.Hue !== this.accessory.context.Hue || this.LightBulb.Saturation !== this.accessory.context.Saturation) {
|
|
494
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.LightBulb.Hue)}`);
|
|
495
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
|
|
496
|
+
const [red, green, blue] = hs2rgb(Number(this.LightBulb.Hue), Number(this.LightBulb.Saturation));
|
|
547
497
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
548
498
|
const switchbot = await this.platform.connectBLE();
|
|
549
499
|
// Convert to BLE Address
|
|
@@ -558,12 +508,12 @@ export class StripLight {
|
|
|
558
508
|
id: this.device.bleMac,
|
|
559
509
|
})
|
|
560
510
|
.then(async (device_list) => {
|
|
561
|
-
this.infoLog(`${this.accessory.displayName} Target RGB: ${(this.Brightness, red, green, blue)}`);
|
|
562
|
-
return await device_list[0].setRGB(this.Brightness, red, green, blue);
|
|
511
|
+
this.infoLog(`${this.accessory.displayName} Target RGB: ${(this.LightBulb.Brightness, red, green, blue)}`);
|
|
512
|
+
return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue);
|
|
563
513
|
})
|
|
564
514
|
.then(() => {
|
|
565
515
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
566
|
-
this.On = false;
|
|
516
|
+
this.LightBulb.On = false;
|
|
567
517
|
})
|
|
568
518
|
.catch(async (e) => {
|
|
569
519
|
this.apiError(e);
|
|
@@ -573,15 +523,15 @@ export class StripLight {
|
|
|
573
523
|
});
|
|
574
524
|
}
|
|
575
525
|
else {
|
|
576
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.Hue}, ` +
|
|
577
|
-
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
526
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.LightBulb.Hue}, ` +
|
|
527
|
+
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
578
528
|
}
|
|
579
529
|
}
|
|
580
530
|
async openAPIpushChanges() {
|
|
581
531
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
582
|
-
if (this.On !== this.accessory.context.On) {
|
|
583
|
-
const command = this.On ? 'turnOn' : 'turnOff';
|
|
584
|
-
/*if (this.On) {
|
|
532
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
533
|
+
const command = this.LightBulb.On ? 'turnOn' : 'turnOff';
|
|
534
|
+
/*if (this.LightBulb.On) {
|
|
585
535
|
command = 'turnOn';
|
|
586
536
|
} else {
|
|
587
537
|
command = 'turnOff';
|
|
@@ -606,6 +556,8 @@ export class StripLight {
|
|
|
606
556
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
607
557
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
608
558
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
559
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
560
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
609
561
|
}
|
|
610
562
|
else {
|
|
611
563
|
this.statusCode(statusCode);
|
|
@@ -620,24 +572,24 @@ export class StripLight {
|
|
|
620
572
|
}
|
|
621
573
|
else {
|
|
622
574
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
|
|
623
|
-
`On: ${this.On}, ` +
|
|
575
|
+
`On: ${this.LightBulb.On}, ` +
|
|
624
576
|
`OnCached: ${this.accessory.context.On}`);
|
|
625
577
|
}
|
|
626
578
|
// Push Hue & Saturation Update
|
|
627
|
-
if (this.On) {
|
|
579
|
+
if (this.LightBulb.On) {
|
|
628
580
|
await this.pushHueSaturationChanges();
|
|
629
581
|
}
|
|
630
582
|
// Push Brightness Update
|
|
631
|
-
if (this.On) {
|
|
583
|
+
if (this.LightBulb.On) {
|
|
632
584
|
await this.pushBrightnessChanges();
|
|
633
585
|
}
|
|
634
586
|
}
|
|
635
587
|
async pushHueSaturationChanges() {
|
|
636
588
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges`);
|
|
637
|
-
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
638
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
639
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
640
|
-
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
589
|
+
if (this.LightBulb.Hue !== this.accessory.context.Hue || this.LightBulb.Saturation !== this.accessory.context.Saturation) {
|
|
590
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.LightBulb.Hue)}`);
|
|
591
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
|
|
592
|
+
const [red, green, blue] = hs2rgb(Number(this.LightBulb.Hue), Number(this.LightBulb.Saturation));
|
|
641
593
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
642
594
|
// Make Push On request to the API
|
|
643
595
|
const bodyChange = JSON.stringify({
|
|
@@ -660,6 +612,8 @@ export class StripLight {
|
|
|
660
612
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
661
613
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
662
614
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
615
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
616
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
663
617
|
}
|
|
664
618
|
else {
|
|
665
619
|
this.statusCode(statusCode);
|
|
@@ -673,16 +627,16 @@ export class StripLight {
|
|
|
673
627
|
}
|
|
674
628
|
}
|
|
675
629
|
else {
|
|
676
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, ` +
|
|
677
|
-
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
630
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.LightBulb.Hue}, ` +
|
|
631
|
+
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
678
632
|
}
|
|
679
633
|
}
|
|
680
634
|
async pushBrightnessChanges() {
|
|
681
635
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
|
|
682
|
-
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
636
|
+
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
683
637
|
const bodyChange = JSON.stringify({
|
|
684
638
|
command: 'setBrightness',
|
|
685
|
-
parameter: `${this.Brightness}`,
|
|
639
|
+
parameter: `${this.LightBulb.Brightness}`,
|
|
686
640
|
commandType: 'command',
|
|
687
641
|
});
|
|
688
642
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
@@ -700,6 +654,8 @@ export class StripLight {
|
|
|
700
654
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
701
655
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
702
656
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
657
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
658
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
703
659
|
}
|
|
704
660
|
else {
|
|
705
661
|
this.statusCode(statusCode);
|
|
@@ -714,7 +670,7 @@ export class StripLight {
|
|
|
714
670
|
}
|
|
715
671
|
else {
|
|
716
672
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges,` +
|
|
717
|
-
`Brightness: ${this.Brightness}, ` +
|
|
673
|
+
`Brightness: ${this.LightBulb.Brightness}, ` +
|
|
718
674
|
`BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
719
675
|
}
|
|
720
676
|
}
|
|
@@ -722,165 +678,140 @@ export class StripLight {
|
|
|
722
678
|
* Handle requests to set the value of the "On" characteristic
|
|
723
679
|
*/
|
|
724
680
|
async OnSet(value) {
|
|
725
|
-
if (this.On === this.accessory.context.On) {
|
|
681
|
+
if (this.LightBulb.On === this.accessory.context.On) {
|
|
726
682
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set On: ${value}`);
|
|
727
683
|
}
|
|
728
684
|
else {
|
|
729
685
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
|
|
730
686
|
}
|
|
731
|
-
this.On = value;
|
|
687
|
+
this.LightBulb.On = value;
|
|
732
688
|
this.doStripLightUpdate.next();
|
|
733
689
|
}
|
|
734
690
|
/**
|
|
735
691
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
736
692
|
*/
|
|
737
693
|
async BrightnessSet(value) {
|
|
738
|
-
if (this.Brightness === this.accessory.context.Brightness) {
|
|
694
|
+
if (this.LightBulb.Brightness === this.accessory.context.Brightness) {
|
|
739
695
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Brightness: ${value}`);
|
|
740
696
|
}
|
|
741
|
-
else if (this.On) {
|
|
697
|
+
else if (this.LightBulb.On) {
|
|
742
698
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
743
699
|
}
|
|
744
700
|
else {
|
|
745
701
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
746
702
|
}
|
|
747
|
-
this.Brightness = value;
|
|
703
|
+
this.LightBulb.Brightness = value;
|
|
748
704
|
this.doStripLightUpdate.next();
|
|
749
705
|
}
|
|
750
706
|
/**
|
|
751
707
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
752
708
|
*/
|
|
753
709
|
async ColorTemperatureSet(value) {
|
|
754
|
-
if (this.ColorTemperature === this.accessory.context.ColorTemperature) {
|
|
710
|
+
if (this.LightBulb.ColorTemperature === this.accessory.context.ColorTemperature) {
|
|
755
711
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set ColorTemperature: ${value}`);
|
|
756
712
|
}
|
|
757
|
-
else if (this.On) {
|
|
713
|
+
else if (this.LightBulb.On) {
|
|
758
714
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
|
|
759
715
|
}
|
|
760
716
|
else {
|
|
761
717
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
|
|
762
718
|
}
|
|
719
|
+
const minKelvin = 2000;
|
|
720
|
+
const maxKelvin = 9000;
|
|
763
721
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
764
722
|
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
765
723
|
// Check and increase/decrease kelvin to range of device
|
|
766
|
-
const k = Math.min(Math.max(kelvin,
|
|
767
|
-
if (!this.accessory.context.On || this.
|
|
724
|
+
const k = Math.min(Math.max(kelvin, minKelvin), maxKelvin);
|
|
725
|
+
if (!this.accessory.context.On || this.accessory.context.maxKelvin === k) {
|
|
768
726
|
return;
|
|
769
727
|
}
|
|
770
728
|
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
771
729
|
const hs = m2hs(value);
|
|
772
|
-
this.
|
|
773
|
-
this.
|
|
774
|
-
this.ColorTemperature = value;
|
|
730
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, hs[0]);
|
|
731
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, hs[1]);
|
|
732
|
+
this.LightBulb.ColorTemperature = value;
|
|
775
733
|
this.doStripLightUpdate.next();
|
|
776
734
|
}
|
|
777
735
|
/**
|
|
778
736
|
* Handle requests to set the value of the "Hue" characteristic
|
|
779
737
|
*/
|
|
780
738
|
async HueSet(value) {
|
|
781
|
-
if (this.Hue === this.accessory.context.Hue) {
|
|
739
|
+
if (this.LightBulb.Hue === this.accessory.context.Hue) {
|
|
782
740
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Hue: ${value}`);
|
|
783
741
|
}
|
|
784
|
-
else if (this.On) {
|
|
742
|
+
else if (this.LightBulb.On) {
|
|
785
743
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
786
744
|
}
|
|
787
745
|
else {
|
|
788
746
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
789
747
|
}
|
|
790
|
-
this.
|
|
791
|
-
this.Hue = value;
|
|
748
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
749
|
+
this.LightBulb.Hue = value;
|
|
792
750
|
this.doStripLightUpdate.next();
|
|
793
751
|
}
|
|
794
752
|
/**
|
|
795
753
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
796
754
|
*/
|
|
797
755
|
async SaturationSet(value) {
|
|
798
|
-
if (this.Saturation === this.accessory.context.Saturation) {
|
|
756
|
+
if (this.LightBulb.Saturation === this.accessory.context.Saturation) {
|
|
799
757
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Saturation: ${value}`);
|
|
800
758
|
}
|
|
801
|
-
else if (this.On) {
|
|
759
|
+
else if (this.LightBulb.On) {
|
|
802
760
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
803
761
|
}
|
|
804
762
|
else {
|
|
805
763
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
806
764
|
}
|
|
807
|
-
this.
|
|
808
|
-
this.Saturation = value;
|
|
765
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
766
|
+
this.LightBulb.Saturation = value;
|
|
809
767
|
this.doStripLightUpdate.next();
|
|
810
768
|
}
|
|
811
769
|
async updateHomeKitCharacteristics() {
|
|
812
770
|
// On
|
|
813
|
-
if (this.On === undefined) {
|
|
814
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
771
|
+
if (this.LightBulb.On === undefined) {
|
|
772
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
815
773
|
}
|
|
816
774
|
else {
|
|
817
|
-
this.accessory.context.On = this.On;
|
|
818
|
-
this.
|
|
819
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
775
|
+
this.accessory.context.On = this.LightBulb.On;
|
|
776
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
|
|
777
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
|
|
820
778
|
}
|
|
821
779
|
// Brightness
|
|
822
|
-
if (this.Brightness === undefined) {
|
|
823
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
780
|
+
if (this.LightBulb.Brightness === undefined) {
|
|
781
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
824
782
|
}
|
|
825
783
|
else {
|
|
826
|
-
this.accessory.context.Brightness = this.Brightness;
|
|
827
|
-
this.
|
|
828
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
784
|
+
this.accessory.context.Brightness = this.LightBulb.Brightness;
|
|
785
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, this.LightBulb.Brightness);
|
|
786
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.LightBulb.Brightness}`);
|
|
829
787
|
}
|
|
830
788
|
// ColorTemperature
|
|
831
|
-
if (this.ColorTemperature === undefined) {
|
|
832
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
789
|
+
if (this.LightBulb.ColorTemperature === undefined) {
|
|
790
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
833
791
|
}
|
|
834
792
|
else {
|
|
835
|
-
this.accessory.context.ColorTemperature = this.ColorTemperature;
|
|
836
|
-
this.
|
|
837
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
793
|
+
this.accessory.context.ColorTemperature = this.LightBulb.ColorTemperature;
|
|
794
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, this.LightBulb.ColorTemperature);
|
|
795
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
796
|
+
+ ` ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
838
797
|
}
|
|
839
798
|
// Hue
|
|
840
|
-
if (this.Hue === undefined) {
|
|
841
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
799
|
+
if (this.LightBulb.Hue === undefined) {
|
|
800
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
842
801
|
}
|
|
843
802
|
else {
|
|
844
|
-
this.accessory.context.Hue = this.Hue;
|
|
845
|
-
this.
|
|
846
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
803
|
+
this.accessory.context.Hue = this.LightBulb.Hue;
|
|
804
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, this.LightBulb.Hue);
|
|
805
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.LightBulb.Hue}`);
|
|
847
806
|
}
|
|
848
807
|
// Saturation
|
|
849
|
-
if (this.Saturation === undefined) {
|
|
850
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
808
|
+
if (this.LightBulb.Saturation === undefined) {
|
|
809
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
851
810
|
}
|
|
852
811
|
else {
|
|
853
|
-
this.accessory.context.Saturation = this.Saturation;
|
|
854
|
-
this.
|
|
855
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
async stopScanning(switchbot) {
|
|
859
|
-
switchbot.stopScan();
|
|
860
|
-
if (this.BLE_IsConnected) {
|
|
861
|
-
await this.BLEparseStatus();
|
|
862
|
-
await this.updateHomeKitCharacteristics();
|
|
863
|
-
}
|
|
864
|
-
else {
|
|
865
|
-
await this.BLERefreshConnection(switchbot);
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
async getCustomBLEAddress(switchbot) {
|
|
869
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
870
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
|
|
871
|
-
(async () => {
|
|
872
|
-
// Start to monitor advertisement packets
|
|
873
|
-
await switchbot.startScan({
|
|
874
|
-
model: 'r',
|
|
875
|
-
});
|
|
876
|
-
// Set an event handler
|
|
877
|
-
switchbot.onadvertisement = (ad) => {
|
|
878
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
879
|
-
};
|
|
880
|
-
await sleep(10000);
|
|
881
|
-
// Stop to monitor
|
|
882
|
-
switchbot.stopScan();
|
|
883
|
-
})();
|
|
812
|
+
this.accessory.context.Saturation = this.LightBulb.Saturation;
|
|
813
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, this.LightBulb.Saturation);
|
|
814
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.LightBulb.Saturation}`);
|
|
884
815
|
}
|
|
885
816
|
}
|
|
886
817
|
async BLEPushConnection() {
|
|
@@ -897,33 +828,15 @@ export class StripLight {
|
|
|
897
828
|
await this.openAPIRefreshStatus();
|
|
898
829
|
}
|
|
899
830
|
}
|
|
900
|
-
async retry({ max, fn }) {
|
|
901
|
-
return fn().catch(async (e) => {
|
|
902
|
-
if (max === 0) {
|
|
903
|
-
throw e;
|
|
904
|
-
}
|
|
905
|
-
this.infoLog(e);
|
|
906
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
|
|
907
|
-
await sleep(1000);
|
|
908
|
-
return this.retry({ max: max - 1, fn });
|
|
909
|
-
});
|
|
910
|
-
}
|
|
911
|
-
maxRetry() {
|
|
912
|
-
if (this.device.maxRetry) {
|
|
913
|
-
return this.device.maxRetry;
|
|
914
|
-
}
|
|
915
|
-
else {
|
|
916
|
-
return 5;
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
831
|
minStep(device) {
|
|
832
|
+
let set_minStep;
|
|
920
833
|
if (device.striplight?.set_minStep) {
|
|
921
|
-
|
|
834
|
+
set_minStep = device.striplight?.set_minStep;
|
|
922
835
|
}
|
|
923
836
|
else {
|
|
924
|
-
|
|
837
|
+
set_minStep = 1;
|
|
925
838
|
}
|
|
926
|
-
return
|
|
839
|
+
return set_minStep;
|
|
927
840
|
}
|
|
928
841
|
async adaptiveLighting(device) {
|
|
929
842
|
if (device.striplight?.adaptiveLightingShift) {
|
|
@@ -935,246 +848,17 @@ export class StripLight {
|
|
|
935
848
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
936
849
|
}
|
|
937
850
|
}
|
|
938
|
-
async scan(device) {
|
|
939
|
-
if (device.scanDuration) {
|
|
940
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
941
|
-
if (this.BLE) {
|
|
942
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
else {
|
|
946
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
947
|
-
if (this.BLE) {
|
|
948
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
async statusCode(statusCode) {
|
|
953
|
-
switch (statusCode) {
|
|
954
|
-
case 151:
|
|
955
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
956
|
-
break;
|
|
957
|
-
case 152:
|
|
958
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
959
|
-
break;
|
|
960
|
-
case 160:
|
|
961
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
962
|
-
break;
|
|
963
|
-
case 161:
|
|
964
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
965
|
-
this.offlineOff();
|
|
966
|
-
break;
|
|
967
|
-
case 171:
|
|
968
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
969
|
-
`Hub: ${this.device.hubDeviceId}`);
|
|
970
|
-
this.offlineOff();
|
|
971
|
-
break;
|
|
972
|
-
case 190:
|
|
973
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
974
|
-
` Or command format is invalid, statusCode: ${statusCode}`);
|
|
975
|
-
break;
|
|
976
|
-
case 100:
|
|
977
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
978
|
-
break;
|
|
979
|
-
case 200:
|
|
980
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
981
|
-
break;
|
|
982
|
-
case 400:
|
|
983
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
984
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
985
|
-
break;
|
|
986
|
-
case 401:
|
|
987
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
988
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
989
|
-
break;
|
|
990
|
-
case 403:
|
|
991
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
992
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
993
|
-
break;
|
|
994
|
-
case 404:
|
|
995
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
996
|
-
+ `statusCode: ${statusCode}`);
|
|
997
|
-
break;
|
|
998
|
-
case 406:
|
|
999
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
1000
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
1001
|
-
break;
|
|
1002
|
-
case 415:
|
|
1003
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
1004
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
1005
|
-
break;
|
|
1006
|
-
case 422:
|
|
1007
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
1008
|
-
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
1009
|
-
break;
|
|
1010
|
-
case 429:
|
|
1011
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
1012
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
1013
|
-
break;
|
|
1014
|
-
case 500:
|
|
1015
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
1016
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
1017
|
-
break;
|
|
1018
|
-
default:
|
|
1019
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
1020
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
851
|
async offlineOff() {
|
|
1024
852
|
if (this.device.offline) {
|
|
1025
|
-
|
|
1026
|
-
await this.updateHomeKitCharacteristics();
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
apiError(e) {
|
|
1030
|
-
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1031
|
-
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Hue, e);
|
|
1032
|
-
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Brightness, e);
|
|
1033
|
-
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Saturation, e);
|
|
1034
|
-
}
|
|
1035
|
-
async deviceContext() {
|
|
1036
|
-
if (this.On === undefined) {
|
|
1037
|
-
this.On = false;
|
|
1038
|
-
}
|
|
1039
|
-
else {
|
|
1040
|
-
this.On = this.accessory.context.On;
|
|
1041
|
-
}
|
|
1042
|
-
if (this.Hue === undefined) {
|
|
1043
|
-
this.Hue = 0;
|
|
1044
|
-
}
|
|
1045
|
-
else {
|
|
1046
|
-
this.Hue = this.accessory.context.Hue;
|
|
1047
|
-
}
|
|
1048
|
-
if (this.Brightness === undefined) {
|
|
1049
|
-
this.Brightness = 0;
|
|
1050
|
-
}
|
|
1051
|
-
else {
|
|
1052
|
-
this.Brightness = this.accessory.context.Brightness;
|
|
1053
|
-
}
|
|
1054
|
-
if (this.Saturation === undefined) {
|
|
1055
|
-
this.Saturation = 0;
|
|
1056
|
-
}
|
|
1057
|
-
else {
|
|
1058
|
-
this.Saturation = this.accessory.context.Saturation;
|
|
1059
|
-
}
|
|
1060
|
-
if (this.ColorTemperature === undefined) {
|
|
1061
|
-
this.ColorTemperature = 140;
|
|
1062
|
-
}
|
|
1063
|
-
else {
|
|
1064
|
-
this.ColorTemperature = this.accessory.context.ColorTemperature;
|
|
1065
|
-
}
|
|
1066
|
-
this.minKelvin = 2000;
|
|
1067
|
-
this.maxKelvin = 9000;
|
|
1068
|
-
if (this.FirmwareRevision === undefined) {
|
|
1069
|
-
this.FirmwareRevision = this.platform.version;
|
|
1070
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
async refreshRate(device) {
|
|
1074
|
-
if (device.refreshRate) {
|
|
1075
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
1076
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1077
|
-
}
|
|
1078
|
-
else if (this.platform.config.options.refreshRate) {
|
|
1079
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
1080
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
async deviceConfig(device) {
|
|
1084
|
-
let config = {};
|
|
1085
|
-
if (device.striplight) {
|
|
1086
|
-
config = device.striplight;
|
|
1087
|
-
}
|
|
1088
|
-
if (device.connectionType !== undefined) {
|
|
1089
|
-
config['connectionType'] = device.connectionType;
|
|
1090
|
-
}
|
|
1091
|
-
if (device.external !== undefined) {
|
|
1092
|
-
config['external'] = device.external;
|
|
1093
|
-
}
|
|
1094
|
-
if (device.logging !== undefined) {
|
|
1095
|
-
config['logging'] = device.logging;
|
|
1096
|
-
}
|
|
1097
|
-
if (device.refreshRate !== undefined) {
|
|
1098
|
-
config['refreshRate'] = device.refreshRate;
|
|
1099
|
-
}
|
|
1100
|
-
if (device.scanDuration !== undefined) {
|
|
1101
|
-
config['scanDuration'] = device.scanDuration;
|
|
1102
|
-
}
|
|
1103
|
-
if (device.offline !== undefined) {
|
|
1104
|
-
config['offline'] = device.offline;
|
|
1105
|
-
}
|
|
1106
|
-
if (device.maxRetry !== undefined) {
|
|
1107
|
-
config['maxRetry'] = device.maxRetry;
|
|
1108
|
-
}
|
|
1109
|
-
if (device.webhook !== undefined) {
|
|
1110
|
-
config['webhook'] = device.webhook;
|
|
1111
|
-
}
|
|
1112
|
-
if (Object.entries(config).length !== 0) {
|
|
1113
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
async deviceLogs(device) {
|
|
1117
|
-
if (this.platform.debugMode) {
|
|
1118
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1119
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
1120
|
-
}
|
|
1121
|
-
else if (device.logging) {
|
|
1122
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
1123
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
1124
|
-
}
|
|
1125
|
-
else if (this.platform.config.options?.logging) {
|
|
1126
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
1127
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
1128
|
-
}
|
|
1129
|
-
else {
|
|
1130
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
1131
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
/**
|
|
1135
|
-
* Logging for Device
|
|
1136
|
-
*/
|
|
1137
|
-
infoLog(...log) {
|
|
1138
|
-
if (this.enablingDeviceLogging()) {
|
|
1139
|
-
this.platform.log.info(String(...log));
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
warnLog(...log) {
|
|
1143
|
-
if (this.enablingDeviceLogging()) {
|
|
1144
|
-
this.platform.log.warn(String(...log));
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
debugWarnLog(...log) {
|
|
1148
|
-
if (this.enablingDeviceLogging()) {
|
|
1149
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1150
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
errorLog(...log) {
|
|
1155
|
-
if (this.enablingDeviceLogging()) {
|
|
1156
|
-
this.platform.log.error(String(...log));
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
debugErrorLog(...log) {
|
|
1160
|
-
if (this.enablingDeviceLogging()) {
|
|
1161
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1162
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
debugLog(...log) {
|
|
1167
|
-
if (this.enablingDeviceLogging()) {
|
|
1168
|
-
if (this.deviceLogging === 'debug') {
|
|
1169
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
1170
|
-
}
|
|
1171
|
-
else {
|
|
1172
|
-
this.platform.log.debug(String(...log));
|
|
1173
|
-
}
|
|
853
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false);
|
|
1174
854
|
}
|
|
1175
855
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
856
|
+
async apiError(e) {
|
|
857
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
858
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, e);
|
|
859
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e);
|
|
860
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, e);
|
|
861
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, e);
|
|
1178
862
|
}
|
|
1179
863
|
}
|
|
1180
864
|
//# sourceMappingURL=lightstrip.js.map
|