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