@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
package/src/irdevices/cameras.ts
CHANGED
|
@@ -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 Camera {
|
|
|
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} Camera`;
|
|
47
|
+
accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Camera`;
|
|
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 Camera {
|
|
|
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) {
|
|
@@ -81,13 +72,8 @@ export class Camera {
|
|
|
81
72
|
if (this.On === undefined) {
|
|
82
73
|
this.debugLog(`Camera: ${this.accessory.displayName} On: ${this.On}`);
|
|
83
74
|
} else {
|
|
84
|
-
this.service?.updateCharacteristic(
|
|
85
|
-
|
|
86
|
-
this.On,
|
|
87
|
-
);
|
|
88
|
-
this.debugLog(
|
|
89
|
-
`Camera: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
|
|
90
|
-
);
|
|
75
|
+
this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
76
|
+
this.debugLog(`Camera: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
91
77
|
}
|
|
92
78
|
}
|
|
93
79
|
|
|
@@ -104,9 +90,9 @@ export class Camera {
|
|
|
104
90
|
async pushOnChanges() {
|
|
105
91
|
if (this.On) {
|
|
106
92
|
const payload = {
|
|
107
|
-
commandType:
|
|
108
|
-
parameter:
|
|
109
|
-
command:
|
|
93
|
+
commandType: 'command',
|
|
94
|
+
parameter: 'default',
|
|
95
|
+
command: 'turnOn',
|
|
110
96
|
} as payload;
|
|
111
97
|
await this.pushChanges(payload);
|
|
112
98
|
}
|
|
@@ -115,9 +101,9 @@ export class Camera {
|
|
|
115
101
|
async pushOffChanges() {
|
|
116
102
|
if (!this.On) {
|
|
117
103
|
const payload = {
|
|
118
|
-
commandType:
|
|
119
|
-
parameter:
|
|
120
|
-
command:
|
|
104
|
+
commandType: 'command',
|
|
105
|
+
parameter: 'default',
|
|
106
|
+
command: 'turnOff',
|
|
121
107
|
} as payload;
|
|
122
108
|
await this.pushChanges(payload);
|
|
123
109
|
}
|
|
@@ -125,87 +111,56 @@ export class Camera {
|
|
|
125
111
|
|
|
126
112
|
public async pushChanges(payload: payload) {
|
|
127
113
|
try {
|
|
128
|
-
this.infoLog(
|
|
129
|
-
`
|
|
130
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
131
|
-
);
|
|
114
|
+
this.infoLog(`Camera: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
115
|
+
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
132
116
|
|
|
133
117
|
// Make the API request
|
|
134
|
-
const push = await this.platform.axios.post(
|
|
135
|
-
|
|
136
|
-
payload,
|
|
137
|
-
);
|
|
138
|
-
this.debugLog(
|
|
139
|
-
`Camera: ${this.accessory.displayName} pushChanges: ${push.data}`,
|
|
140
|
-
);
|
|
118
|
+
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
119
|
+
this.debugLog(`Camera: ${this.accessory.displayName} pushChanges: ${push.data}`);
|
|
141
120
|
this.statusCode(push);
|
|
142
121
|
this.updateHomeKitCharacteristics();
|
|
143
122
|
this.OnCached = this.On;
|
|
144
123
|
this.accessory.context.On = this.OnCached;
|
|
145
124
|
} catch (e: any) {
|
|
146
|
-
this.errorLog(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
this.errorLog(
|
|
151
|
-
`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
152
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
153
|
-
);
|
|
125
|
+
this.errorLog(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
126
|
+
if (this.deviceLogging === 'debug') {
|
|
127
|
+
this.errorLog(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
128
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
154
129
|
}
|
|
155
130
|
if (this.platform.debugMode) {
|
|
156
|
-
this.errorLog(
|
|
157
|
-
`
|
|
158
|
-
` Error: ${JSON.stringify(e)}`,
|
|
159
|
-
);
|
|
131
|
+
this.errorLog(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
132
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
160
133
|
}
|
|
161
134
|
this.apiError(e);
|
|
162
135
|
}
|
|
163
136
|
}
|
|
164
137
|
|
|
165
|
-
private statusCode(push: AxiosResponse<{ statusCode: number }>) {
|
|
138
|
+
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
166
139
|
switch (push.data.statusCode) {
|
|
167
140
|
case 151:
|
|
168
|
-
this.errorLog(
|
|
169
|
-
`Camera: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
170
|
-
);
|
|
141
|
+
this.errorLog(`Camera: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
171
142
|
break;
|
|
172
143
|
case 152:
|
|
173
|
-
this.errorLog(
|
|
174
|
-
`Camera: ${this.accessory.displayName} Device not found.`,
|
|
175
|
-
);
|
|
144
|
+
this.errorLog(`Camera: ${this.accessory.displayName} Device not found.`);
|
|
176
145
|
break;
|
|
177
146
|
case 160:
|
|
178
|
-
this.errorLog(
|
|
179
|
-
`Camera: ${this.accessory.displayName} Command is not supported.`,
|
|
180
|
-
);
|
|
147
|
+
this.errorLog(`Camera: ${this.accessory.displayName} Command is not supported.`);
|
|
181
148
|
break;
|
|
182
149
|
case 161:
|
|
183
|
-
this.errorLog(
|
|
184
|
-
`Camera: ${this.accessory.displayName} Device is offline.`,
|
|
185
|
-
);
|
|
150
|
+
this.errorLog(`Camera: ${this.accessory.displayName} Device is offline.`);
|
|
186
151
|
break;
|
|
187
152
|
case 171:
|
|
188
|
-
this.errorLog(
|
|
189
|
-
`Camera: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
190
|
-
);
|
|
153
|
+
this.errorLog(`Camera: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
191
154
|
break;
|
|
192
155
|
case 190:
|
|
193
|
-
this.errorLog(
|
|
194
|
-
`
|
|
195
|
-
` with server, Or command: ${JSON.stringify(
|
|
196
|
-
push.data,
|
|
197
|
-
)} format is invalid`,
|
|
198
|
-
);
|
|
156
|
+
this.errorLog(`Camera: ${this.accessory.displayName} Device internal error due to device states not synchronized`
|
|
157
|
+
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
199
158
|
break;
|
|
200
159
|
case 100:
|
|
201
|
-
this.debugLog(
|
|
202
|
-
`Camera: ${this.accessory.displayName} Command successfully sent.`,
|
|
203
|
-
);
|
|
160
|
+
this.debugLog(`Camera: ${this.accessory.displayName} Command successfully sent.`);
|
|
204
161
|
break;
|
|
205
162
|
default:
|
|
206
|
-
this.debugLog(
|
|
207
|
-
`Camera: ${this.accessory.displayName} Unknown statusCode.`,
|
|
208
|
-
);
|
|
163
|
+
this.debugLog(`Camera: ${this.accessory.displayName} Unknown statusCode.`);
|
|
209
164
|
}
|
|
210
165
|
}
|
|
211
166
|
|
|
@@ -220,45 +175,32 @@ export class Camera {
|
|
|
220
175
|
config = device.ircam;
|
|
221
176
|
}
|
|
222
177
|
if (device.logging !== undefined) {
|
|
223
|
-
config[
|
|
178
|
+
config['logging'] = device.logging;
|
|
224
179
|
}
|
|
225
180
|
if (Object.entries(config).length !== 0) {
|
|
226
|
-
this.warnLog(
|
|
227
|
-
`Camera: ${this.accessory.displayName} Config: ${JSON.stringify(
|
|
228
|
-
config,
|
|
229
|
-
)}`,
|
|
230
|
-
);
|
|
181
|
+
this.warnLog(`Camera: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
231
182
|
}
|
|
232
183
|
}
|
|
233
184
|
|
|
234
185
|
logs(device: irdevice & irDevicesConfig) {
|
|
235
186
|
if (this.platform.debugMode) {
|
|
236
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
237
|
-
this.debugLog(
|
|
238
|
-
`Camera: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
239
|
-
);
|
|
187
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
188
|
+
this.debugLog(`Camera: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
240
189
|
} else if (device.logging) {
|
|
241
190
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
242
|
-
this.debugLog(
|
|
243
|
-
`Camera: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
244
|
-
);
|
|
191
|
+
this.debugLog(`Camera: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
245
192
|
} else if (this.platform.config.options?.logging) {
|
|
246
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
247
|
-
|
|
248
|
-
this.debugLog(
|
|
249
|
-
`Camera: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
250
|
-
);
|
|
193
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
194
|
+
this.debugLog(`Camera: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
251
195
|
} else {
|
|
252
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
253
|
-
this.debugLog(
|
|
254
|
-
`Camera: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
255
|
-
);
|
|
196
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
197
|
+
this.debugLog(`Camera: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
256
198
|
}
|
|
257
199
|
}
|
|
258
200
|
|
|
259
201
|
/**
|
|
260
|
-
|
|
261
|
-
|
|
202
|
+
* Logging for Device
|
|
203
|
+
*/
|
|
262
204
|
infoLog(...log: any[]) {
|
|
263
205
|
if (this.enablingDeviceLogging()) {
|
|
264
206
|
this.platform.log.info(String(...log));
|
|
@@ -279,8 +221,8 @@ export class Camera {
|
|
|
279
221
|
|
|
280
222
|
debugLog(...log: any[]) {
|
|
281
223
|
if (this.enablingDeviceLogging()) {
|
|
282
|
-
if (this.deviceLogging ===
|
|
283
|
-
this.platform.log.info(
|
|
224
|
+
if (this.deviceLogging === 'debug') {
|
|
225
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
284
226
|
} else {
|
|
285
227
|
this.platform.log.debug(String(...log));
|
|
286
228
|
}
|
|
@@ -288,6 +230,6 @@ export class Camera {
|
|
|
288
230
|
}
|
|
289
231
|
|
|
290
232
|
enablingDeviceLogging(): boolean {
|
|
291
|
-
return this.deviceLogging
|
|
233
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
292
234
|
}
|
|
293
235
|
}
|