@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
|
@@ -1,82 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* waterheater.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
5
|
+
import { irdeviceBase } from './irdevice.js';
|
|
6
|
+
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
+
import type { irDevicesConfig, irdevice } from '../settings.js';
|
|
9
|
+
import type { 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
|
-
|
|
22
|
-
|
|
23
|
-
// Config
|
|
24
|
-
deviceLogging!: string;
|
|
25
|
-
disablePushOn?: boolean;
|
|
26
|
-
disablePushOff?: boolean;
|
|
18
|
+
private Valve: {
|
|
19
|
+
Name: CharacteristicValue;
|
|
20
|
+
Service: Service;
|
|
21
|
+
Active: CharacteristicValue;
|
|
22
|
+
};
|
|
27
23
|
|
|
28
24
|
constructor(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
readonly platform: SwitchBotPlatform,
|
|
26
|
+
accessory: PlatformAccessory,
|
|
27
|
+
device: irdevice & irDevicesConfig,
|
|
32
28
|
) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.
|
|
47
|
-
.
|
|
48
|
-
.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// get the Television service if it exists, otherwise create a new Television service
|
|
53
|
-
// you can create multiple services for each accessory
|
|
54
|
-
const valveService = `${accessory.displayName} ${device.remoteType}`;
|
|
55
|
-
(this.valveService = accessory.getService(this.hap.Service.Valve)
|
|
56
|
-
|| accessory.addService(this.hap.Service.Valve)), valveService;
|
|
57
|
-
|
|
58
|
-
this.valveService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
59
|
-
if (!this.valveService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
60
|
-
this.valveService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// set sleep discovery characteristic
|
|
64
|
-
this.valveService.setCharacteristic(this.hap.Characteristic.ValveType, this.hap.Characteristic.ValveType.GENERIC_VALVE);
|
|
65
|
-
|
|
66
|
-
// handle on / off events using the Active characteristic
|
|
67
|
-
this.valveService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
29
|
+
super(platform, accessory, device);
|
|
30
|
+
|
|
31
|
+
// Initialize Switch Service
|
|
32
|
+
accessory.context.Valve = accessory.context.Valve ?? {};
|
|
33
|
+
this.Valve = {
|
|
34
|
+
Name: accessory.context.Valve.Name ?? `${accessory.displayName} ${device.remoteType}`,
|
|
35
|
+
Service: accessory.getService(this.hap.Service.Valve) ?? accessory.addService(this.hap.Service.Valve) as Service,
|
|
36
|
+
Active: accessory.context.Active ?? this.hap.Characteristic.Active.INACTIVE,
|
|
37
|
+
};
|
|
38
|
+
accessory.context.Valve = this.Valve as object;
|
|
39
|
+
|
|
40
|
+
this.Valve.Service
|
|
41
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
42
|
+
.setCharacteristic(this.hap.Characteristic.ValveType, this.hap.Characteristic.ValveType.GENERIC_VALVE)
|
|
43
|
+
.getCharacteristic(this.hap.Characteristic.Active)
|
|
44
|
+
.onGet(() => {
|
|
45
|
+
return this.Valve.Active;
|
|
46
|
+
})
|
|
47
|
+
.onSet(this.ActiveSet.bind(this));
|
|
68
48
|
}
|
|
69
49
|
|
|
70
50
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
71
51
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
|
|
72
52
|
|
|
73
|
-
this.Active = value;
|
|
74
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
53
|
+
this.Valve.Active = value;
|
|
54
|
+
if (this.Valve.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
75
55
|
await this.pushWaterHeaterOnChanges();
|
|
76
|
-
this.
|
|
56
|
+
this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.IN_USE);
|
|
77
57
|
} else {
|
|
78
58
|
await this.pushWaterHeaterOffChanges();
|
|
79
|
-
this.
|
|
59
|
+
this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.NOT_IN_USE);
|
|
80
60
|
}
|
|
81
61
|
}
|
|
82
62
|
|
|
@@ -87,11 +67,9 @@ export class WaterHeater {
|
|
|
87
67
|
* WaterHeater "command" "turnOn" "default" set to ON state
|
|
88
68
|
*/
|
|
89
69
|
async pushWaterHeaterOnChanges(): Promise<void> {
|
|
90
|
-
this.debugLog(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
);
|
|
94
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
70
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushWaterHeaterOnChanges Active: ${this.Valve.Active},`
|
|
71
|
+
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
72
|
+
if (this.Valve.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
95
73
|
const commandType: string = await this.commandType();
|
|
96
74
|
const command: string = await this.commandOn();
|
|
97
75
|
const bodyChange = JSON.stringify({
|
|
@@ -104,11 +82,9 @@ export class WaterHeater {
|
|
|
104
82
|
}
|
|
105
83
|
|
|
106
84
|
async pushWaterHeaterOffChanges(): Promise<void> {
|
|
107
|
-
this.debugLog(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
);
|
|
111
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
85
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushWaterHeaterOffChanges Active: ${this.Valve.Active},`
|
|
86
|
+
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
87
|
+
if (this.Valve.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
112
88
|
const commandType: string = await this.commandType();
|
|
113
89
|
const command: string = await this.commandOff();
|
|
114
90
|
const bodyChange = JSON.stringify({
|
|
@@ -125,285 +101,39 @@ export class WaterHeater {
|
|
|
125
101
|
if (this.device.connectionType === 'OpenAPI') {
|
|
126
102
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
127
103
|
try {
|
|
128
|
-
const { body, statusCode } = await
|
|
129
|
-
body: bodyChange,
|
|
130
|
-
method: 'POST',
|
|
131
|
-
headers: this.platform.generateHeaders(),
|
|
132
|
-
});
|
|
133
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
104
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
134
105
|
const deviceStatus: any = await body.json();
|
|
135
|
-
this.
|
|
136
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
106
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
137
107
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
138
|
-
this.
|
|
139
|
-
|
|
140
|
-
this.updateHomeKitCharacteristics();
|
|
108
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
109
|
+
await this.updateHomeKitCharacteristics();
|
|
141
110
|
} else {
|
|
142
|
-
this.statusCode(statusCode);
|
|
143
|
-
this.statusCode(deviceStatus.statusCode);
|
|
111
|
+
await this.statusCode(statusCode);
|
|
112
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
144
113
|
}
|
|
145
114
|
} catch (e: any) {
|
|
146
115
|
this.apiError(e);
|
|
147
|
-
this.errorLog(
|
|
148
|
-
|
|
149
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
150
|
-
);
|
|
116
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
|
|
117
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
151
118
|
}
|
|
152
119
|
} else {
|
|
153
|
-
this.warnLog(
|
|
154
|
-
|
|
155
|
-
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
156
|
-
);
|
|
120
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
121
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
157
122
|
}
|
|
158
123
|
}
|
|
159
124
|
|
|
160
125
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
161
126
|
// Active
|
|
162
|
-
if (this.Active === undefined) {
|
|
163
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
164
|
-
} else {
|
|
165
|
-
this.accessory.context.Active = this.Active;
|
|
166
|
-
this.valveService?.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
|
|
167
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
172
|
-
if (device.disablePushOn === undefined) {
|
|
173
|
-
this.disablePushOn = false;
|
|
174
|
-
} else {
|
|
175
|
-
this.disablePushOn = device.disablePushOn;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
180
|
-
if (device.disablePushOff === undefined) {
|
|
181
|
-
this.disablePushOff = false;
|
|
182
|
-
} else {
|
|
183
|
-
this.disablePushOff = device.disablePushOff;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
async commandType(): Promise<string> {
|
|
188
|
-
let commandType: string;
|
|
189
|
-
if (this.device.customize) {
|
|
190
|
-
commandType = 'customize';
|
|
191
|
-
} else {
|
|
192
|
-
commandType = 'command';
|
|
193
|
-
}
|
|
194
|
-
return commandType;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async commandOn(): Promise<string> {
|
|
198
|
-
let command: string;
|
|
199
|
-
if (this.device.customize && this.device.customOn) {
|
|
200
|
-
command = this.device.customOn;
|
|
201
|
-
} else {
|
|
202
|
-
command = 'turnOn';
|
|
203
|
-
}
|
|
204
|
-
return command;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
async commandOff(): Promise<string> {
|
|
208
|
-
let command: string;
|
|
209
|
-
if (this.device.customize && this.device.customOff) {
|
|
210
|
-
command = this.device.customOff;
|
|
127
|
+
if (this.Valve.Active === undefined) {
|
|
128
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Valve.Active}`);
|
|
211
129
|
} else {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
218
|
-
switch (statusCode) {
|
|
219
|
-
case 151:
|
|
220
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
221
|
-
break;
|
|
222
|
-
case 152:
|
|
223
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
224
|
-
break;
|
|
225
|
-
case 160:
|
|
226
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
227
|
-
break;
|
|
228
|
-
case 161:
|
|
229
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
230
|
-
break;
|
|
231
|
-
case 171:
|
|
232
|
-
this.errorLog(
|
|
233
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
234
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
235
|
-
);
|
|
236
|
-
break;
|
|
237
|
-
case 190:
|
|
238
|
-
this.errorLog(
|
|
239
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
240
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
241
|
-
);
|
|
242
|
-
break;
|
|
243
|
-
case 100:
|
|
244
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
245
|
-
break;
|
|
246
|
-
case 200:
|
|
247
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
248
|
-
break;
|
|
249
|
-
case 400:
|
|
250
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
251
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
252
|
-
break;
|
|
253
|
-
case 401:
|
|
254
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
255
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
256
|
-
break;
|
|
257
|
-
case 403:
|
|
258
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
259
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
260
|
-
break;
|
|
261
|
-
case 404:
|
|
262
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
263
|
-
+ `statusCode: ${statusCode}`);
|
|
264
|
-
break;
|
|
265
|
-
case 406:
|
|
266
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
267
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
268
|
-
break;
|
|
269
|
-
case 415:
|
|
270
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
271
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
272
|
-
break;
|
|
273
|
-
case 422:
|
|
274
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
|
|
275
|
-
+ `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
276
|
-
break;
|
|
277
|
-
case 429:
|
|
278
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
279
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
280
|
-
break;
|
|
281
|
-
case 500:
|
|
282
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
283
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
284
|
-
break;
|
|
285
|
-
default:
|
|
286
|
-
this.infoLog(
|
|
287
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
288
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
289
|
-
);
|
|
130
|
+
this.accessory.context.Active = this.Valve.Active;
|
|
131
|
+
this.Valve.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Valve.Active);
|
|
132
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Valve.Active}`);
|
|
290
133
|
}
|
|
291
134
|
}
|
|
292
135
|
|
|
293
136
|
async apiError({ e }: { e: any }): Promise<void> {
|
|
294
|
-
this.
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
async deviceContext(): Promise<void> {
|
|
298
|
-
if (this.Active === undefined) {
|
|
299
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
300
|
-
} else {
|
|
301
|
-
this.Active = this.accessory.context.Active;
|
|
302
|
-
}
|
|
303
|
-
if (this.FirmwareRevision === undefined) {
|
|
304
|
-
this.FirmwareRevision = this.platform.version;
|
|
305
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
310
|
-
let config = {};
|
|
311
|
-
if (device.irwh) {
|
|
312
|
-
config = device.irwh;
|
|
313
|
-
}
|
|
314
|
-
if (device.logging !== undefined) {
|
|
315
|
-
config['logging'] = device.logging;
|
|
316
|
-
}
|
|
317
|
-
if (device.connectionType !== undefined) {
|
|
318
|
-
config['connectionType'] = device.connectionType;
|
|
319
|
-
}
|
|
320
|
-
if (device.external !== undefined) {
|
|
321
|
-
config['external'] = device.external;
|
|
322
|
-
}
|
|
323
|
-
if (device.customOn !== undefined) {
|
|
324
|
-
config['customOn'] = device.customOn;
|
|
325
|
-
}
|
|
326
|
-
if (device.customOff !== undefined) {
|
|
327
|
-
config['customOff'] = device.customOff;
|
|
328
|
-
}
|
|
329
|
-
if (device.customize !== undefined) {
|
|
330
|
-
config['customize'] = device.customize;
|
|
331
|
-
}
|
|
332
|
-
if (device.disablePushOn !== undefined) {
|
|
333
|
-
config['disablePushOn'] = device.disablePushOn;
|
|
334
|
-
}
|
|
335
|
-
if (device.disablePushOff !== undefined) {
|
|
336
|
-
config['disablePushOff'] = device.disablePushOff;
|
|
337
|
-
}
|
|
338
|
-
if (Object.entries(config).length !== 0) {
|
|
339
|
-
this.debugWarnLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`] });
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
344
|
-
if (this.platform.debugMode) {
|
|
345
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
346
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
347
|
-
} else if (device.logging) {
|
|
348
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
349
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
350
|
-
} else if (this.platform.config.options?.logging) {
|
|
351
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
352
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
353
|
-
} else {
|
|
354
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
355
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Logging for Device
|
|
361
|
-
*/
|
|
362
|
-
infoLog(...log: any[]): void {
|
|
363
|
-
if (this.enablingDeviceLogging()) {
|
|
364
|
-
this.platform.log.info(String(...log));
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
warnLog(...log: any[]): void {
|
|
369
|
-
if (this.enablingDeviceLogging()) {
|
|
370
|
-
this.platform.log.warn(String(...log));
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
debugWarnLog(...log: any[]): void {
|
|
375
|
-
if (this.enablingDeviceLogging()) {
|
|
376
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
377
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
errorLog(...log: any[]): void {
|
|
383
|
-
if (this.enablingDeviceLogging()) {
|
|
384
|
-
this.platform.log.error(String(...log));
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
debugErrorLog(...log: any[]): void {
|
|
389
|
-
if (this.enablingDeviceLogging()) {
|
|
390
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
391
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
debugLog(...log: any[]): void {
|
|
397
|
-
if (this.enablingDeviceLogging()) {
|
|
398
|
-
if (this.deviceLogging === 'debug') {
|
|
399
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
400
|
-
} else {
|
|
401
|
-
this.platform.log.debug(String(...log));
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
enablingDeviceLogging(): boolean {
|
|
407
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
137
|
+
this.Valve.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
408
138
|
}
|
|
409
139
|
}
|