@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.9.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/.eslintrc +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +8 -0
- package/config.schema.json +9 -0
- package/dist/devices/bots.d.ts +37 -34
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +196 -243
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +50 -50
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +131 -145
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +29 -27
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +115 -138
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +31 -29
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +176 -211
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +33 -33
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +189 -214
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +31 -30
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +100 -124
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +26 -25
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +102 -120
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +23 -23
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +63 -81
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -22
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +6 -6
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +79 -105
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +5 -5
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +42 -56
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +5 -5
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +27 -31
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +5 -5
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +38 -45
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +5 -5
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +33 -37
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +5 -5
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +29 -34
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +5 -5
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +76 -91
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +5 -5
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +27 -31
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +5 -5
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +27 -31
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +12 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +172 -241
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +2 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/package.json +71 -72
- package/src/devices/bots.ts +455 -929
- package/src/devices/colorbulb.ts +246 -473
- package/src/devices/contact.ts +208 -381
- package/src/devices/curtains.ts +321 -613
- package/src/devices/humidifiers.ts +323 -594
- package/src/devices/meters.ts +186 -331
- package/src/devices/motion.ts +184 -327
- package/src/devices/plugs.ts +107 -175
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +149 -360
- package/src/irdevices/airpurifiers.ts +80 -178
- package/src/irdevices/cameras.ts +51 -109
- package/src/irdevices/fans.ts +77 -174
- package/src/irdevices/lights.ts +57 -110
- package/src/irdevices/others.ts +62 -137
- package/src/irdevices/tvs.ts +124 -249
- package/src/irdevices/vacuumcleaners.ts +52 -112
- package/src/irdevices/waterheaters.ts +53 -115
- package/src/platform.ts +357 -768
- package/src/settings.ts +24 -17
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AxiosResponse } from
|
|
2
|
-
import { SwitchBotPlatform } from
|
|
3
|
-
import { irDevicesConfig, DeviceURL, irdevice, payload } from
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { SwitchBotPlatform } from '../platform';
|
|
3
|
+
import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
|
|
4
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -36,19 +36,15 @@ export class VacuumCleaner {
|
|
|
36
36
|
// set accessory information
|
|
37
37
|
accessory
|
|
38
38
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
39
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
39
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
40
40
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
41
|
-
.setCharacteristic(
|
|
42
|
-
this.platform.Characteristic.SerialNumber,
|
|
43
|
-
device.deviceId!,
|
|
44
|
-
);
|
|
41
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
45
42
|
|
|
46
43
|
// get the Television service if it exists, otherwise create a new Television service
|
|
47
44
|
// you can create multiple services for each accessory
|
|
48
45
|
(this.service =
|
|
49
46
|
accessory.getService(this.platform.Service.Switch) ||
|
|
50
|
-
accessory.addService(this.platform.Service.Switch)),
|
|
51
|
-
`${accessory.displayName} Vacuum`;
|
|
47
|
+
accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Vacuum`;
|
|
52
48
|
|
|
53
49
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
54
50
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -56,15 +52,10 @@ export class VacuumCleaner {
|
|
|
56
52
|
|
|
57
53
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
58
54
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
59
|
-
this.service.setCharacteristic(
|
|
60
|
-
this.platform.Characteristic.Name,
|
|
61
|
-
accessory.displayName,
|
|
62
|
-
);
|
|
55
|
+
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
63
56
|
|
|
64
57
|
// handle on / off events using the On characteristic
|
|
65
|
-
this.service
|
|
66
|
-
.getCharacteristic(this.platform.Characteristic.On)
|
|
67
|
-
.onSet(this.OnSet.bind(this));
|
|
58
|
+
this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
68
59
|
}
|
|
69
60
|
|
|
70
61
|
private OnSet(value: CharacteristicValue) {
|
|
@@ -79,17 +70,10 @@ export class VacuumCleaner {
|
|
|
79
70
|
|
|
80
71
|
private updateHomeKitCharacteristics() {
|
|
81
72
|
if (this.On === undefined) {
|
|
82
|
-
this.debugLog(
|
|
83
|
-
`Vacuum Cleaner: ${this.accessory.displayName} On: ${this.On}`,
|
|
84
|
-
);
|
|
73
|
+
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} On: ${this.On}`);
|
|
85
74
|
} else {
|
|
86
|
-
this.service?.updateCharacteristic(
|
|
87
|
-
|
|
88
|
-
this.On,
|
|
89
|
-
);
|
|
90
|
-
this.debugLog(
|
|
91
|
-
`Vacuum Cleaner: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
|
|
92
|
-
);
|
|
75
|
+
this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
76
|
+
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
93
77
|
}
|
|
94
78
|
}
|
|
95
79
|
|
|
@@ -106,9 +90,9 @@ export class VacuumCleaner {
|
|
|
106
90
|
async pushOnChanges() {
|
|
107
91
|
if (this.On) {
|
|
108
92
|
const payload = {
|
|
109
|
-
commandType:
|
|
110
|
-
parameter:
|
|
111
|
-
command:
|
|
93
|
+
commandType: 'command',
|
|
94
|
+
parameter: 'default',
|
|
95
|
+
command: 'turnOn',
|
|
112
96
|
} as payload;
|
|
113
97
|
await this.pushChanges(payload);
|
|
114
98
|
}
|
|
@@ -117,9 +101,9 @@ export class VacuumCleaner {
|
|
|
117
101
|
async pushOffChanges() {
|
|
118
102
|
if (!this.On) {
|
|
119
103
|
const payload = {
|
|
120
|
-
commandType:
|
|
121
|
-
parameter:
|
|
122
|
-
command:
|
|
104
|
+
commandType: 'command',
|
|
105
|
+
parameter: 'default',
|
|
106
|
+
command: 'turnOff',
|
|
123
107
|
} as payload;
|
|
124
108
|
await this.pushChanges(payload);
|
|
125
109
|
}
|
|
@@ -127,87 +111,56 @@ export class VacuumCleaner {
|
|
|
127
111
|
|
|
128
112
|
public async pushChanges(payload: payload) {
|
|
129
113
|
try {
|
|
130
|
-
this.infoLog(
|
|
131
|
-
`
|
|
132
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
133
|
-
);
|
|
114
|
+
this.infoLog(`Vacuum Cleaner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
115
|
+
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
134
116
|
|
|
135
117
|
// Make the API request
|
|
136
|
-
const push = await this.platform.axios.post(
|
|
137
|
-
|
|
138
|
-
payload,
|
|
139
|
-
);
|
|
140
|
-
this.debugLog(
|
|
141
|
-
`Vacuum Cleaner: ${this.accessory.displayName} pushChanges: ${push.data}`,
|
|
142
|
-
);
|
|
118
|
+
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
119
|
+
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} pushChanges: ${push.data}`);
|
|
143
120
|
this.statusCode(push);
|
|
144
121
|
this.OnCached = this.On;
|
|
145
122
|
this.accessory.context.On = this.OnCached;
|
|
146
123
|
this.updateHomeKitCharacteristics();
|
|
147
124
|
} catch (e: any) {
|
|
148
|
-
this.errorLog(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
this.errorLog(
|
|
153
|
-
`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
154
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
155
|
-
);
|
|
125
|
+
this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
126
|
+
if (this.deviceLogging === 'debug') {
|
|
127
|
+
this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
128
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
156
129
|
}
|
|
157
130
|
if (this.platform.debugMode) {
|
|
158
|
-
this.errorLog(
|
|
159
|
-
`
|
|
160
|
-
` Error: ${JSON.stringify(e)}`,
|
|
161
|
-
);
|
|
131
|
+
this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
132
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
162
133
|
}
|
|
163
134
|
this.apiError(e);
|
|
164
135
|
}
|
|
165
136
|
}
|
|
166
137
|
|
|
167
|
-
private statusCode(push: AxiosResponse<{ statusCode: number }>) {
|
|
138
|
+
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
168
139
|
switch (push.data.statusCode) {
|
|
169
140
|
case 151:
|
|
170
|
-
this.errorLog(
|
|
171
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
172
|
-
);
|
|
141
|
+
this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
173
142
|
break;
|
|
174
143
|
case 152:
|
|
175
|
-
this.errorLog(
|
|
176
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Device not found.`,
|
|
177
|
-
);
|
|
144
|
+
this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device not found.`);
|
|
178
145
|
break;
|
|
179
146
|
case 160:
|
|
180
|
-
this.errorLog(
|
|
181
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Command is not supported.`,
|
|
182
|
-
);
|
|
147
|
+
this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command is not supported.`);
|
|
183
148
|
break;
|
|
184
149
|
case 161:
|
|
185
|
-
this.errorLog(
|
|
186
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Device is offline.`,
|
|
187
|
-
);
|
|
150
|
+
this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device is offline.`);
|
|
188
151
|
break;
|
|
189
152
|
case 171:
|
|
190
|
-
this.errorLog(
|
|
191
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
192
|
-
);
|
|
153
|
+
this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
193
154
|
break;
|
|
194
155
|
case 190:
|
|
195
|
-
this.errorLog(
|
|
196
|
-
`
|
|
197
|
-
` with server, Or command: ${JSON.stringify(
|
|
198
|
-
push.data,
|
|
199
|
-
)} format is invalid`,
|
|
200
|
-
);
|
|
156
|
+
this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device internal error due to device states not synchronized`
|
|
157
|
+
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
201
158
|
break;
|
|
202
159
|
case 100:
|
|
203
|
-
this.debugLog(
|
|
204
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Command successfully sent.`,
|
|
205
|
-
);
|
|
160
|
+
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Command successfully sent.`);
|
|
206
161
|
break;
|
|
207
162
|
default:
|
|
208
|
-
this.debugLog(
|
|
209
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Unknown statusCode.`,
|
|
210
|
-
);
|
|
163
|
+
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Unknown statusCode.`);
|
|
211
164
|
}
|
|
212
165
|
}
|
|
213
166
|
|
|
@@ -222,45 +175,32 @@ export class VacuumCleaner {
|
|
|
222
175
|
config = device.irvc;
|
|
223
176
|
}
|
|
224
177
|
if (device.logging !== undefined) {
|
|
225
|
-
config[
|
|
178
|
+
config['logging'] = device.logging;
|
|
226
179
|
}
|
|
227
180
|
if (Object.entries(config).length !== 0) {
|
|
228
|
-
this.warnLog(
|
|
229
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Config: ${JSON.stringify(
|
|
230
|
-
config,
|
|
231
|
-
)}`,
|
|
232
|
-
);
|
|
181
|
+
this.warnLog(`Vacuum Cleaner: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
233
182
|
}
|
|
234
183
|
}
|
|
235
184
|
|
|
236
185
|
logs(device: irdevice & irDevicesConfig) {
|
|
237
186
|
if (this.platform.debugMode) {
|
|
238
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
239
|
-
this.debugLog(
|
|
240
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
241
|
-
);
|
|
187
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
188
|
+
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
242
189
|
} else if (device.logging) {
|
|
243
190
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
244
|
-
this.debugLog(
|
|
245
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
246
|
-
);
|
|
191
|
+
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
247
192
|
} else if (this.platform.config.options?.logging) {
|
|
248
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
249
|
-
|
|
250
|
-
this.debugLog(
|
|
251
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
252
|
-
);
|
|
193
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
194
|
+
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
253
195
|
} else {
|
|
254
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
255
|
-
this.debugLog(
|
|
256
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
257
|
-
);
|
|
196
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
197
|
+
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
258
198
|
}
|
|
259
199
|
}
|
|
260
200
|
|
|
261
201
|
/**
|
|
262
|
-
|
|
263
|
-
|
|
202
|
+
* Logging for Device
|
|
203
|
+
*/
|
|
264
204
|
infoLog(...log: any[]) {
|
|
265
205
|
if (this.enablingDeviceLogging()) {
|
|
266
206
|
this.platform.log.info(String(...log));
|
|
@@ -281,8 +221,8 @@ export class VacuumCleaner {
|
|
|
281
221
|
|
|
282
222
|
debugLog(...log: any[]) {
|
|
283
223
|
if (this.enablingDeviceLogging()) {
|
|
284
|
-
if (this.deviceLogging ===
|
|
285
|
-
this.platform.log.info(
|
|
224
|
+
if (this.deviceLogging === 'debug') {
|
|
225
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
286
226
|
} else {
|
|
287
227
|
this.platform.log.debug(String(...log));
|
|
288
228
|
}
|
|
@@ -290,6 +230,6 @@ export class VacuumCleaner {
|
|
|
290
230
|
}
|
|
291
231
|
|
|
292
232
|
enablingDeviceLogging(): boolean {
|
|
293
|
-
return this.deviceLogging
|
|
233
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
294
234
|
}
|
|
295
235
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AxiosResponse } from
|
|
2
|
-
import { SwitchBotPlatform } from
|
|
3
|
-
import { irDevicesConfig, DeviceURL, irdevice, payload } from
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { SwitchBotPlatform } from '../platform';
|
|
3
|
+
import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
|
|
4
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -36,19 +36,15 @@ export class WaterHeater {
|
|
|
36
36
|
// set accessory information
|
|
37
37
|
accessory
|
|
38
38
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
39
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
39
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
40
40
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
41
|
-
.setCharacteristic(
|
|
42
|
-
this.platform.Characteristic.SerialNumber,
|
|
43
|
-
device.deviceId!,
|
|
44
|
-
);
|
|
41
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
45
42
|
|
|
46
43
|
// get the Television service if it exists, otherwise create a new Television service
|
|
47
44
|
// you can create multiple services for each accessory
|
|
48
45
|
(this.service =
|
|
49
46
|
accessory.getService(this.platform.Service.Valve) ||
|
|
50
|
-
accessory.addService(this.platform.Service.Valve)),
|
|
51
|
-
`${accessory.displayName} Water Heater`;
|
|
47
|
+
accessory.addService(this.platform.Service.Valve)), `${accessory.displayName} Water Heater`;
|
|
52
48
|
|
|
53
49
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
54
50
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -68,15 +64,11 @@ export class WaterHeater {
|
|
|
68
64
|
);
|
|
69
65
|
|
|
70
66
|
// handle on / off events using the Active characteristic
|
|
71
|
-
this.service
|
|
72
|
-
.getCharacteristic(this.platform.Characteristic.Active)
|
|
73
|
-
.onSet(this.ActiveSet.bind(this));
|
|
67
|
+
this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
74
68
|
}
|
|
75
69
|
|
|
76
70
|
private ActiveSet(value: CharacteristicValue) {
|
|
77
|
-
this.debugLog(
|
|
78
|
-
`Water Heater: ${this.accessory.displayName} Active: ${value}`,
|
|
79
|
-
);
|
|
71
|
+
this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${value}`);
|
|
80
72
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
81
73
|
this.pushWaterHeaterOffChanges();
|
|
82
74
|
this.service.setCharacteristic(
|
|
@@ -85,10 +77,7 @@ export class WaterHeater {
|
|
|
85
77
|
);
|
|
86
78
|
} else {
|
|
87
79
|
this.pushWaterHeaterOnChanges();
|
|
88
|
-
this.service.setCharacteristic(
|
|
89
|
-
this.platform.Characteristic.InUse,
|
|
90
|
-
this.platform.Characteristic.InUse.IN_USE,
|
|
91
|
-
);
|
|
80
|
+
this.service.setCharacteristic(this.platform.Characteristic.InUse, this.platform.Characteristic.InUse.IN_USE);
|
|
92
81
|
}
|
|
93
82
|
this.Active = value;
|
|
94
83
|
this.ActiveCached = this.Active;
|
|
@@ -97,17 +86,10 @@ export class WaterHeater {
|
|
|
97
86
|
|
|
98
87
|
private updateHomeKitCharacteristics() {
|
|
99
88
|
if (this.Active === undefined) {
|
|
100
|
-
this.debugLog(
|
|
101
|
-
`Water Heater: ${this.accessory.displayName} Active: ${this.Active}`,
|
|
102
|
-
);
|
|
89
|
+
this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
103
90
|
} else {
|
|
104
|
-
this.service?.updateCharacteristic(
|
|
105
|
-
|
|
106
|
-
this.Active,
|
|
107
|
-
);
|
|
108
|
-
this.debugLog(
|
|
109
|
-
`Water Heater: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`,
|
|
110
|
-
);
|
|
91
|
+
this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
92
|
+
this.debugLog(`Water Heater: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
111
93
|
}
|
|
112
94
|
}
|
|
113
95
|
|
|
@@ -124,9 +106,9 @@ export class WaterHeater {
|
|
|
124
106
|
async pushWaterHeaterOnChanges() {
|
|
125
107
|
if (this.Active !== 1) {
|
|
126
108
|
const payload = {
|
|
127
|
-
commandType:
|
|
128
|
-
parameter:
|
|
129
|
-
command:
|
|
109
|
+
commandType: 'command',
|
|
110
|
+
parameter: 'default',
|
|
111
|
+
command: 'turnOn',
|
|
130
112
|
} as payload;
|
|
131
113
|
await this.pushChanges(payload);
|
|
132
114
|
}
|
|
@@ -135,9 +117,9 @@ export class WaterHeater {
|
|
|
135
117
|
async pushWaterHeaterOffChanges() {
|
|
136
118
|
if (this.Active !== 0) {
|
|
137
119
|
const payload = {
|
|
138
|
-
commandType:
|
|
139
|
-
parameter:
|
|
140
|
-
command:
|
|
120
|
+
commandType: 'command',
|
|
121
|
+
parameter: 'default',
|
|
122
|
+
command: 'turnOff',
|
|
141
123
|
} as payload;
|
|
142
124
|
await this.pushChanges(payload);
|
|
143
125
|
}
|
|
@@ -145,85 +127,54 @@ export class WaterHeater {
|
|
|
145
127
|
|
|
146
128
|
public async pushChanges(payload: payload) {
|
|
147
129
|
try {
|
|
148
|
-
this.infoLog(
|
|
149
|
-
`
|
|
150
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
151
|
-
);
|
|
130
|
+
this.infoLog(`Water Heater: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
131
|
+
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
152
132
|
|
|
153
133
|
// Make the API request
|
|
154
|
-
const push = await this.platform.axios.post(
|
|
155
|
-
|
|
156
|
-
payload,
|
|
157
|
-
);
|
|
158
|
-
this.debugLog(
|
|
159
|
-
`Water Heater: ${this.accessory.displayName} pushChanges: ${push.data}`,
|
|
160
|
-
);
|
|
134
|
+
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
135
|
+
this.debugLog(`Water Heater: ${this.accessory.displayName} pushChanges: ${push.data}`);
|
|
161
136
|
this.statusCode(push);
|
|
162
137
|
this.updateHomeKitCharacteristics();
|
|
163
138
|
} catch (e: any) {
|
|
164
|
-
this.errorLog(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
this.errorLog(
|
|
169
|
-
`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
170
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
171
|
-
);
|
|
139
|
+
this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
140
|
+
if (this.deviceLogging === 'debug') {
|
|
141
|
+
this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
142
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
172
143
|
}
|
|
173
144
|
if (this.platform.debugMode) {
|
|
174
|
-
this.errorLog(
|
|
175
|
-
`
|
|
176
|
-
` Error: ${JSON.stringify(e)}`,
|
|
177
|
-
);
|
|
145
|
+
this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
146
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
178
147
|
}
|
|
179
148
|
this.apiError(e);
|
|
180
149
|
}
|
|
181
150
|
}
|
|
182
151
|
|
|
183
|
-
private statusCode(push: AxiosResponse<{ statusCode: number }>) {
|
|
152
|
+
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
184
153
|
switch (push.data.statusCode) {
|
|
185
154
|
case 151:
|
|
186
|
-
this.errorLog(
|
|
187
|
-
`Water Heater: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
188
|
-
);
|
|
155
|
+
this.errorLog(`Water Heater: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
189
156
|
break;
|
|
190
157
|
case 152:
|
|
191
|
-
this.errorLog(
|
|
192
|
-
`Water Heater: ${this.accessory.displayName} Device not found.`,
|
|
193
|
-
);
|
|
158
|
+
this.errorLog(`Water Heater: ${this.accessory.displayName} Device not found.`);
|
|
194
159
|
break;
|
|
195
160
|
case 160:
|
|
196
|
-
this.errorLog(
|
|
197
|
-
`Water Heater: ${this.accessory.displayName} Command is not supported.`,
|
|
198
|
-
);
|
|
161
|
+
this.errorLog(`Water Heater: ${this.accessory.displayName} Command is not supported.`);
|
|
199
162
|
break;
|
|
200
163
|
case 161:
|
|
201
|
-
this.errorLog(
|
|
202
|
-
`Water Heater: ${this.accessory.displayName} Device is offline.`,
|
|
203
|
-
);
|
|
164
|
+
this.errorLog(`Water Heater: ${this.accessory.displayName} Device is offline.`);
|
|
204
165
|
break;
|
|
205
166
|
case 171:
|
|
206
|
-
this.errorLog(
|
|
207
|
-
`Water Heater: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
208
|
-
);
|
|
167
|
+
this.errorLog(`Water Heater: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
209
168
|
break;
|
|
210
169
|
case 190:
|
|
211
|
-
this.errorLog(
|
|
212
|
-
`
|
|
213
|
-
` with server, Or command: ${JSON.stringify(
|
|
214
|
-
push.data,
|
|
215
|
-
)} format is invalid`,
|
|
216
|
-
);
|
|
170
|
+
this.errorLog(`Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized`
|
|
171
|
+
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
217
172
|
break;
|
|
218
173
|
case 100:
|
|
219
|
-
this.debugLog(
|
|
220
|
-
`Water Heater: ${this.accessory.displayName} Command successfully sent.`,
|
|
221
|
-
);
|
|
174
|
+
this.debugLog(`Water Heater: ${this.accessory.displayName} Command successfully sent.`);
|
|
222
175
|
break;
|
|
223
176
|
default:
|
|
224
|
-
this.debugLog(
|
|
225
|
-
`Water Heater: ${this.accessory.displayName} Unknown statusCode.`,
|
|
226
|
-
);
|
|
177
|
+
this.debugLog(`Water Heater: ${this.accessory.displayName} Unknown statusCode.`);
|
|
227
178
|
}
|
|
228
179
|
}
|
|
229
180
|
|
|
@@ -238,45 +189,32 @@ export class WaterHeater {
|
|
|
238
189
|
config = device.irwh;
|
|
239
190
|
}
|
|
240
191
|
if (device.logging !== undefined) {
|
|
241
|
-
config[
|
|
192
|
+
config['logging'] = device.logging;
|
|
242
193
|
}
|
|
243
194
|
if (Object.entries(config).length !== 0) {
|
|
244
|
-
this.warnLog(
|
|
245
|
-
`Water Heater: ${this.accessory.displayName} Config: ${JSON.stringify(
|
|
246
|
-
config,
|
|
247
|
-
)}`,
|
|
248
|
-
);
|
|
195
|
+
this.warnLog(`Water Heater: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
249
196
|
}
|
|
250
197
|
}
|
|
251
198
|
|
|
252
199
|
logs(device: irdevice & irDevicesConfig) {
|
|
253
200
|
if (this.platform.debugMode) {
|
|
254
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
255
|
-
this.debugLog(
|
|
256
|
-
`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
257
|
-
);
|
|
201
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
202
|
+
this.debugLog(`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
258
203
|
} else if (device.logging) {
|
|
259
204
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
260
|
-
this.debugLog(
|
|
261
|
-
`Water Heater: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
262
|
-
);
|
|
205
|
+
this.debugLog(`Water Heater: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
263
206
|
} else if (this.platform.config.options?.logging) {
|
|
264
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
265
|
-
|
|
266
|
-
this.debugLog(
|
|
267
|
-
`Water Heater: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
268
|
-
);
|
|
207
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
208
|
+
this.debugLog(`Water Heater: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
269
209
|
} else {
|
|
270
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
271
|
-
this.debugLog(
|
|
272
|
-
`Water Heater: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
273
|
-
);
|
|
210
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
211
|
+
this.debugLog(`Water Heater: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
274
212
|
}
|
|
275
213
|
}
|
|
276
214
|
|
|
277
215
|
/**
|
|
278
|
-
|
|
279
|
-
|
|
216
|
+
* Logging for Device
|
|
217
|
+
*/
|
|
280
218
|
infoLog(...log: any[]) {
|
|
281
219
|
if (this.enablingDeviceLogging()) {
|
|
282
220
|
this.platform.log.info(String(...log));
|
|
@@ -297,8 +235,8 @@ export class WaterHeater {
|
|
|
297
235
|
|
|
298
236
|
debugLog(...log: any[]) {
|
|
299
237
|
if (this.enablingDeviceLogging()) {
|
|
300
|
-
if (this.deviceLogging ===
|
|
301
|
-
this.platform.log.info(
|
|
238
|
+
if (this.deviceLogging === 'debug') {
|
|
239
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
302
240
|
} else {
|
|
303
241
|
this.platform.log.debug(String(...log));
|
|
304
242
|
}
|
|
@@ -306,6 +244,6 @@ export class WaterHeater {
|
|
|
306
244
|
}
|
|
307
245
|
|
|
308
246
|
enablingDeviceLogging(): boolean {
|
|
309
|
-
return this.deviceLogging
|
|
247
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
310
248
|
}
|
|
311
249
|
}
|