@switchbot/homebridge-switchbot 3.5.0-beta.22 → 3.5.0-beta.24
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/config.schema.json +23 -2
- package/dist/device/blindtilt.d.ts +21 -98
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +332 -785
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -75
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +566 -778
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -71
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +168 -606
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -78
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +218 -655
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -69
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +196 -553
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -90
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +324 -810
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +58 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +629 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/hub.d.ts +15 -63
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +223 -610
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -69
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -595
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -68
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +156 -599
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -72
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +204 -591
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -66
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +199 -566
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -67
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +152 -592
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -68
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +151 -599
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -73
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +129 -540
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -61
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +71 -476
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -66
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +122 -471
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -66
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +105 -478
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +5 -36
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +228 -337
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -34
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +19 -267
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +5 -34
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +13 -261
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +5 -34
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +13 -260
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +39 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +502 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +5 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +13 -267
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +349 -551
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +79 -325
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +38 -288
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +39 -291
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +15 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/utils.d.ts +68 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +71 -0
- package/dist/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/device/blindtilt.ts +356 -809
- package/src/device/bot.ts +601 -865
- package/src/device/ceilinglight.ts +182 -628
- package/src/device/colorbulb.ts +235 -683
- package/src/device/contact.ts +220 -575
- package/src/device/curtain.ts +344 -836
- package/src/device/device.ts +655 -0
- package/src/device/hub.ts +246 -636
- package/src/device/humidifier.ts +224 -645
- package/src/device/iosensor.ts +181 -625
- package/src/device/lightstrip.ts +230 -622
- package/src/device/lock.ts +236 -607
- package/src/device/meter.ts +177 -616
- package/src/device/meterplus.ts +175 -624
- package/src/device/motion.ts +147 -563
- package/src/device/plug.ts +81 -505
- package/src/device/robotvacuumcleaner.ts +139 -494
- package/src/device/waterdetector.ts +126 -506
- package/src/irdevice/airconditioner.ts +228 -353
- package/src/irdevice/airpurifier.ts +23 -282
- package/src/irdevice/camera.ts +18 -277
- package/src/irdevice/fan.ts +18 -275
- package/src/irdevice/irdevice.ts +518 -0
- package/src/irdevice/light.ts +18 -283
- package/src/irdevice/other.ts +394 -621
- package/src/irdevice/tv.ts +97 -344
- package/src/irdevice/vacuumcleaner.ts +46 -310
- package/src/irdevice/waterheater.ts +47 -315
- package/src/settings.ts +20 -3
- package/src/utils.ts +71 -0
|
@@ -1,82 +1,63 @@
|
|
|
1
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* waterheater.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
2
5
|
import { request } from 'undici';
|
|
6
|
+
import { irdeviceBase } from './irdevice.js';
|
|
3
7
|
import { SwitchBotPlatform } from '../platform.js';
|
|
4
|
-
import { Devices, irDevicesConfig, irdevice
|
|
8
|
+
import { Devices, irDevicesConfig, irdevice } from '../settings.js';
|
|
9
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
5
10
|
|
|
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 WaterHeater {
|
|
12
|
-
public readonly api: API;
|
|
13
|
-
public readonly log: Logging;
|
|
14
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
15
|
-
protected readonly hap: HAP;
|
|
16
|
+
export class WaterHeater extends irdeviceBase {
|
|
16
17
|
// Services
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
FirmwareRevision!: CharacteristicValue;
|
|
22
|
-
|
|
23
|
-
// Config
|
|
24
|
-
deviceLogging!: string;
|
|
25
|
-
disablePushOn?: boolean;
|
|
26
|
-
disablePushOff?: boolean;
|
|
18
|
+
private Valve: {
|
|
19
|
+
Service: Service;
|
|
20
|
+
Active: CharacteristicValue;
|
|
21
|
+
};
|
|
27
22
|
|
|
28
23
|
constructor(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
readonly platform: SwitchBotPlatform,
|
|
25
|
+
accessory: PlatformAccessory,
|
|
26
|
+
device: irdevice & irDevicesConfig,
|
|
32
27
|
) {
|
|
33
|
-
|
|
34
|
-
this.log = this.platform.log;
|
|
35
|
-
this.config = this.platform.config;
|
|
36
|
-
this.hap = this.api.hap;
|
|
37
|
-
// default placeholders
|
|
38
|
-
this.deviceLogs(device);
|
|
39
|
-
this.deviceContext();
|
|
40
|
-
this.disablePushOnChanges(device);
|
|
41
|
-
this.disablePushOffChanges(device);
|
|
42
|
-
this.deviceConfig(device);
|
|
28
|
+
super(platform, accessory, device);
|
|
43
29
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
.
|
|
47
|
-
.
|
|
48
|
-
|
|
49
|
-
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
50
|
-
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
30
|
+
// Initialize Valve property
|
|
31
|
+
this.Valve = {
|
|
32
|
+
Service: accessory.addService(this.hap.Service.Valve),
|
|
33
|
+
Active: accessory.context.Active || this.hap.Characteristic.Active.INACTIVE,
|
|
34
|
+
};
|
|
51
35
|
|
|
52
36
|
// get the Television service if it exists, otherwise create a new Television service
|
|
53
37
|
// you can create multiple services for each accessory
|
|
54
|
-
const
|
|
55
|
-
(this.
|
|
56
|
-
|| accessory.addService(this.hap.Service.Valve)),
|
|
38
|
+
const ValveService = `${accessory.displayName} ${device.remoteType}`;
|
|
39
|
+
(this.Valve.Service = accessory.getService(this.hap.Service.Valve)
|
|
40
|
+
|| accessory.addService(this.hap.Service.Valve)), ValveService;
|
|
57
41
|
|
|
58
|
-
this.
|
|
59
|
-
if (!this.valveService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
60
|
-
this.valveService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
61
|
-
}
|
|
42
|
+
this.Valve.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
62
43
|
|
|
63
44
|
// set sleep discovery characteristic
|
|
64
|
-
this.
|
|
45
|
+
this.Valve.Service.setCharacteristic(this.hap.Characteristic.ValveType, this.hap.Characteristic.ValveType.GENERIC_VALVE);
|
|
65
46
|
|
|
66
47
|
// handle on / off events using the Active characteristic
|
|
67
|
-
this.
|
|
48
|
+
this.Valve.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
68
49
|
}
|
|
69
50
|
|
|
70
51
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
71
52
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
|
|
72
53
|
|
|
73
|
-
this.Active = value;
|
|
74
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
54
|
+
this.Valve.Active = value;
|
|
55
|
+
if (this.Valve.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
75
56
|
await this.pushWaterHeaterOnChanges();
|
|
76
|
-
this.
|
|
57
|
+
this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.IN_USE);
|
|
77
58
|
} else {
|
|
78
59
|
await this.pushWaterHeaterOffChanges();
|
|
79
|
-
this.
|
|
60
|
+
this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.NOT_IN_USE);
|
|
80
61
|
}
|
|
81
62
|
}
|
|
82
63
|
|
|
@@ -87,11 +68,9 @@ export class WaterHeater {
|
|
|
87
68
|
* WaterHeater "command" "turnOn" "default" set to ON state
|
|
88
69
|
*/
|
|
89
70
|
async pushWaterHeaterOnChanges(): Promise<void> {
|
|
90
|
-
this.debugLog(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
);
|
|
94
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
71
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushWaterHeaterOnChanges Active: ${this.Valve.Active},`
|
|
72
|
+
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
73
|
+
if (this.Valve.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
95
74
|
const commandType: string = await this.commandType();
|
|
96
75
|
const command: string = await this.commandOn();
|
|
97
76
|
const bodyChange = JSON.stringify({
|
|
@@ -104,11 +83,9 @@ export class WaterHeater {
|
|
|
104
83
|
}
|
|
105
84
|
|
|
106
85
|
async pushWaterHeaterOffChanges(): Promise<void> {
|
|
107
|
-
this.debugLog(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
);
|
|
111
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
86
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushWaterHeaterOffChanges Active: ${this.Valve.Active},`
|
|
87
|
+
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
88
|
+
if (this.Valve.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
112
89
|
const commandType: string = await this.commandType();
|
|
113
90
|
const command: string = await this.commandOff();
|
|
114
91
|
const bodyChange = JSON.stringify({
|
|
@@ -145,272 +122,27 @@ export class WaterHeater {
|
|
|
145
122
|
}
|
|
146
123
|
} catch (e: any) {
|
|
147
124
|
this.apiError(e);
|
|
148
|
-
this.errorLog(
|
|
149
|
-
|
|
150
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
151
|
-
);
|
|
125
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
|
|
126
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
152
127
|
}
|
|
153
128
|
} else {
|
|
154
|
-
this.warnLog(
|
|
155
|
-
|
|
156
|
-
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
157
|
-
);
|
|
129
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
130
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
158
131
|
}
|
|
159
132
|
}
|
|
160
133
|
|
|
161
134
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
162
135
|
// Active
|
|
163
|
-
if (this.Active === undefined) {
|
|
164
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
165
|
-
} else {
|
|
166
|
-
this.accessory.context.Active = this.Active;
|
|
167
|
-
this.valveService?.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
|
|
168
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
173
|
-
if (device.disablePushOn === undefined) {
|
|
174
|
-
this.disablePushOn = false;
|
|
175
|
-
} else {
|
|
176
|
-
this.disablePushOn = device.disablePushOn;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
181
|
-
if (device.disablePushOff === undefined) {
|
|
182
|
-
this.disablePushOff = false;
|
|
183
|
-
} else {
|
|
184
|
-
this.disablePushOff = device.disablePushOff;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async commandType(): Promise<string> {
|
|
189
|
-
let commandType: string;
|
|
190
|
-
if (this.device.customize) {
|
|
191
|
-
commandType = 'customize';
|
|
192
|
-
} else {
|
|
193
|
-
commandType = 'command';
|
|
194
|
-
}
|
|
195
|
-
return commandType;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async commandOn(): Promise<string> {
|
|
199
|
-
let command: string;
|
|
200
|
-
if (this.device.customize && this.device.customOn) {
|
|
201
|
-
command = this.device.customOn;
|
|
202
|
-
} else {
|
|
203
|
-
command = 'turnOn';
|
|
204
|
-
}
|
|
205
|
-
return command;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
async commandOff(): Promise<string> {
|
|
209
|
-
let command: string;
|
|
210
|
-
if (this.device.customize && this.device.customOff) {
|
|
211
|
-
command = this.device.customOff;
|
|
136
|
+
if (this.Valve.Active === undefined) {
|
|
137
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Valve.Active}`);
|
|
212
138
|
} else {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
219
|
-
switch (statusCode) {
|
|
220
|
-
case 151:
|
|
221
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
222
|
-
break;
|
|
223
|
-
case 152:
|
|
224
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
225
|
-
break;
|
|
226
|
-
case 160:
|
|
227
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
228
|
-
break;
|
|
229
|
-
case 161:
|
|
230
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
231
|
-
break;
|
|
232
|
-
case 171:
|
|
233
|
-
this.errorLog(
|
|
234
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
235
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
236
|
-
);
|
|
237
|
-
break;
|
|
238
|
-
case 190:
|
|
239
|
-
this.errorLog(
|
|
240
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
241
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
242
|
-
);
|
|
243
|
-
break;
|
|
244
|
-
case 100:
|
|
245
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
246
|
-
break;
|
|
247
|
-
case 200:
|
|
248
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
249
|
-
break;
|
|
250
|
-
case 400:
|
|
251
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
252
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
253
|
-
break;
|
|
254
|
-
case 401:
|
|
255
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
256
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
257
|
-
break;
|
|
258
|
-
case 403:
|
|
259
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
260
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
261
|
-
break;
|
|
262
|
-
case 404:
|
|
263
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
264
|
-
+ `statusCode: ${statusCode}`);
|
|
265
|
-
break;
|
|
266
|
-
case 406:
|
|
267
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
268
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
269
|
-
break;
|
|
270
|
-
case 415:
|
|
271
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
272
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
273
|
-
break;
|
|
274
|
-
case 422:
|
|
275
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
|
|
276
|
-
+ `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
277
|
-
break;
|
|
278
|
-
case 429:
|
|
279
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
280
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
281
|
-
break;
|
|
282
|
-
case 500:
|
|
283
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
284
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
285
|
-
break;
|
|
286
|
-
default:
|
|
287
|
-
this.infoLog(
|
|
288
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
289
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
290
|
-
);
|
|
139
|
+
this.accessory.context.Active = this.Valve.Active;
|
|
140
|
+
this.Valve.Service?.updateCharacteristic(this.hap.Characteristic.Active, this.Valve.Active);
|
|
141
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Valve.Active}`);
|
|
291
142
|
}
|
|
292
143
|
}
|
|
293
144
|
|
|
294
145
|
async apiError({ e }: { e: any }): Promise<void> {
|
|
295
|
-
this.
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
async deviceContext(): Promise<void> {
|
|
299
|
-
if (this.Active === undefined) {
|
|
300
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
301
|
-
} else {
|
|
302
|
-
this.Active = this.accessory.context.Active;
|
|
303
|
-
}
|
|
304
|
-
if (this.FirmwareRevision === undefined) {
|
|
305
|
-
this.FirmwareRevision = this.platform.version;
|
|
306
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
311
|
-
let config = {};
|
|
312
|
-
if (device.irwh) {
|
|
313
|
-
config = device.irwh;
|
|
314
|
-
}
|
|
315
|
-
if (device.logging !== undefined) {
|
|
316
|
-
config['logging'] = device.logging;
|
|
317
|
-
}
|
|
318
|
-
if (device.connectionType !== undefined) {
|
|
319
|
-
config['connectionType'] = device.connectionType;
|
|
320
|
-
}
|
|
321
|
-
if (device.external !== undefined) {
|
|
322
|
-
config['external'] = device.external;
|
|
323
|
-
}
|
|
324
|
-
if (device.customOn !== undefined) {
|
|
325
|
-
config['customOn'] = device.customOn;
|
|
326
|
-
}
|
|
327
|
-
if (device.customOff !== undefined) {
|
|
328
|
-
config['customOff'] = device.customOff;
|
|
329
|
-
}
|
|
330
|
-
if (device.customize !== undefined) {
|
|
331
|
-
config['customize'] = device.customize;
|
|
332
|
-
}
|
|
333
|
-
if (device.disablePushOn !== undefined) {
|
|
334
|
-
config['disablePushOn'] = device.disablePushOn;
|
|
335
|
-
}
|
|
336
|
-
if (device.disablePushOff !== undefined) {
|
|
337
|
-
config['disablePushOff'] = device.disablePushOff;
|
|
338
|
-
}
|
|
339
|
-
if (Object.entries(config).length !== 0) {
|
|
340
|
-
this.debugWarnLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`] });
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
345
|
-
if (this.platform.debugMode) {
|
|
346
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
347
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
348
|
-
} else if (device.logging) {
|
|
349
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
350
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
351
|
-
} else if (this.platform.config.options?.logging) {
|
|
352
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
353
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
354
|
-
} else {
|
|
355
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
356
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Logging for Device
|
|
362
|
-
*/
|
|
363
|
-
successLog(...log: any[]): void {
|
|
364
|
-
if (this.enablingDeviceLogging()) {
|
|
365
|
-
this.platform.log.success(String(...log));
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
infoLog(...log: any[]): void {
|
|
370
|
-
if (this.enablingDeviceLogging()) {
|
|
371
|
-
this.platform.log.info(String(...log));
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
warnLog(...log: any[]): void {
|
|
376
|
-
if (this.enablingDeviceLogging()) {
|
|
377
|
-
this.platform.log.warn(String(...log));
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
debugWarnLog(...log: any[]): void {
|
|
382
|
-
if (this.enablingDeviceLogging()) {
|
|
383
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
384
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
errorLog(...log: any[]): void {
|
|
390
|
-
if (this.enablingDeviceLogging()) {
|
|
391
|
-
this.platform.log.error(String(...log));
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
debugErrorLog(...log: any[]): void {
|
|
396
|
-
if (this.enablingDeviceLogging()) {
|
|
397
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
398
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
debugLog(...log: any[]): void {
|
|
404
|
-
if (this.enablingDeviceLogging()) {
|
|
405
|
-
if (this.deviceLogging === 'debug') {
|
|
406
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
407
|
-
} else {
|
|
408
|
-
this.platform.log.debug(String(...log));
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
enablingDeviceLogging(): boolean {
|
|
414
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
146
|
+
this.Valve.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
415
147
|
}
|
|
416
148
|
}
|
package/src/settings.ts
CHANGED
|
@@ -53,6 +53,7 @@ export interface devicesConfig extends device {
|
|
|
53
53
|
deviceId: string;
|
|
54
54
|
external?: boolean;
|
|
55
55
|
refreshRate?: number;
|
|
56
|
+
updateRate?: number;
|
|
56
57
|
firmware?: string;
|
|
57
58
|
logging?: string;
|
|
58
59
|
connectionType?: string;
|
|
@@ -71,6 +72,7 @@ export interface devicesConfig extends device {
|
|
|
71
72
|
webhook?: boolean;
|
|
72
73
|
bot?: bot;
|
|
73
74
|
meter?: meter;
|
|
75
|
+
iosensor?: iosensor;
|
|
74
76
|
humidifier?: humidifier;
|
|
75
77
|
curtain?: curtain;
|
|
76
78
|
blindTilt?: blindTilt;
|
|
@@ -90,6 +92,11 @@ export type meter = {
|
|
|
90
92
|
hide_humidity?: boolean;
|
|
91
93
|
};
|
|
92
94
|
|
|
95
|
+
export type iosensor = {
|
|
96
|
+
hide_temperature?: boolean;
|
|
97
|
+
hide_humidity?: boolean;
|
|
98
|
+
};
|
|
99
|
+
|
|
93
100
|
export type bot = {
|
|
94
101
|
mode?: string;
|
|
95
102
|
deviceType?: string;
|
|
@@ -109,7 +116,6 @@ export type curtain = {
|
|
|
109
116
|
hide_lightsensor?: boolean;
|
|
110
117
|
set_minLux?: number;
|
|
111
118
|
set_maxLux?: number;
|
|
112
|
-
updateRate?: number;
|
|
113
119
|
set_max?: number;
|
|
114
120
|
set_min?: number;
|
|
115
121
|
set_minStep?: number;
|
|
@@ -122,7 +128,6 @@ export type blindTilt = {
|
|
|
122
128
|
hide_lightsensor?: boolean;
|
|
123
129
|
set_minLux?: number;
|
|
124
130
|
set_maxLux?: number;
|
|
125
|
-
updateRate?: number;
|
|
126
131
|
set_max?: number;
|
|
127
132
|
set_min?: number;
|
|
128
133
|
set_minStep?: number;
|
|
@@ -268,6 +273,10 @@ export type device = {
|
|
|
268
273
|
version?: number;
|
|
269
274
|
//BLE Mac Address
|
|
270
275
|
bleMac?: string;
|
|
276
|
+
//Device Model
|
|
277
|
+
model?: string;
|
|
278
|
+
//Device BLE Model
|
|
279
|
+
bleModel?: string;
|
|
271
280
|
};
|
|
272
281
|
|
|
273
282
|
//a list of virtual infrared remote devices.
|
|
@@ -280,9 +289,16 @@ export type irdevice = {
|
|
|
280
289
|
deviceName: string; //device name
|
|
281
290
|
remoteType: string; //device type
|
|
282
291
|
hubDeviceId: string; //remote device's parent Hub ID
|
|
292
|
+
model: string; //device model
|
|
283
293
|
};
|
|
284
294
|
|
|
285
295
|
export type deviceStatus = {
|
|
296
|
+
statusCode: number;
|
|
297
|
+
message: string;
|
|
298
|
+
body: deviceStatusBody;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export type deviceStatusBody = {
|
|
286
302
|
//v1.1 of API
|
|
287
303
|
deviceId: string; //device ID. (Used by the following deviceTypes: Bot, Curtain, Meter, Meter Plus, Lock, Keypad, Keypad Touch, Motion Sensor, Contact Sensor, Ceiling Light, Ceiling Light Pro, Plug Mini (US), Plug Mini (JP), Strip Light, Color Bulb, Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Humidifier, Blind Tilt)
|
|
288
304
|
deviceType: string; //device type. (Used by the following deviceTypes: Bot, Curtain, Meter, Meter Plus, Lock, Keypad, Keypad Touch, Motion Sensor, Contact Sensor, Ceiling Light, Ceiling Light Pro, Plug Mini (US), Plug Mini (JP), Strip Light, Color Bulb, Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Humidifier, Blind Tilt)
|
|
@@ -323,6 +339,7 @@ export type deviceStatus = {
|
|
|
323
339
|
shakeCenter?: string; //the fan's swing direction. (Used by the following deviceTypes: Smart Fan)
|
|
324
340
|
shakeRange?: string; //the fan's swing range, 0~120°. (Used by the following deviceTypes: Smart Fan)
|
|
325
341
|
status?: number //the leak status. 0 for no leak, 1 for leak. (Used by the following deviceTypes: Water Detector)
|
|
342
|
+
lightLevel?: number; //the light level. (Used by the following deviceTypes: Hub)
|
|
326
343
|
};
|
|
327
344
|
|
|
328
345
|
export type ad = {
|
|
@@ -359,7 +376,7 @@ export type serviceData = {
|
|
|
359
376
|
battery?: number;
|
|
360
377
|
//Humidifier's humidity level percentage
|
|
361
378
|
percentage?: boolean | string;
|
|
362
|
-
//Humidifier's
|
|
379
|
+
//Humidifier's state
|
|
363
380
|
onState?: boolean;
|
|
364
381
|
//Humidifier's AutoMode
|
|
365
382
|
autoMode?: boolean;
|
package/src/utils.ts
CHANGED
|
@@ -2,6 +2,77 @@
|
|
|
2
2
|
*
|
|
3
3
|
* util.ts: @switchbot/homebridge-switchbot platform class.
|
|
4
4
|
*/
|
|
5
|
+
export enum SwitchBotModel {
|
|
6
|
+
HubMini = 'W0202200',
|
|
7
|
+
HubPlus = 'SwitchBot Hub S1',
|
|
8
|
+
Hub2 = 'W3202100',
|
|
9
|
+
Bot = 'SwitchBot S1',
|
|
10
|
+
Curtain = 'W0701600',
|
|
11
|
+
Curtain3 = 'W2400000',
|
|
12
|
+
Humidifier = 'W0801800',
|
|
13
|
+
Plug = 'SP11', // Currently only available in Japan
|
|
14
|
+
Meter = 'SwitchBot MeterTH S1',
|
|
15
|
+
MeterPlusJP = 'W2201500',
|
|
16
|
+
MeterPlusUS = 'W2301500',
|
|
17
|
+
OutdoorMeter = 'W3400010',
|
|
18
|
+
MotionSensor = 'W1101500',
|
|
19
|
+
ContactSensor = 'W1201500',
|
|
20
|
+
ColorBulb = 'W1401400',
|
|
21
|
+
StripLight = 'W1701100',
|
|
22
|
+
PlugMiniUS = 'W1901400',
|
|
23
|
+
PlugMiniJP = 'W2001400',
|
|
24
|
+
Lock = 'W1601700',
|
|
25
|
+
LockPro = 'W3500000',
|
|
26
|
+
Keypad = 'W2500010',
|
|
27
|
+
KeypadTouch = 'W2500020',
|
|
28
|
+
K10 = 'K10+',
|
|
29
|
+
WoSweeper = 'WoSweeper',
|
|
30
|
+
WoSweeperMini = 'WoSweeperMini',
|
|
31
|
+
RobotVacuumCleanerS1 = 'W3011000', // Currently only available in Japan.
|
|
32
|
+
RobotVacuumCleanerS1Plus = 'W3011010', // Currently only available in Japan.
|
|
33
|
+
Remote = 'Remote',
|
|
34
|
+
UniversalRemote = 'UniversalRemote',
|
|
35
|
+
CeilingLight = 'W2612230', // Currently only available in Japan.
|
|
36
|
+
CeilingLightPro = 'W2612210', // Currently only available in Japan.
|
|
37
|
+
IndoorCam = 'W1301200',
|
|
38
|
+
PanTiltCam = 'W1801200',
|
|
39
|
+
PanTiltCam2K = 'W3101100',
|
|
40
|
+
BlindTilt = 'W2701600',
|
|
41
|
+
BatteryCirculatorFan = 'W3800510',
|
|
42
|
+
WaterDetector = 'WoWaterDetector',
|
|
43
|
+
Unknown = 'Unknown',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export enum SwitchBotBLEModel {
|
|
47
|
+
Bot = 'H',
|
|
48
|
+
Curtain = 'c',
|
|
49
|
+
Curtain3 = '{',
|
|
50
|
+
Humidifier = 'e',
|
|
51
|
+
Meter = 'T',
|
|
52
|
+
MeterPlus = 'i',
|
|
53
|
+
OutdoorMeter = 'w',
|
|
54
|
+
MotionSensor = 's',
|
|
55
|
+
ContactSensor = 'd',
|
|
56
|
+
ColorBulb = 'u',
|
|
57
|
+
StripLight = 'r',
|
|
58
|
+
PlugMiniUS = 'g',
|
|
59
|
+
PlugMiniJP = 'j',
|
|
60
|
+
Lock = 'o',
|
|
61
|
+
Remote = '',
|
|
62
|
+
CeilingLight = 'q', // Currently only available in Japan.
|
|
63
|
+
CeilingLightPro = 'n', // Currently only available in Japan.
|
|
64
|
+
BlindTilt = 'x',
|
|
65
|
+
Unknown = 'Unknown',
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export enum BlindTiltMappingMode {
|
|
69
|
+
OnlyUp = 'only_up',
|
|
70
|
+
OnlyDown = 'only_down',
|
|
71
|
+
DownAndUp = 'down_and_up',
|
|
72
|
+
UpAndDown = 'up_and_down',
|
|
73
|
+
UseTiltForDirection = 'use_tilt_for_direction',
|
|
74
|
+
}
|
|
75
|
+
|
|
5
76
|
export function sleep(ms: number): Promise<void> {
|
|
6
77
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
7
78
|
}
|