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