@switchbot/homebridge-switchbot 3.5.0-beta.9 → 3.5.1-beta.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 +164 -22
- package/dist/device/blindtilt.d.ts +21 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +457 -866
- 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 +851 -913
- 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 +316 -742
- 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 +380 -833
- 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 +267 -602
- 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 +469 -897
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +76 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +846 -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 +645 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +19 -58
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +304 -640
- 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 +300 -710
- 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 +225 -643
- 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 +371 -742
- 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 +309 -642
- 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 +223 -638
- 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 +216 -644
- 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 +209 -588
- 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 +141 -532
- 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 +252 -609
- 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 +179 -521
- 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 +337 -482
- 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 +108 -333
- 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 +47 -299
- 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 +95 -364
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +46 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +393 -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 +121 -376
- 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 +441 -584
- 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 +94 -353
- 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 +48 -299
- 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 +50 -305
- 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 +66 -18
- 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 +95 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +657 -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 +488 -937
- package/src/device/bot.ts +907 -1016
- package/src/device/ceilinglight.ts +330 -798
- package/src/device/colorbulb.ts +394 -904
- package/src/device/contact.ts +298 -637
- package/src/device/curtain.ts +496 -954
- package/src/device/device.ts +872 -0
- package/src/device/fan.ts +692 -0
- package/src/device/hub.ts +338 -671
- package/src/device/humidifier.ts +330 -777
- package/src/device/iosensor.ts +258 -671
- package/src/device/lightstrip.ts +394 -809
- package/src/device/lock.ts +345 -700
- package/src/device/meter.ts +256 -666
- package/src/device/meterplus.ts +248 -672
- package/src/device/motion.ts +234 -622
- package/src/device/plug.ts +152 -572
- package/src/device/robotvacuumcleaner.ts +273 -653
- package/src/device/waterdetector.ts +198 -549
- 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 +368 -540
- package/src/irdevice/airpurifier.ts +134 -369
- package/src/irdevice/camera.ts +60 -324
- package/src/irdevice/fan.ts +111 -392
- package/src/irdevice/irdevice.ts +406 -0
- package/src/irdevice/light.ts +159 -425
- package/src/irdevice/other.ts +509 -661
- package/src/irdevice/tv.ts +123 -388
- package/src/irdevice/vacuumcleaner.ts +61 -324
- package/src/irdevice/waterheater.ts +63 -333
- package/src/platform.ts +395 -259
- package/src/settings.ts +120 -610
- package/src/utils.ts +661 -1
- package/src/device/waterdetector.json +0 -11
package/dist/irdevice/light.js
CHANGED
|
@@ -1,116 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* light.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
5
|
+
import { irdeviceBase } from './irdevice.js';
|
|
3
6
|
/**
|
|
4
7
|
* Platform Accessory
|
|
5
8
|
* An instance of this class is created for each accessory your platform registers
|
|
6
9
|
* Each accessory may expose multiple services of different service types.
|
|
7
10
|
*/
|
|
8
|
-
export class Light {
|
|
11
|
+
export class Light extends irdeviceBase {
|
|
9
12
|
platform;
|
|
10
|
-
accessory;
|
|
11
|
-
device;
|
|
12
|
-
api;
|
|
13
|
-
log;
|
|
14
|
-
config;
|
|
15
|
-
hap;
|
|
16
13
|
// 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;
|
|
14
|
+
LightBulb;
|
|
15
|
+
ProgrammableSwitchOn;
|
|
16
|
+
ProgrammableSwitchOff;
|
|
31
17
|
constructor(platform, accessory, device) {
|
|
18
|
+
super(platform, accessory, device);
|
|
32
19
|
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
20
|
if (!device.irlight?.stateless) {
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
21
|
+
// Initialize LightBulb Service
|
|
22
|
+
accessory.context.LightBulb = accessory.context.LightBulb ?? {};
|
|
23
|
+
this.LightBulb = {
|
|
24
|
+
Name: accessory.context.LightBulb.Name ?? `${accessory.displayName} ${device.remoteType}`,
|
|
25
|
+
Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb),
|
|
26
|
+
On: accessory.context.On || false,
|
|
27
|
+
};
|
|
28
|
+
accessory.context.LightBulb = this.LightBulb;
|
|
29
|
+
this.LightBulb.Service
|
|
30
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
|
|
31
|
+
.getCharacteristic(this.hap.Characteristic.On)
|
|
32
|
+
.onGet(() => {
|
|
33
|
+
return this.LightBulb.On;
|
|
34
|
+
})
|
|
35
|
+
.onSet(this.OnSet.bind(this));
|
|
64
36
|
}
|
|
65
37
|
else {
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
38
|
+
// Initialize ProgrammableSwitchOn Service
|
|
39
|
+
accessory.context.ProgrammableSwitchOn = accessory.context.ProgrammableSwitchOn ?? {};
|
|
40
|
+
this.ProgrammableSwitchOn = {
|
|
41
|
+
Name: accessory.context.ProgrammableSwitchOn.Name ?? `${accessory.displayName} ${device.remoteType} On`,
|
|
42
|
+
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
43
|
+
?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch),
|
|
44
|
+
ProgrammableSwitchEvent: accessory.context.ProgrammableSwitchEvent ?? this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
|
|
45
|
+
ProgrammableSwitchOutputState: accessory.context.ProgrammableSwitchOutputState ?? 0,
|
|
46
|
+
};
|
|
47
|
+
accessory.context.ProgrammableSwitchOn = this.ProgrammableSwitchOn;
|
|
48
|
+
// Initialize ProgrammableSwitchOn Characteristics
|
|
49
|
+
this.ProgrammableSwitchOn?.Service
|
|
50
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.ProgrammableSwitchOn.Name)
|
|
51
|
+
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
|
|
75
52
|
validValueRanges: [0, 0],
|
|
76
53
|
minValue: 0,
|
|
77
54
|
maxValue: 0,
|
|
78
55
|
validValues: [0],
|
|
79
56
|
})
|
|
80
57
|
.onGet(() => {
|
|
81
|
-
return this.
|
|
58
|
+
return this.ProgrammableSwitchOn.ProgrammableSwitchEvent;
|
|
82
59
|
});
|
|
83
|
-
this.
|
|
60
|
+
this.ProgrammableSwitchOn?.Service
|
|
61
|
+
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
62
|
+
.onGet(() => {
|
|
63
|
+
return this.ProgrammableSwitchOn.ProgrammableSwitchOutputState;
|
|
64
|
+
})
|
|
84
65
|
.onSet(this.ProgrammableSwitchOutputStateSetOn.bind(this));
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
66
|
+
// Initialize ProgrammableSwitchOff Service
|
|
67
|
+
accessory.context.ProgrammableSwitchOff = accessory.context.ProgrammableSwitchOff ?? {};
|
|
68
|
+
this.ProgrammableSwitchOff = {
|
|
69
|
+
Name: accessory.context.ProgrammableSwitchOff.Name ?? `${accessory.displayName} ${device.remoteType} Off`,
|
|
70
|
+
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
71
|
+
?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch),
|
|
72
|
+
ProgrammableSwitchEvent: accessory.context.ProgrammableSwitchEvent ?? this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
|
|
73
|
+
ProgrammableSwitchOutputState: accessory.context.ProgrammableSwitchOutputState ?? 0,
|
|
74
|
+
};
|
|
75
|
+
accessory.context.ProgrammableSwitchOff = this.ProgrammableSwitchOff;
|
|
76
|
+
// Initialize ProgrammableSwitchOff Characteristics
|
|
77
|
+
this.ProgrammableSwitchOff?.Service
|
|
78
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.ProgrammableSwitchOff.Name)
|
|
79
|
+
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
|
|
94
80
|
validValueRanges: [0, 0],
|
|
95
81
|
minValue: 0,
|
|
96
82
|
maxValue: 0,
|
|
97
83
|
validValues: [0],
|
|
98
84
|
})
|
|
99
85
|
.onGet(() => {
|
|
100
|
-
return this.
|
|
86
|
+
return this.ProgrammableSwitchOff.ProgrammableSwitchEvent;
|
|
101
87
|
});
|
|
102
|
-
this.
|
|
88
|
+
this.ProgrammableSwitchOff?.Service
|
|
89
|
+
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
90
|
+
.onGet(() => {
|
|
91
|
+
return this.ProgrammableSwitchOff.ProgrammableSwitchOutputState;
|
|
92
|
+
})
|
|
103
93
|
.onSet(this.ProgrammableSwitchOutputStateSetOff.bind(this));
|
|
104
94
|
}
|
|
105
95
|
}
|
|
106
96
|
async OnSet(value) {
|
|
107
97
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
108
|
-
this.On = value;
|
|
109
|
-
if (this.On) {
|
|
110
|
-
|
|
98
|
+
this.LightBulb.On = value;
|
|
99
|
+
if (this.LightBulb?.On) {
|
|
100
|
+
const On = true;
|
|
101
|
+
await this.pushLightOnChanges(On);
|
|
111
102
|
}
|
|
112
103
|
else {
|
|
113
|
-
|
|
104
|
+
const On = false;
|
|
105
|
+
await this.pushLightOffChanges(On);
|
|
114
106
|
}
|
|
115
107
|
/**
|
|
116
108
|
* pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
@@ -119,10 +111,10 @@ export class Light {
|
|
|
119
111
|
}
|
|
120
112
|
async ProgrammableSwitchOutputStateSetOn(value) {
|
|
121
113
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
122
|
-
this.
|
|
123
|
-
if (this.
|
|
124
|
-
|
|
125
|
-
await this.pushLightOnChanges();
|
|
114
|
+
this.ProgrammableSwitchOn.ProgrammableSwitchOutputState = value;
|
|
115
|
+
if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === 1) {
|
|
116
|
+
const On = true;
|
|
117
|
+
await this.pushLightOnChanges(On);
|
|
126
118
|
}
|
|
127
119
|
/**
|
|
128
120
|
* pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
@@ -131,10 +123,10 @@ export class Light {
|
|
|
131
123
|
}
|
|
132
124
|
async ProgrammableSwitchOutputStateSetOff(value) {
|
|
133
125
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
134
|
-
this.
|
|
135
|
-
if (this.
|
|
136
|
-
|
|
137
|
-
await this.pushLightOffChanges();
|
|
126
|
+
this.ProgrammableSwitchOff.ProgrammableSwitchOutputState = value;
|
|
127
|
+
if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === 1) {
|
|
128
|
+
const On = false;
|
|
129
|
+
await this.pushLightOffChanges(On);
|
|
138
130
|
}
|
|
139
131
|
/**
|
|
140
132
|
* pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
@@ -151,9 +143,9 @@ export class Light {
|
|
|
151
143
|
* Light - "command" "channelAdd" "default" = next channel
|
|
152
144
|
* Light - "command" "channelSub" "default" = previous channel
|
|
153
145
|
*/
|
|
154
|
-
async pushLightOnChanges() {
|
|
155
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOnChanges On: ${
|
|
156
|
-
if (
|
|
146
|
+
async pushLightOnChanges(On) {
|
|
147
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOnChanges On: ${On}, disablePushOn: ${this.disablePushOn}`);
|
|
148
|
+
if (On === true && this.disablePushOn === false) {
|
|
157
149
|
const commandType = await this.commandType();
|
|
158
150
|
const command = await this.commandOn();
|
|
159
151
|
const bodyChange = JSON.stringify({
|
|
@@ -161,12 +153,12 @@ export class Light {
|
|
|
161
153
|
parameter: 'default',
|
|
162
154
|
commandType: commandType,
|
|
163
155
|
});
|
|
164
|
-
await this.pushChanges(bodyChange);
|
|
156
|
+
await this.pushChanges(bodyChange, On);
|
|
165
157
|
}
|
|
166
158
|
}
|
|
167
|
-
async pushLightOffChanges() {
|
|
168
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges On: ${
|
|
169
|
-
if (
|
|
159
|
+
async pushLightOffChanges(On) {
|
|
160
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges On: ${On}, disablePushOff: ${this.disablePushOff}`);
|
|
161
|
+
if (On === false && this.disablePushOff === false) {
|
|
170
162
|
const commandType = await this.commandType();
|
|
171
163
|
const command = await this.commandOff();
|
|
172
164
|
const bodyChange = JSON.stringify({
|
|
@@ -174,332 +166,85 @@ export class Light {
|
|
|
174
166
|
parameter: 'default',
|
|
175
167
|
commandType: commandType,
|
|
176
168
|
});
|
|
177
|
-
await this.pushChanges(bodyChange);
|
|
169
|
+
await this.pushChanges(bodyChange, On);
|
|
178
170
|
}
|
|
179
171
|
}
|
|
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) {
|
|
172
|
+
async pushChanges(bodyChange, On) {
|
|
198
173
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
199
174
|
if (this.device.connectionType === 'OpenAPI') {
|
|
200
175
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
201
176
|
try {
|
|
202
|
-
const { body, statusCode } = await
|
|
203
|
-
body: bodyChange,
|
|
204
|
-
method: 'POST',
|
|
205
|
-
headers: this.platform.generateHeaders(),
|
|
206
|
-
});
|
|
207
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
177
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
208
178
|
const deviceStatus = await body.json();
|
|
209
|
-
this.
|
|
210
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
179
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
211
180
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
212
|
-
this.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
this.updateHomeKitCharacteristics();
|
|
181
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
182
|
+
this.accessory.context.On = On;
|
|
183
|
+
await this.updateHomeKitCharacteristics();
|
|
216
184
|
}
|
|
217
185
|
else {
|
|
218
|
-
this.statusCode(statusCode);
|
|
219
|
-
this.statusCode(deviceStatus.statusCode);
|
|
186
|
+
await this.statusCode(statusCode);
|
|
187
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
220
188
|
}
|
|
221
189
|
}
|
|
222
190
|
catch (e) {
|
|
223
191
|
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)}`);
|
|
192
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
|
|
193
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
226
194
|
}
|
|
227
195
|
}
|
|
228
196
|
else {
|
|
229
|
-
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
230
|
-
|
|
197
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Connection Type: `
|
|
198
|
+
+ `${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
231
199
|
}
|
|
232
200
|
}
|
|
233
201
|
async updateHomeKitCharacteristics() {
|
|
234
|
-
if (this.device.irlight?.stateless) {
|
|
202
|
+
if (!this.device.irlight?.stateless) {
|
|
235
203
|
// On
|
|
236
|
-
if (this.On === undefined) {
|
|
237
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
204
|
+
if (this.LightBulb?.On === undefined) {
|
|
205
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.LightBulb?.On}`);
|
|
238
206
|
}
|
|
239
207
|
else {
|
|
240
|
-
this.accessory.context.On = this.On;
|
|
241
|
-
this.
|
|
242
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
208
|
+
this.accessory.context.On = this.LightBulb.On;
|
|
209
|
+
this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
|
|
210
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
|
|
243
211
|
}
|
|
244
212
|
}
|
|
245
213
|
else {
|
|
246
214
|
// On Stateful Programmable Switch
|
|
247
|
-
if (this.
|
|
215
|
+
if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === undefined) {
|
|
248
216
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
249
|
-
+ ` ProgrammableSwitchOutputStateOn: ${this.
|
|
217
|
+
+ ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState}`);
|
|
250
218
|
}
|
|
251
219
|
else {
|
|
252
|
-
this.accessory.context.ProgrammableSwitchOutputStateOn = this.
|
|
253
|
-
this.
|
|
220
|
+
this.accessory.context.ProgrammableSwitchOutputStateOn = this.ProgrammableSwitchOn.ProgrammableSwitchOutputState;
|
|
221
|
+
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, this.ProgrammableSwitchOn.ProgrammableSwitchOutputState);
|
|
254
222
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
255
|
-
+ ` ProgrammableSwitchOutputStateOn: ${this.
|
|
223
|
+
+ ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn.ProgrammableSwitchOutputState}`);
|
|
256
224
|
}
|
|
257
225
|
// Off Stateful Programmable Switch
|
|
258
|
-
if (this.
|
|
226
|
+
if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === undefined) {
|
|
259
227
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
260
|
-
+ ` ProgrammableSwitchOutputStateOff: ${this.
|
|
228
|
+
+ ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
|
|
261
229
|
}
|
|
262
230
|
else {
|
|
263
|
-
this.accessory.context.ProgrammableSwitchOutputStateOff = this.
|
|
264
|
-
this.
|
|
231
|
+
this.accessory.context.ProgrammableSwitchOutputStateOff = this.ProgrammableSwitchOff.ProgrammableSwitchOutputState;
|
|
232
|
+
this.ProgrammableSwitchOff.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, this.ProgrammableSwitchOff.ProgrammableSwitchOutputState);
|
|
265
233
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
266
|
-
+ ` ProgrammableSwitchOutputStateOff: ${this.
|
|
234
|
+
+ ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
|
|
267
235
|
}
|
|
268
236
|
}
|
|
269
237
|
}
|
|
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
238
|
async apiError(e) {
|
|
386
|
-
if (this.device.irlight?.stateless) {
|
|
387
|
-
this.
|
|
239
|
+
if (!this.device.irlight?.stateless) {
|
|
240
|
+
this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
388
241
|
}
|
|
389
242
|
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;
|
|
243
|
+
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
244
|
+
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
245
|
+
this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
246
|
+
this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
406
247
|
}
|
|
407
248
|
}
|
|
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
249
|
}
|
|
505
250
|
//# sourceMappingURL=light.js.map
|