@switchbot/homebridge-switchbot 3.5.0-beta.9 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +4 -1
- package/CHANGELOG.md +4 -1
- package/config.schema.json +166 -24
- package/dist/device/blindtilt.d.ts +21 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +439 -817
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +27 -72
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +835 -865
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +15 -69
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +287 -653
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +15 -76
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +354 -732
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -66
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +268 -576
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +18 -89
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +431 -851
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +60 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +739 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +63 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +698 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +15 -60
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +257 -631
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +11 -66
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +266 -629
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +12 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +215 -615
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +12 -70
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +336 -645
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +17 -63
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +290 -595
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +15 -64
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +211 -608
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +15 -65
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +205 -615
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +12 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +202 -563
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +10 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +125 -484
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +13 -63
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +233 -549
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +11 -63
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +170 -493
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +22 -16
- package/dist/homebridge-ui/server.js +1 -1
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +10 -50
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +340 -468
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -39
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +105 -319
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +7 -36
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +44 -285
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -43
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +92 -350
- 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 +369 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +12 -45
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +118 -362
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +19 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +438 -570
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +91 -339
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +45 -285
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +47 -291
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +22 -8
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +342 -191
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +64 -17
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -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 +96 -0
- package/package.json +20 -16
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +472 -888
- package/src/device/bot.ts +893 -968
- package/src/device/ceilinglight.ts +304 -709
- package/src/device/colorbulb.ts +370 -803
- package/src/device/contact.ts +301 -611
- package/src/device/curtain.ts +460 -908
- package/src/device/device.ts +755 -0
- package/src/device/fan.ts +749 -0
- package/src/device/hub.ts +294 -664
- package/src/device/humidifier.ts +299 -696
- package/src/device/iosensor.ts +251 -644
- package/src/device/lightstrip.ts +362 -712
- package/src/device/lock.ts +328 -653
- package/src/device/meter.ts +247 -637
- package/src/device/meterplus.ts +240 -644
- package/src/device/motion.ts +230 -598
- package/src/device/plug.ts +139 -525
- package/src/device/robotvacuumcleaner.ts +258 -593
- package/src/device/waterdetector.ts +191 -522
- package/src/homebridge-ui/public/index.html +22 -16
- package/src/homebridge-ui/server.ts +1 -1
- package/src/index.ts +4 -3
- package/src/irdevice/airconditioner.ts +370 -527
- package/src/irdevice/airpurifier.ts +132 -356
- package/src/irdevice/camera.ts +58 -311
- package/src/irdevice/fan.ts +109 -379
- package/src/irdevice/irdevice.ts +382 -0
- package/src/irdevice/light.ts +157 -412
- package/src/irdevice/other.ts +507 -648
- package/src/irdevice/tv.ts +121 -375
- package/src/irdevice/vacuumcleaner.ts +59 -311
- package/src/irdevice/waterheater.ts +61 -320
- package/src/platform.ts +395 -259
- package/src/settings.ts +118 -609
- package/src/utils.ts +642 -1
- package/.github/npm-version-script.cjs +0 -81
- package/src/device/waterdetector.json +0 -11
package/dist/irdevice/light.js
CHANGED
|
@@ -1,116 +1,110 @@
|
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* light.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
1
5
|
import { request } from 'undici';
|
|
2
6
|
import { Devices } from '../settings.js';
|
|
7
|
+
import { irdeviceBase } from './irdevice.js';
|
|
3
8
|
/**
|
|
4
9
|
* Platform Accessory
|
|
5
10
|
* An instance of this class is created for each accessory your platform registers
|
|
6
11
|
* Each accessory may expose multiple services of different service types.
|
|
7
12
|
*/
|
|
8
|
-
export class Light {
|
|
13
|
+
export class Light extends irdeviceBase {
|
|
9
14
|
platform;
|
|
10
|
-
accessory;
|
|
11
|
-
device;
|
|
12
|
-
api;
|
|
13
|
-
log;
|
|
14
|
-
config;
|
|
15
|
-
hap;
|
|
16
15
|
// Services
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// Characteristic Values
|
|
21
|
-
On;
|
|
22
|
-
ProgrammableSwitchEventOn;
|
|
23
|
-
ProgrammableSwitchOutputStateOn;
|
|
24
|
-
ProgrammableSwitchEventOff;
|
|
25
|
-
ProgrammableSwitchOutputStateOff;
|
|
26
|
-
FirmwareRevision;
|
|
27
|
-
// Config
|
|
28
|
-
deviceLogging;
|
|
29
|
-
disablePushOn;
|
|
30
|
-
disablePushOff;
|
|
16
|
+
LightBulb;
|
|
17
|
+
ProgrammableSwitchOn;
|
|
18
|
+
ProgrammableSwitchOff;
|
|
31
19
|
constructor(platform, accessory, device) {
|
|
20
|
+
super(platform, accessory, device);
|
|
32
21
|
this.platform = platform;
|
|
33
|
-
this.accessory = accessory;
|
|
34
|
-
this.device = device;
|
|
35
|
-
this.api = this.platform.api;
|
|
36
|
-
this.log = this.platform.log;
|
|
37
|
-
this.config = this.platform.config;
|
|
38
|
-
this.hap = this.api.hap;
|
|
39
|
-
// default placeholders
|
|
40
|
-
this.deviceLogs(device);
|
|
41
|
-
this.deviceContext();
|
|
42
|
-
this.disablePushOnChanges(device);
|
|
43
|
-
this.disablePushOffChanges(device);
|
|
44
|
-
this.deviceConfig(device);
|
|
45
|
-
// set accessory information
|
|
46
|
-
accessory
|
|
47
|
-
.getService(this.hap.Service.AccessoryInformation)
|
|
48
|
-
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
49
|
-
.setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
|
|
50
|
-
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
51
|
-
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
52
22
|
if (!device.irlight?.stateless) {
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
23
|
+
// Initialize LightBulb Service
|
|
24
|
+
accessory.context.LightBulb = accessory.context.LightBulb ?? {};
|
|
25
|
+
this.LightBulb = {
|
|
26
|
+
Name: accessory.context.LightBulb.Name ?? `${accessory.displayName} ${device.remoteType}`,
|
|
27
|
+
Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb),
|
|
28
|
+
On: accessory.context.On || false,
|
|
29
|
+
};
|
|
30
|
+
accessory.context.LightBulb = this.LightBulb;
|
|
31
|
+
this.LightBulb.Service
|
|
32
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
|
|
33
|
+
.getCharacteristic(this.hap.Characteristic.On)
|
|
34
|
+
.onGet(() => {
|
|
35
|
+
return this.LightBulb.On;
|
|
36
|
+
})
|
|
37
|
+
.onSet(this.OnSet.bind(this));
|
|
64
38
|
}
|
|
65
39
|
else {
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
40
|
+
// Initialize ProgrammableSwitchOn Service
|
|
41
|
+
accessory.context.ProgrammableSwitchOn = accessory.context.ProgrammableSwitchOn ?? {};
|
|
42
|
+
this.ProgrammableSwitchOn = {
|
|
43
|
+
Name: accessory.context.ProgrammableSwitchOn.Name ?? `${accessory.displayName} ${device.remoteType} On`,
|
|
44
|
+
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
45
|
+
?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch),
|
|
46
|
+
ProgrammableSwitchEvent: accessory.context.ProgrammableSwitchEvent ?? this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
|
|
47
|
+
ProgrammableSwitchOutputState: accessory.context.ProgrammableSwitchOutputState ?? 0,
|
|
48
|
+
};
|
|
49
|
+
accessory.context.ProgrammableSwitchOn = this.ProgrammableSwitchOn;
|
|
50
|
+
// Initialize ProgrammableSwitchOn Characteristics
|
|
51
|
+
this.ProgrammableSwitchOn?.Service
|
|
52
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.ProgrammableSwitchOn.Name)
|
|
53
|
+
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
|
|
75
54
|
validValueRanges: [0, 0],
|
|
76
55
|
minValue: 0,
|
|
77
56
|
maxValue: 0,
|
|
78
57
|
validValues: [0],
|
|
79
58
|
})
|
|
80
59
|
.onGet(() => {
|
|
81
|
-
return this.
|
|
60
|
+
return this.ProgrammableSwitchOn.ProgrammableSwitchEvent;
|
|
82
61
|
});
|
|
83
|
-
this.
|
|
62
|
+
this.ProgrammableSwitchOn?.Service
|
|
63
|
+
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
64
|
+
.onGet(() => {
|
|
65
|
+
return this.ProgrammableSwitchOn.ProgrammableSwitchOutputState;
|
|
66
|
+
})
|
|
84
67
|
.onSet(this.ProgrammableSwitchOutputStateSetOn.bind(this));
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
68
|
+
// Initialize ProgrammableSwitchOff Service
|
|
69
|
+
accessory.context.ProgrammableSwitchOff = accessory.context.ProgrammableSwitchOff ?? {};
|
|
70
|
+
this.ProgrammableSwitchOff = {
|
|
71
|
+
Name: accessory.context.ProgrammableSwitchOff.Name ?? `${accessory.displayName} ${device.remoteType} Off`,
|
|
72
|
+
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
73
|
+
?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch),
|
|
74
|
+
ProgrammableSwitchEvent: accessory.context.ProgrammableSwitchEvent ?? this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
|
|
75
|
+
ProgrammableSwitchOutputState: accessory.context.ProgrammableSwitchOutputState ?? 0,
|
|
76
|
+
};
|
|
77
|
+
accessory.context.ProgrammableSwitchOff = this.ProgrammableSwitchOff;
|
|
78
|
+
// Initialize ProgrammableSwitchOff Characteristics
|
|
79
|
+
this.ProgrammableSwitchOff?.Service
|
|
80
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.ProgrammableSwitchOff.Name)
|
|
81
|
+
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
|
|
94
82
|
validValueRanges: [0, 0],
|
|
95
83
|
minValue: 0,
|
|
96
84
|
maxValue: 0,
|
|
97
85
|
validValues: [0],
|
|
98
86
|
})
|
|
99
87
|
.onGet(() => {
|
|
100
|
-
return this.
|
|
88
|
+
return this.ProgrammableSwitchOff.ProgrammableSwitchEvent;
|
|
101
89
|
});
|
|
102
|
-
this.
|
|
90
|
+
this.ProgrammableSwitchOff?.Service
|
|
91
|
+
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
92
|
+
.onGet(() => {
|
|
93
|
+
return this.ProgrammableSwitchOff.ProgrammableSwitchOutputState;
|
|
94
|
+
})
|
|
103
95
|
.onSet(this.ProgrammableSwitchOutputStateSetOff.bind(this));
|
|
104
96
|
}
|
|
105
97
|
}
|
|
106
98
|
async OnSet(value) {
|
|
107
99
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
108
|
-
this.On = value;
|
|
109
|
-
if (this.On) {
|
|
110
|
-
|
|
100
|
+
this.LightBulb.On = value;
|
|
101
|
+
if (this.LightBulb?.On) {
|
|
102
|
+
const On = true;
|
|
103
|
+
await this.pushLightOnChanges(On);
|
|
111
104
|
}
|
|
112
105
|
else {
|
|
113
|
-
|
|
106
|
+
const On = false;
|
|
107
|
+
await this.pushLightOffChanges(On);
|
|
114
108
|
}
|
|
115
109
|
/**
|
|
116
110
|
* pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
@@ -119,10 +113,10 @@ export class Light {
|
|
|
119
113
|
}
|
|
120
114
|
async ProgrammableSwitchOutputStateSetOn(value) {
|
|
121
115
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
122
|
-
this.
|
|
123
|
-
if (this.
|
|
124
|
-
|
|
125
|
-
await this.pushLightOnChanges();
|
|
116
|
+
this.ProgrammableSwitchOn.ProgrammableSwitchOutputState = value;
|
|
117
|
+
if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === 1) {
|
|
118
|
+
const On = true;
|
|
119
|
+
await this.pushLightOnChanges(On);
|
|
126
120
|
}
|
|
127
121
|
/**
|
|
128
122
|
* pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
@@ -131,10 +125,10 @@ export class Light {
|
|
|
131
125
|
}
|
|
132
126
|
async ProgrammableSwitchOutputStateSetOff(value) {
|
|
133
127
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
134
|
-
this.
|
|
135
|
-
if (this.
|
|
136
|
-
|
|
137
|
-
await this.pushLightOffChanges();
|
|
128
|
+
this.ProgrammableSwitchOff.ProgrammableSwitchOutputState = value;
|
|
129
|
+
if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === 1) {
|
|
130
|
+
const On = false;
|
|
131
|
+
await this.pushLightOffChanges(On);
|
|
138
132
|
}
|
|
139
133
|
/**
|
|
140
134
|
* pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
@@ -151,9 +145,9 @@ export class Light {
|
|
|
151
145
|
* Light - "command" "channelAdd" "default" = next channel
|
|
152
146
|
* Light - "command" "channelSub" "default" = previous channel
|
|
153
147
|
*/
|
|
154
|
-
async pushLightOnChanges() {
|
|
155
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOnChanges On: ${
|
|
156
|
-
if (
|
|
148
|
+
async pushLightOnChanges(On) {
|
|
149
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOnChanges On: ${On}, disablePushOn: ${this.disablePushOn}`);
|
|
150
|
+
if (On === true && this.disablePushOn === false) {
|
|
157
151
|
const commandType = await this.commandType();
|
|
158
152
|
const command = await this.commandOn();
|
|
159
153
|
const bodyChange = JSON.stringify({
|
|
@@ -161,12 +155,12 @@ export class Light {
|
|
|
161
155
|
parameter: 'default',
|
|
162
156
|
commandType: commandType,
|
|
163
157
|
});
|
|
164
|
-
await this.pushChanges(bodyChange);
|
|
158
|
+
await this.pushChanges(bodyChange, On);
|
|
165
159
|
}
|
|
166
160
|
}
|
|
167
|
-
async pushLightOffChanges() {
|
|
168
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges On: ${
|
|
169
|
-
if (
|
|
161
|
+
async pushLightOffChanges(On) {
|
|
162
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges On: ${On}, disablePushOff: ${this.disablePushOff}`);
|
|
163
|
+
if (On === false && this.disablePushOff === false) {
|
|
170
164
|
const commandType = await this.commandType();
|
|
171
165
|
const command = await this.commandOff();
|
|
172
166
|
const bodyChange = JSON.stringify({
|
|
@@ -174,27 +168,10 @@ export class Light {
|
|
|
174
168
|
parameter: 'default',
|
|
175
169
|
commandType: commandType,
|
|
176
170
|
});
|
|
177
|
-
await this.pushChanges(bodyChange);
|
|
171
|
+
await this.pushChanges(bodyChange, On);
|
|
178
172
|
}
|
|
179
173
|
}
|
|
180
|
-
|
|
181
|
-
const bodyChange = JSON.stringify({
|
|
182
|
-
command: 'brightnessUp',
|
|
183
|
-
parameter: 'default',
|
|
184
|
-
commandType: 'command',
|
|
185
|
-
});
|
|
186
|
-
await this.pushChanges(bodyChange);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
async pushLightBrightnessDownChanges(): Promise<void> {
|
|
190
|
-
const bodyChange = JSON.stringify({
|
|
191
|
-
command: 'brightnessDown',
|
|
192
|
-
parameter: 'default',
|
|
193
|
-
commandType: 'command',
|
|
194
|
-
});
|
|
195
|
-
await this.pushChanges(bodyChange);
|
|
196
|
-
}*/
|
|
197
|
-
async pushChanges(bodyChange) {
|
|
174
|
+
async pushChanges(bodyChange, On) {
|
|
198
175
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
199
176
|
if (this.device.connectionType === 'OpenAPI') {
|
|
200
177
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
@@ -209,9 +186,11 @@ export class Light {
|
|
|
209
186
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
210
187
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
211
188
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
212
|
-
this.
|
|
189
|
+
this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
|
|
213
190
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
214
|
-
this.
|
|
191
|
+
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
192
|
+
+ ` request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
193
|
+
this.accessory.context.On = On;
|
|
215
194
|
this.updateHomeKitCharacteristics();
|
|
216
195
|
}
|
|
217
196
|
else {
|
|
@@ -221,285 +200,62 @@ export class Light {
|
|
|
221
200
|
}
|
|
222
201
|
catch (e) {
|
|
223
202
|
this.apiError(e);
|
|
224
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
|
|
225
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
203
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
|
|
204
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
226
205
|
}
|
|
227
206
|
}
|
|
228
207
|
else {
|
|
229
|
-
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
230
|
-
|
|
208
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Connection Type: `
|
|
209
|
+
+ `${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
231
210
|
}
|
|
232
211
|
}
|
|
233
212
|
async updateHomeKitCharacteristics() {
|
|
234
|
-
if (this.device.irlight?.stateless) {
|
|
213
|
+
if (!this.device.irlight?.stateless) {
|
|
235
214
|
// On
|
|
236
|
-
if (this.On === undefined) {
|
|
237
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
215
|
+
if (this.LightBulb?.On === undefined) {
|
|
216
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.LightBulb?.On}`);
|
|
238
217
|
}
|
|
239
218
|
else {
|
|
240
|
-
this.accessory.context.On = this.On;
|
|
241
|
-
this.
|
|
242
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
219
|
+
this.accessory.context.On = this.LightBulb.On;
|
|
220
|
+
this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
|
|
221
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
|
|
243
222
|
}
|
|
244
223
|
}
|
|
245
224
|
else {
|
|
246
225
|
// On Stateful Programmable Switch
|
|
247
|
-
if (this.
|
|
226
|
+
if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === undefined) {
|
|
248
227
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
249
|
-
+ ` ProgrammableSwitchOutputStateOn: ${this.
|
|
228
|
+
+ ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState}`);
|
|
250
229
|
}
|
|
251
230
|
else {
|
|
252
|
-
this.accessory.context.ProgrammableSwitchOutputStateOn = this.
|
|
253
|
-
this.
|
|
231
|
+
this.accessory.context.ProgrammableSwitchOutputStateOn = this.ProgrammableSwitchOn.ProgrammableSwitchOutputState;
|
|
232
|
+
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, this.ProgrammableSwitchOn.ProgrammableSwitchOutputState);
|
|
254
233
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
255
|
-
+ ` ProgrammableSwitchOutputStateOn: ${this.
|
|
234
|
+
+ ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn.ProgrammableSwitchOutputState}`);
|
|
256
235
|
}
|
|
257
236
|
// Off Stateful Programmable Switch
|
|
258
|
-
if (this.
|
|
237
|
+
if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === undefined) {
|
|
259
238
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
260
|
-
+ ` ProgrammableSwitchOutputStateOff: ${this.
|
|
239
|
+
+ ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
|
|
261
240
|
}
|
|
262
241
|
else {
|
|
263
|
-
this.accessory.context.ProgrammableSwitchOutputStateOff = this.
|
|
264
|
-
this.
|
|
242
|
+
this.accessory.context.ProgrammableSwitchOutputStateOff = this.ProgrammableSwitchOff.ProgrammableSwitchOutputState;
|
|
243
|
+
this.ProgrammableSwitchOff.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, this.ProgrammableSwitchOff.ProgrammableSwitchOutputState);
|
|
265
244
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
266
|
-
+ ` ProgrammableSwitchOutputStateOff: ${this.
|
|
245
|
+
+ ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
|
|
267
246
|
}
|
|
268
247
|
}
|
|
269
248
|
}
|
|
270
|
-
async disablePushOnChanges(device) {
|
|
271
|
-
if (device.disablePushOn === undefined) {
|
|
272
|
-
this.disablePushOn = false;
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
this.disablePushOn = device.disablePushOn;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
async disablePushOffChanges(device) {
|
|
279
|
-
if (device.disablePushOff === undefined) {
|
|
280
|
-
this.disablePushOff = false;
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
this.disablePushOff = device.disablePushOff;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
async commandType() {
|
|
287
|
-
let commandType;
|
|
288
|
-
if (this.device.customize) {
|
|
289
|
-
commandType = 'customize';
|
|
290
|
-
}
|
|
291
|
-
else {
|
|
292
|
-
commandType = 'command';
|
|
293
|
-
}
|
|
294
|
-
return commandType;
|
|
295
|
-
}
|
|
296
|
-
async commandOn() {
|
|
297
|
-
let command;
|
|
298
|
-
if (this.device.customize && this.device.customOn) {
|
|
299
|
-
command = this.device.customOn;
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
command = 'turnOn';
|
|
303
|
-
}
|
|
304
|
-
return command;
|
|
305
|
-
}
|
|
306
|
-
async commandOff() {
|
|
307
|
-
let command;
|
|
308
|
-
if (this.device.customize && this.device.customOff) {
|
|
309
|
-
command = this.device.customOff;
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
command = 'turnOff';
|
|
313
|
-
}
|
|
314
|
-
return command;
|
|
315
|
-
}
|
|
316
|
-
async statusCode(statusCode) {
|
|
317
|
-
switch (statusCode) {
|
|
318
|
-
case 151:
|
|
319
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
320
|
-
break;
|
|
321
|
-
case 152:
|
|
322
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
323
|
-
break;
|
|
324
|
-
case 160:
|
|
325
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
326
|
-
break;
|
|
327
|
-
case 161:
|
|
328
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
329
|
-
break;
|
|
330
|
-
case 171:
|
|
331
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
332
|
-
`Hub: ${this.device.hubDeviceId}`);
|
|
333
|
-
break;
|
|
334
|
-
case 190:
|
|
335
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
336
|
-
` Or command format is invalid, statusCode: ${statusCode}`);
|
|
337
|
-
break;
|
|
338
|
-
case 100:
|
|
339
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
340
|
-
break;
|
|
341
|
-
case 200:
|
|
342
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
343
|
-
break;
|
|
344
|
-
case 400:
|
|
345
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
346
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
347
|
-
break;
|
|
348
|
-
case 401:
|
|
349
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
350
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
351
|
-
break;
|
|
352
|
-
case 403:
|
|
353
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
354
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
355
|
-
break;
|
|
356
|
-
case 404:
|
|
357
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
358
|
-
+ `statusCode: ${statusCode}`);
|
|
359
|
-
break;
|
|
360
|
-
case 406:
|
|
361
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
362
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
363
|
-
break;
|
|
364
|
-
case 415:
|
|
365
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
366
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
367
|
-
break;
|
|
368
|
-
case 422:
|
|
369
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
|
|
370
|
-
+ `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
371
|
-
break;
|
|
372
|
-
case 429:
|
|
373
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
374
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
375
|
-
break;
|
|
376
|
-
case 500:
|
|
377
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
378
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
379
|
-
break;
|
|
380
|
-
default:
|
|
381
|
-
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
382
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
249
|
async apiError(e) {
|
|
386
|
-
if (this.device.irlight?.stateless) {
|
|
387
|
-
this.
|
|
250
|
+
if (!this.device.irlight?.stateless) {
|
|
251
|
+
this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
388
252
|
}
|
|
389
253
|
else {
|
|
390
|
-
this.
|
|
391
|
-
this.
|
|
392
|
-
this.
|
|
393
|
-
this.
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
async deviceContext() {
|
|
397
|
-
if (this.On === undefined) {
|
|
398
|
-
this.On = false;
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
this.On = this.accessory.context.On;
|
|
402
|
-
}
|
|
403
|
-
if (this.FirmwareRevision === undefined) {
|
|
404
|
-
this.FirmwareRevision = this.platform.version;
|
|
405
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
254
|
+
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
255
|
+
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
256
|
+
this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
257
|
+
this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
406
258
|
}
|
|
407
259
|
}
|
|
408
|
-
async deviceConfig(device) {
|
|
409
|
-
let config = {};
|
|
410
|
-
if (device.irlight) {
|
|
411
|
-
config = device.irlight;
|
|
412
|
-
}
|
|
413
|
-
if (device.logging !== undefined) {
|
|
414
|
-
config['logging'] = device.logging;
|
|
415
|
-
}
|
|
416
|
-
if (device.connectionType !== undefined) {
|
|
417
|
-
config['connectionType'] = device.connectionType;
|
|
418
|
-
}
|
|
419
|
-
if (device.external !== undefined) {
|
|
420
|
-
config['external'] = device.external;
|
|
421
|
-
}
|
|
422
|
-
if (device.customOn !== undefined) {
|
|
423
|
-
config['customOn'] = device.customOn;
|
|
424
|
-
}
|
|
425
|
-
if (device.customOff !== undefined) {
|
|
426
|
-
config['customOff'] = device.customOff;
|
|
427
|
-
}
|
|
428
|
-
if (device.customize !== undefined) {
|
|
429
|
-
config['customize'] = device.customize;
|
|
430
|
-
}
|
|
431
|
-
if (device.disablePushOn !== undefined) {
|
|
432
|
-
config['disablePushOn'] = device.disablePushOn;
|
|
433
|
-
}
|
|
434
|
-
if (device.disablePushOff !== undefined) {
|
|
435
|
-
config['disablePushOff'] = device.disablePushOff;
|
|
436
|
-
}
|
|
437
|
-
if (Object.entries(config).length !== 0) {
|
|
438
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
async deviceLogs(device) {
|
|
442
|
-
if (this.platform.debugMode) {
|
|
443
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
444
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
445
|
-
}
|
|
446
|
-
else if (device.logging) {
|
|
447
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
448
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
449
|
-
}
|
|
450
|
-
else if (this.platform.config.options?.logging) {
|
|
451
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
452
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
453
|
-
}
|
|
454
|
-
else {
|
|
455
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
456
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Logging for Device
|
|
461
|
-
*/
|
|
462
|
-
infoLog(...log) {
|
|
463
|
-
if (this.enablingDeviceLogging()) {
|
|
464
|
-
this.platform.log.info(String(...log));
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
warnLog(...log) {
|
|
468
|
-
if (this.enablingDeviceLogging()) {
|
|
469
|
-
this.platform.log.warn(String(...log));
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
debugWarnLog(...log) {
|
|
473
|
-
if (this.enablingDeviceLogging()) {
|
|
474
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
475
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
errorLog(...log) {
|
|
480
|
-
if (this.enablingDeviceLogging()) {
|
|
481
|
-
this.platform.log.error(String(...log));
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
debugErrorLog(...log) {
|
|
485
|
-
if (this.enablingDeviceLogging()) {
|
|
486
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
487
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
debugLog(...log) {
|
|
492
|
-
if (this.enablingDeviceLogging()) {
|
|
493
|
-
if (this.deviceLogging === 'debug') {
|
|
494
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
495
|
-
}
|
|
496
|
-
else {
|
|
497
|
-
this.platform.log.debug(String(...log));
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
enablingDeviceLogging() {
|
|
502
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
503
|
-
}
|
|
504
260
|
}
|
|
505
261
|
//# sourceMappingURL=light.js.map
|