@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/platform.ts
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
1
|
+
import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
|
+
import {
|
|
3
|
+
API, Characteristic, DynamicPlatformPlugin,
|
|
4
|
+
Logger,
|
|
5
|
+
PlatformAccessory,
|
|
6
|
+
Service,
|
|
7
|
+
} from "homebridge";
|
|
8
|
+
import { Bot } from "./devices/bots";
|
|
9
|
+
import { ColorBulb } from "./devices/colorbulb";
|
|
10
|
+
import { Contact } from "./devices/contact";
|
|
11
|
+
import { Curtain } from "./devices/curtains";
|
|
12
|
+
import { Humidifier } from "./devices/humidifiers";
|
|
13
|
+
import { Meter } from "./devices/meters";
|
|
14
|
+
import { Motion } from "./devices/motion";
|
|
15
|
+
import { Plug } from "./devices/plugs";
|
|
16
|
+
import { AirConditioner } from "./irdevices/airconditioners";
|
|
17
|
+
import { AirPurifier } from "./irdevices/airpurifiers";
|
|
18
|
+
import { Camera } from "./irdevices/cameras";
|
|
19
|
+
import { Fan } from "./irdevices/fans";
|
|
20
|
+
import { Light } from "./irdevices/lights";
|
|
21
|
+
import { Others } from "./irdevices/others";
|
|
22
|
+
import { TV } from "./irdevices/tvs";
|
|
23
|
+
import { VacuumCleaner } from "./irdevices/vacuumcleaners";
|
|
24
|
+
import { WaterHeater } from "./irdevices/waterheaters";
|
|
25
|
+
import * as settings from "./settings";
|
|
21
26
|
|
|
22
27
|
/**
|
|
23
28
|
* HomebridgePlatform
|
|
@@ -26,42 +31,49 @@ import { PLATFORM_NAME, PLUGIN_NAME, DeviceURL, irdevice, device, SwitchBotPlatf
|
|
|
26
31
|
*/
|
|
27
32
|
export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
28
33
|
public readonly Service: typeof Service = this.api.hap.Service;
|
|
29
|
-
public readonly Characteristic: typeof Characteristic =
|
|
34
|
+
public readonly Characteristic: typeof Characteristic =
|
|
35
|
+
this.api.hap.Characteristic;
|
|
30
36
|
|
|
31
37
|
// this is used to track restored cached accessories
|
|
32
38
|
public readonly accessories: PlatformAccessory[] = [];
|
|
33
39
|
|
|
34
40
|
public axios: AxiosInstance = axios.create({
|
|
35
|
-
responseType:
|
|
41
|
+
responseType: "json",
|
|
36
42
|
});
|
|
37
43
|
|
|
38
|
-
version = require(
|
|
39
|
-
deviceStatus!: deviceResponses;
|
|
44
|
+
version = require("../package.json").version; // eslint-disable-line @typescript-eslint/no-var-requires
|
|
45
|
+
deviceStatus!: settings.deviceResponses;
|
|
40
46
|
registeringDevice!: boolean;
|
|
41
47
|
debugMode!: boolean;
|
|
42
48
|
platformLogging?: string;
|
|
43
49
|
|
|
44
|
-
constructor(
|
|
50
|
+
constructor(
|
|
51
|
+
public readonly log: Logger,
|
|
52
|
+
public readonly config: settings.SwitchBotPlatformConfig,
|
|
53
|
+
public readonly api: API,
|
|
54
|
+
) {
|
|
45
55
|
this.logs();
|
|
46
|
-
this.debugLog(
|
|
56
|
+
this.debugLog("Finished initializing platform:", this.config.name);
|
|
47
57
|
// only load if configured
|
|
48
58
|
if (!this.config) {
|
|
49
59
|
return;
|
|
50
60
|
}
|
|
51
61
|
|
|
52
62
|
// HOOBS notice
|
|
53
|
-
if (__dirname.includes(
|
|
54
|
-
this.log.warn(
|
|
55
|
-
|
|
63
|
+
if (__dirname.includes("hoobs")) {
|
|
64
|
+
this.log.warn(
|
|
65
|
+
"This plugin has not been tested under HOOBS, it is highly recommended that " +
|
|
66
|
+
"you switch to Homebridge: https://git.io/Jtxb0",
|
|
67
|
+
);
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
// verify the config
|
|
59
71
|
try {
|
|
60
72
|
this.verifyConfig();
|
|
61
|
-
this.debugLog(
|
|
73
|
+
this.debugLog("Config OK");
|
|
62
74
|
} catch (e: any) {
|
|
63
75
|
this.errorLog(JSON.stringify(e.message));
|
|
64
|
-
if (this.platformLogging ===
|
|
76
|
+
if (this.platformLogging === "debugMode") {
|
|
65
77
|
this.errorLog(JSON.stringify(e));
|
|
66
78
|
}
|
|
67
79
|
return;
|
|
@@ -70,7 +82,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
70
82
|
// setup axios interceptor to add headers / api key to each request
|
|
71
83
|
this.axios.interceptors.request.use((request: AxiosRequestConfig) => {
|
|
72
84
|
request.headers!.Authorization = this.config.credentials?.openToken;
|
|
73
|
-
request.headers![
|
|
85
|
+
request.headers!["Content-Type"] = "application/json; charset=utf8";
|
|
74
86
|
return request;
|
|
75
87
|
});
|
|
76
88
|
|
|
@@ -78,14 +90,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
78
90
|
// Dynamic Platform plugins should only register new accessories after this event was fired,
|
|
79
91
|
// in order to ensure they weren't added to homebridge already. This event can also be used
|
|
80
92
|
// to start discovery of new accessories.
|
|
81
|
-
this.api.on(
|
|
82
|
-
this.debugLog(
|
|
93
|
+
this.api.on("didFinishLaunching", async () => {
|
|
94
|
+
this.debugLog("Executed didFinishLaunching callback");
|
|
83
95
|
// run the method to discover / register your devices as accessories
|
|
84
96
|
try {
|
|
85
97
|
this.discoverDevices();
|
|
86
98
|
} catch (e: any) {
|
|
87
|
-
this.errorLog(
|
|
88
|
-
if (this.platformLogging ===
|
|
99
|
+
this.errorLog("Failed to Discover Devices.", JSON.stringify(e.message));
|
|
100
|
+
if (this.platformLogging === "debugMode") {
|
|
89
101
|
this.errorLog(JSON.stringify(e));
|
|
90
102
|
}
|
|
91
103
|
}
|
|
@@ -93,20 +105,25 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
93
105
|
}
|
|
94
106
|
|
|
95
107
|
logs() {
|
|
96
|
-
this.debugMode =
|
|
97
|
-
|
|
108
|
+
this.debugMode =
|
|
109
|
+
process.argv.includes("-D") || process.argv.includes("--debug");
|
|
110
|
+
if (
|
|
111
|
+
this.config.options?.logging === "debug" ||
|
|
112
|
+
this.config.options?.logging === "standard" ||
|
|
113
|
+
this.config.options?.logging === "none"
|
|
114
|
+
) {
|
|
98
115
|
this.platformLogging = this.config.options!.logging;
|
|
99
|
-
if (this.platformLogging.includes(
|
|
116
|
+
if (this.platformLogging.includes("debug")) {
|
|
100
117
|
this.log.warn(`Using Config Logging: ${this.platformLogging}`);
|
|
101
118
|
}
|
|
102
119
|
} else if (this.debugMode) {
|
|
103
|
-
this.platformLogging =
|
|
104
|
-
if (this.platformLogging?.includes(
|
|
120
|
+
this.platformLogging = "debugMode";
|
|
121
|
+
if (this.platformLogging?.includes("debug")) {
|
|
105
122
|
this.log.warn(`Using ${this.platformLogging} Logging`);
|
|
106
123
|
}
|
|
107
124
|
} else {
|
|
108
|
-
this.platformLogging =
|
|
109
|
-
if (this.platformLogging?.includes(
|
|
125
|
+
this.platformLogging = "standard";
|
|
126
|
+
if (this.platformLogging?.includes("debug")) {
|
|
110
127
|
this.log.warn(`Using ${this.platformLogging} Logging`);
|
|
111
128
|
}
|
|
112
129
|
}
|
|
@@ -131,13 +148,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
131
148
|
|
|
132
149
|
const platformConfig = {};
|
|
133
150
|
if (this.config.options.logging) {
|
|
134
|
-
platformConfig[
|
|
151
|
+
platformConfig["logging"] = this.config.options.logging;
|
|
135
152
|
}
|
|
136
153
|
if (this.config.options.logging) {
|
|
137
|
-
platformConfig[
|
|
154
|
+
platformConfig["refreshRate"] = this.config.options.refreshRate;
|
|
138
155
|
}
|
|
139
156
|
if (this.config.options.logging) {
|
|
140
|
-
platformConfig[
|
|
157
|
+
platformConfig["pushRate"] = this.config.options.pushRate;
|
|
141
158
|
}
|
|
142
159
|
if (Object.entries(platformConfig).length !== 0) {
|
|
143
160
|
this.warnLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
@@ -149,10 +166,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
149
166
|
for (const deviceConfig of this.config.options.devices) {
|
|
150
167
|
if (!deviceConfig.hide_device) {
|
|
151
168
|
if (!deviceConfig.deviceId) {
|
|
152
|
-
throw new Error(
|
|
169
|
+
throw new Error(
|
|
170
|
+
"The devices config section is missing the *Device ID* in the config, Check Your Conifg.",
|
|
171
|
+
);
|
|
153
172
|
}
|
|
154
173
|
if (!deviceConfig.configDeviceType && deviceConfig.ble) {
|
|
155
|
-
throw new Error(
|
|
174
|
+
throw new Error(
|
|
175
|
+
"The devices config section is missing the *Device Type* in the config, Check Your Conifg.",
|
|
176
|
+
);
|
|
156
177
|
}
|
|
157
178
|
}
|
|
158
179
|
}
|
|
@@ -163,10 +184,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
163
184
|
for (const irDeviceConfig of this.config.options.irdevices) {
|
|
164
185
|
if (!irDeviceConfig.hide_device) {
|
|
165
186
|
if (!irDeviceConfig.deviceId) {
|
|
166
|
-
this.errorLog(
|
|
187
|
+
this.errorLog(
|
|
188
|
+
"The devices config section is missing the *Device ID* in the config, Check Your Conifg.",
|
|
189
|
+
);
|
|
167
190
|
}
|
|
168
191
|
if (!irDeviceConfig.deviceId && !irDeviceConfig.configRemoteType) {
|
|
169
|
-
this.errorLog(
|
|
192
|
+
this.errorLog(
|
|
193
|
+
"The devices config section is missing the *Device Type* in the config, Check Your Conifg.",
|
|
194
|
+
);
|
|
170
195
|
}
|
|
171
196
|
}
|
|
172
197
|
}
|
|
@@ -174,53 +199,61 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
174
199
|
}
|
|
175
200
|
|
|
176
201
|
if (this.config.options!.refreshRate! < 30) {
|
|
177
|
-
throw new Error(
|
|
202
|
+
throw new Error("Refresh Rate must be above 30 (30 seconds).");
|
|
178
203
|
}
|
|
179
204
|
|
|
180
205
|
if (!this.config.options.refreshRate) {
|
|
181
206
|
// default 120 seconds (2 minutes)
|
|
182
207
|
this.config.options!.refreshRate! = 120;
|
|
183
|
-
if (this.platformLogging?.includes(
|
|
184
|
-
this.debugLog(
|
|
208
|
+
if (this.platformLogging?.includes("debug")) {
|
|
209
|
+
this.debugLog("Using Default Refresh Rate (2 minutes).");
|
|
185
210
|
}
|
|
186
211
|
|
|
187
212
|
if (!this.config.options.pushRate) {
|
|
188
213
|
// default 100 milliseconds
|
|
189
214
|
this.config.options!.pushRate! = 0.1;
|
|
190
|
-
if (this.platformLogging?.includes(
|
|
191
|
-
this.warnLog(
|
|
215
|
+
if (this.platformLogging?.includes("debug")) {
|
|
216
|
+
this.warnLog("Using Default Push Rate.");
|
|
192
217
|
}
|
|
193
218
|
}
|
|
194
219
|
|
|
195
220
|
if (!this.config.credentials) {
|
|
196
|
-
if (this.platformLogging?.includes(
|
|
197
|
-
this.debugLog(
|
|
221
|
+
if (this.platformLogging?.includes("debug")) {
|
|
222
|
+
this.debugLog("Missing Credentials");
|
|
198
223
|
}
|
|
199
224
|
}
|
|
200
225
|
if (!this.config.credentials?.openToken) {
|
|
201
|
-
if (this.platformLogging?.includes(
|
|
202
|
-
this.errorLog(
|
|
203
|
-
this.warnLog(
|
|
226
|
+
if (this.platformLogging?.includes("debug")) {
|
|
227
|
+
this.errorLog("Missing openToken");
|
|
228
|
+
this.warnLog(
|
|
229
|
+
"Cloud Enabled SwitchBot Devices & IR Devices will not work",
|
|
230
|
+
);
|
|
204
231
|
}
|
|
205
232
|
}
|
|
206
233
|
}
|
|
207
234
|
}
|
|
208
235
|
|
|
209
236
|
/**
|
|
210
|
-
|
|
211
|
-
|
|
237
|
+
* this method discovers devices
|
|
238
|
+
*/
|
|
212
239
|
async discoverDevices() {
|
|
213
240
|
try {
|
|
214
241
|
if (this.config.credentials?.openToken) {
|
|
215
|
-
const devicesAPI: any = (await this.axios.get(DeviceURL)).data;
|
|
242
|
+
const devicesAPI: any = (await this.axios.get(settings.DeviceURL)).data;
|
|
216
243
|
this.deviceListInfo(devicesAPI);
|
|
217
244
|
this.debugLog(JSON.stringify(devicesAPI));
|
|
218
245
|
|
|
219
246
|
// SwitchBot Devices
|
|
220
|
-
this.infoLog(
|
|
247
|
+
this.infoLog(
|
|
248
|
+
`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`,
|
|
249
|
+
);
|
|
221
250
|
const deviceLists = devicesAPI.body.deviceList;
|
|
222
251
|
if (!this.config.options?.devices) {
|
|
223
|
-
this.debugLog(
|
|
252
|
+
this.debugLog(
|
|
253
|
+
`SwitchBot Device Config Not Set: ${JSON.stringify(
|
|
254
|
+
this.config.options?.devices,
|
|
255
|
+
)}`,
|
|
256
|
+
);
|
|
224
257
|
const devices = deviceLists.map((v: any) => v);
|
|
225
258
|
for (const device of devices) {
|
|
226
259
|
if (device.deviceType) {
|
|
@@ -230,14 +263,25 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
230
263
|
this.createDevice(device);
|
|
231
264
|
}
|
|
232
265
|
}
|
|
233
|
-
} else if (
|
|
234
|
-
this.
|
|
266
|
+
} else if (
|
|
267
|
+
this.config.credentials?.openToken &&
|
|
268
|
+
this.config.options.devices
|
|
269
|
+
) {
|
|
270
|
+
this.debugLog(
|
|
271
|
+
`SwitchBot Device Config Set: ${JSON.stringify(
|
|
272
|
+
this.config.options?.devices,
|
|
273
|
+
)}`,
|
|
274
|
+
);
|
|
235
275
|
const deviceConfigs = this.config.options?.devices;
|
|
236
276
|
|
|
237
|
-
const mergeBydeviceId = (a1: { deviceId: string
|
|
238
|
-
a1.map((itm: { deviceId: string
|
|
239
|
-
...a2.find(
|
|
240
|
-
item
|
|
277
|
+
const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
278
|
+
a1.map((itm: { deviceId: string }) => ({
|
|
279
|
+
...a2.find(
|
|
280
|
+
(item: { deviceId: string }) =>
|
|
281
|
+
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, "") ===
|
|
282
|
+
itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, "") &&
|
|
283
|
+
item,
|
|
284
|
+
),
|
|
241
285
|
...itm,
|
|
242
286
|
}));
|
|
243
287
|
|
|
@@ -252,13 +296,21 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
252
296
|
}
|
|
253
297
|
}
|
|
254
298
|
} else {
|
|
255
|
-
this.errorLog(
|
|
299
|
+
this.errorLog(
|
|
300
|
+
"Neither SwitchBot OpenToken or Device Config are not set.",
|
|
301
|
+
);
|
|
256
302
|
}
|
|
257
303
|
// IR Devices
|
|
258
|
-
this.infoLog(
|
|
304
|
+
this.infoLog(
|
|
305
|
+
`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`,
|
|
306
|
+
);
|
|
259
307
|
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
260
308
|
if (!this.config.options?.irdevices) {
|
|
261
|
-
this.debugLog(
|
|
309
|
+
this.debugLog(
|
|
310
|
+
`IR Device Config Not Set: ${JSON.stringify(
|
|
311
|
+
this.config.options?.irdevices,
|
|
312
|
+
)}`,
|
|
313
|
+
);
|
|
262
314
|
const devices = irDeviceLists.map((v: any) => v);
|
|
263
315
|
for (const device of devices) {
|
|
264
316
|
if (device.remoteType) {
|
|
@@ -266,13 +318,21 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
266
318
|
}
|
|
267
319
|
}
|
|
268
320
|
} else {
|
|
269
|
-
this.debugLog(
|
|
321
|
+
this.debugLog(
|
|
322
|
+
`IR Device Config Set: ${JSON.stringify(
|
|
323
|
+
this.config.options?.irdevices,
|
|
324
|
+
)}`,
|
|
325
|
+
);
|
|
270
326
|
const irDeviceConfig = this.config.options?.irdevices;
|
|
271
327
|
|
|
272
|
-
const mergeIRBydeviceId = (a1: { deviceId: string
|
|
273
|
-
a1.map((itm: { deviceId: string
|
|
274
|
-
...a2.find(
|
|
275
|
-
item
|
|
328
|
+
const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
329
|
+
a1.map((itm: { deviceId: string }) => ({
|
|
330
|
+
...a2.find(
|
|
331
|
+
(item: { deviceId: string }) =>
|
|
332
|
+
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, "") ===
|
|
333
|
+
itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, "") &&
|
|
334
|
+
item,
|
|
335
|
+
),
|
|
276
336
|
...itm,
|
|
277
337
|
}));
|
|
278
338
|
|
|
@@ -284,8 +344,15 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
284
344
|
}
|
|
285
345
|
}
|
|
286
346
|
}
|
|
287
|
-
} else if (
|
|
288
|
-
this.
|
|
347
|
+
} else if (
|
|
348
|
+
!this.config.credentials?.openToken &&
|
|
349
|
+
this.config.options?.devices
|
|
350
|
+
) {
|
|
351
|
+
this.debugLog(
|
|
352
|
+
`SwitchBot Device Manual Config Set: ${JSON.stringify(
|
|
353
|
+
this.config.options?.devices,
|
|
354
|
+
)}`,
|
|
355
|
+
);
|
|
289
356
|
const deviceConfigs = this.config.options?.devices;
|
|
290
357
|
const devices = deviceConfigs.map((v: any) => v);
|
|
291
358
|
for (const device of devices) {
|
|
@@ -296,7 +363,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
296
363
|
}
|
|
297
364
|
}
|
|
298
365
|
} else {
|
|
299
|
-
this.errorLog(
|
|
366
|
+
this.errorLog(
|
|
367
|
+
"Neither SwitchBot OpenToken or Device Config are not set.",
|
|
368
|
+
);
|
|
300
369
|
}
|
|
301
370
|
} catch (e: any) {
|
|
302
371
|
this.deviceError(e);
|
|
@@ -304,191 +373,239 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
304
373
|
}
|
|
305
374
|
|
|
306
375
|
deviceError(e: any) {
|
|
307
|
-
if (e.message.includes(
|
|
308
|
-
this.errorLog(
|
|
309
|
-
this.debugLog(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
this.
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
this.
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
} else if (e.message.includes(
|
|
323
|
-
this.errorLog(
|
|
324
|
-
this.debugLog(
|
|
325
|
-
} else if (e.message.includes(
|
|
326
|
-
this.errorLog(
|
|
327
|
-
this.debugLog(
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
this.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
376
|
+
if (e.message.includes("400")) {
|
|
377
|
+
this.errorLog("Failed to Discover Devices: Bad Request");
|
|
378
|
+
this.debugLog(
|
|
379
|
+
"The client has issued an invalid request. This is commonly used to specify validation errors in a request payload.",
|
|
380
|
+
);
|
|
381
|
+
} else if (e.message.includes("401")) {
|
|
382
|
+
this.errorLog("Failed to Discover Devices: Unauthorized Request");
|
|
383
|
+
this.debugLog(
|
|
384
|
+
"Authorization for the API is required, but the request has not been authenticated.",
|
|
385
|
+
);
|
|
386
|
+
} else if (e.message.includes("403")) {
|
|
387
|
+
this.errorLog("Failed to Discover Devices: Forbidden Request");
|
|
388
|
+
this.debugLog(
|
|
389
|
+
"The request has been authenticated but does not have appropriate permissions, or a requested resource is not found.",
|
|
390
|
+
);
|
|
391
|
+
} else if (e.message.includes("404")) {
|
|
392
|
+
this.errorLog("Failed to Discover Devices: Requst Not Found");
|
|
393
|
+
this.debugLog("Specifies the requested path does not exist.");
|
|
394
|
+
} else if (e.message.includes("406")) {
|
|
395
|
+
this.errorLog("Failed to Discover Devices: Request Not Acceptable");
|
|
396
|
+
this.debugLog(
|
|
397
|
+
"The client has requested a MIME type via the Accept header for a value not supported by the server.",
|
|
398
|
+
);
|
|
399
|
+
} else if (e.message.includes("415")) {
|
|
400
|
+
this.errorLog("Failed to Discover Devices: Unsupported Requst Header");
|
|
401
|
+
this.debugLog(
|
|
402
|
+
"The client has defined a contentType header that is not supported by the server.",
|
|
403
|
+
);
|
|
404
|
+
} else if (e.message.includes("422")) {
|
|
405
|
+
this.errorLog("Failed to Discover Devices: Unprocessable Entity");
|
|
406
|
+
this.debugLog(
|
|
407
|
+
"The client has made a valid request, but the server cannot process it." +
|
|
408
|
+
" This is often used for APIs for which certain limits have been exceeded.",
|
|
409
|
+
);
|
|
410
|
+
} else if (e.message.includes("429")) {
|
|
411
|
+
this.errorLog("Failed to Discover Devices: Too Many Requests");
|
|
412
|
+
this.debugLog(
|
|
413
|
+
"The client has exceeded the number of requests allowed for a given time window.",
|
|
414
|
+
);
|
|
415
|
+
} else if (e.message.includes("500")) {
|
|
416
|
+
this.errorLog("Failed to Discover Devices: Internal Server Error");
|
|
417
|
+
this.debugLog(
|
|
418
|
+
"An unexpected error on the SmartThings servers has occurred. These errors should be rare.",
|
|
419
|
+
);
|
|
335
420
|
} else {
|
|
336
|
-
this.errorLog(
|
|
421
|
+
this.errorLog("Failed to Discover Devices");
|
|
337
422
|
}
|
|
338
|
-
if (this.platformLogging ===
|
|
339
|
-
this.errorLog(
|
|
423
|
+
if (this.platformLogging === "debug") {
|
|
424
|
+
this.errorLog(
|
|
425
|
+
`Failed to Discover Devices, Error Message: ${JSON.stringify(
|
|
426
|
+
e.message,
|
|
427
|
+
)}`,
|
|
428
|
+
);
|
|
340
429
|
}
|
|
341
|
-
if (this.platformLogging ===
|
|
430
|
+
if (this.platformLogging === "debugMode") {
|
|
342
431
|
this.errorLog(`Failed to Discover Devices, Error: ${JSON.stringify(e)}`);
|
|
343
432
|
}
|
|
344
433
|
}
|
|
345
434
|
|
|
346
|
-
private createDevice(device: device & devicesConfig) {
|
|
435
|
+
private createDevice(device: settings.device & settings.devicesConfig) {
|
|
347
436
|
switch (device.deviceType!) {
|
|
348
|
-
case
|
|
437
|
+
case "Humidifier":
|
|
349
438
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
350
439
|
this.createHumidifier(device);
|
|
351
440
|
break;
|
|
352
|
-
case
|
|
441
|
+
case "Hub Mini":
|
|
353
442
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
354
443
|
break;
|
|
355
|
-
case
|
|
444
|
+
case "Hub Plus":
|
|
356
445
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
357
446
|
break;
|
|
358
|
-
case
|
|
447
|
+
case "Bot":
|
|
359
448
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
360
449
|
this.createBot(device);
|
|
361
450
|
break;
|
|
362
|
-
case
|
|
451
|
+
case "Meter":
|
|
363
452
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
364
453
|
this.createMeter(device);
|
|
365
454
|
break;
|
|
366
|
-
case
|
|
455
|
+
case "Motion Sensor":
|
|
367
456
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
368
457
|
this.createMotion(device);
|
|
369
458
|
break;
|
|
370
|
-
case
|
|
459
|
+
case "Contact Sensor":
|
|
371
460
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
372
461
|
this.createContact(device);
|
|
373
462
|
break;
|
|
374
|
-
case
|
|
463
|
+
case "Curtain":
|
|
375
464
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
376
465
|
this.createCurtain(device);
|
|
377
466
|
break;
|
|
378
|
-
case
|
|
467
|
+
case "Plug":
|
|
379
468
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
380
469
|
this.createPlug(device);
|
|
381
470
|
break;
|
|
382
|
-
case
|
|
471
|
+
case "Color Bulb":
|
|
383
472
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
384
473
|
this.createColorBulb(device);
|
|
385
474
|
break;
|
|
386
|
-
case
|
|
475
|
+
case "Indoor Cam":
|
|
387
476
|
this.deviceInfo(device);
|
|
388
477
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
389
|
-
this.warnLog(
|
|
478
|
+
this.warnLog(
|
|
479
|
+
`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`,
|
|
480
|
+
);
|
|
390
481
|
break;
|
|
391
|
-
case
|
|
392
|
-
this.debugLog(
|
|
482
|
+
case "Remote":
|
|
483
|
+
this.debugLog(
|
|
484
|
+
`Discovered ${device.deviceType}: ${device.deviceId} is Not Supported.`,
|
|
485
|
+
);
|
|
393
486
|
break;
|
|
394
487
|
default:
|
|
395
488
|
this.deviceInfo(device);
|
|
396
|
-
this.warnLog(
|
|
397
|
-
|
|
489
|
+
this.warnLog(
|
|
490
|
+
`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`,
|
|
491
|
+
);
|
|
492
|
+
this.warnLog("Submit Feature Requests Here: https://git.io/JL14Z");
|
|
398
493
|
}
|
|
399
494
|
}
|
|
400
495
|
|
|
401
|
-
private createIRDevice(device: irdevice & devicesConfig) {
|
|
496
|
+
private createIRDevice(device: settings.irdevice & settings.devicesConfig) {
|
|
402
497
|
switch (device.remoteType!) {
|
|
403
|
-
case
|
|
404
|
-
case
|
|
405
|
-
case
|
|
406
|
-
case
|
|
407
|
-
case
|
|
408
|
-
case
|
|
409
|
-
case
|
|
410
|
-
case
|
|
411
|
-
case
|
|
412
|
-
case
|
|
413
|
-
case
|
|
414
|
-
case
|
|
498
|
+
case "TV":
|
|
499
|
+
case "DIY TV":
|
|
500
|
+
case "Projector":
|
|
501
|
+
case "DIY Projector":
|
|
502
|
+
case "Set Top Box":
|
|
503
|
+
case "DIY Set Top Box":
|
|
504
|
+
case "IPTV":
|
|
505
|
+
case "DIY IPTV":
|
|
506
|
+
case "DVD":
|
|
507
|
+
case "DIY DVD":
|
|
508
|
+
case "Speaker":
|
|
509
|
+
case "DIY Speaker":
|
|
415
510
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
416
511
|
this.createTV(device);
|
|
417
512
|
break;
|
|
418
|
-
case
|
|
419
|
-
case
|
|
513
|
+
case "Fan":
|
|
514
|
+
case "DIY Fan":
|
|
420
515
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
421
516
|
this.createFan(device);
|
|
422
517
|
break;
|
|
423
|
-
case
|
|
424
|
-
case
|
|
518
|
+
case "Air Conditioner":
|
|
519
|
+
case "DIY Air Conditioner":
|
|
425
520
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
426
521
|
this.createAirConditioner(device);
|
|
427
522
|
break;
|
|
428
|
-
case
|
|
429
|
-
case
|
|
523
|
+
case "Light":
|
|
524
|
+
case "DIY Light":
|
|
430
525
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
431
526
|
this.createLight(device);
|
|
432
527
|
break;
|
|
433
|
-
case
|
|
434
|
-
case
|
|
528
|
+
case "Air Purifier":
|
|
529
|
+
case "DIY Air Purifier":
|
|
435
530
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
436
531
|
this.createAirPurifier(device);
|
|
437
532
|
break;
|
|
438
|
-
case
|
|
439
|
-
case
|
|
533
|
+
case "Water Heater":
|
|
534
|
+
case "DIY Water Heater":
|
|
440
535
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
441
536
|
this.createWaterHeater(device);
|
|
442
537
|
break;
|
|
443
|
-
case
|
|
444
|
-
case
|
|
538
|
+
case "Vacuum Cleaner":
|
|
539
|
+
case "DIY Vacuum Cleaner":
|
|
445
540
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
446
541
|
this.createVacuumCleaner(device);
|
|
447
542
|
break;
|
|
448
|
-
case
|
|
449
|
-
case
|
|
543
|
+
case "Camera":
|
|
544
|
+
case "DIY Camera":
|
|
450
545
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
451
546
|
this.createCamera(device);
|
|
452
547
|
break;
|
|
453
|
-
case
|
|
548
|
+
case "Others":
|
|
454
549
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
455
550
|
this.createOthers(device);
|
|
456
551
|
break;
|
|
457
552
|
default:
|
|
458
553
|
this.deviceInfo(device);
|
|
459
|
-
this.warnLog(
|
|
460
|
-
|
|
554
|
+
this.warnLog(
|
|
555
|
+
`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`,
|
|
556
|
+
);
|
|
557
|
+
this.warnLog("Submit Feature Requests Here: https://git.io/JL14Z");
|
|
461
558
|
}
|
|
462
559
|
}
|
|
463
560
|
|
|
464
|
-
private registerDevice(device: device & devicesConfig) {
|
|
561
|
+
private registerDevice(device: settings.device & settings.devicesConfig) {
|
|
465
562
|
if (!device.hide_device && device.enableCloudService && device.ble) {
|
|
466
563
|
this.registeringDevice = true;
|
|
467
|
-
this.debugLog(
|
|
468
|
-
|
|
564
|
+
this.debugLog(
|
|
565
|
+
`Device: ${device.deviceName} Both OpenAPI and BLE Connections Enabled`,
|
|
566
|
+
);
|
|
567
|
+
} else if (
|
|
568
|
+
!device.hide_device &&
|
|
569
|
+
device.deviceId &&
|
|
570
|
+
device.configDeviceType &&
|
|
571
|
+
device.configDeviceName &&
|
|
572
|
+
!device.enableCloudService
|
|
573
|
+
) {
|
|
469
574
|
this.registeringDevice = true;
|
|
470
575
|
this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled`);
|
|
471
|
-
} else if (
|
|
576
|
+
} else if (
|
|
577
|
+
!device.hide_device &&
|
|
578
|
+
device.enableCloudService &&
|
|
579
|
+
!device.ble
|
|
580
|
+
) {
|
|
472
581
|
this.registeringDevice = true;
|
|
473
582
|
this.debugLog(`Device: ${device.deviceName} OpenAPI Connection Enabled`);
|
|
474
583
|
} else {
|
|
475
584
|
this.registeringDevice = false;
|
|
476
|
-
this.debugLog(
|
|
585
|
+
this.debugLog(
|
|
586
|
+
`Device: ${device.deviceName} Neither OpenAPI and BLE Enabled`,
|
|
587
|
+
);
|
|
477
588
|
}
|
|
478
589
|
return this.registeringDevice;
|
|
479
590
|
}
|
|
480
591
|
|
|
481
|
-
private async createHumidifier(device: device & devicesConfig) {
|
|
482
|
-
const uuid = this.api.hap.uuid.generate(
|
|
592
|
+
private async createHumidifier(device: settings.device & settings.devicesConfig) {
|
|
593
|
+
const uuid = this.api.hap.uuid.generate(
|
|
594
|
+
`${device.deviceId}-${device.deviceType}`,
|
|
595
|
+
);
|
|
483
596
|
|
|
484
597
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
485
598
|
// the cached devices we stored in the `configureAccessory` method above
|
|
486
|
-
const existingAccessory = this.accessories.find(
|
|
599
|
+
const existingAccessory = this.accessories.find(
|
|
600
|
+
(accessory) => accessory.UUID === uuid,
|
|
601
|
+
);
|
|
487
602
|
|
|
488
603
|
if (existingAccessory) {
|
|
489
604
|
// the accessory already exists
|
|
490
605
|
if (this.registerDevice(device)) {
|
|
491
|
-
this.infoLog(
|
|
606
|
+
this.infoLog(
|
|
607
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
608
|
+
);
|
|
492
609
|
|
|
493
610
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
494
611
|
//existingAccessory.context.firmwareRevision = firmware;
|
|
@@ -502,13 +619,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
502
619
|
// create the accessory handler for the restored accessory
|
|
503
620
|
// this is imported from `platformAccessory.ts`
|
|
504
621
|
new Humidifier(this, existingAccessory, device);
|
|
505
|
-
this.debugLog(
|
|
622
|
+
this.debugLog(
|
|
623
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
|
|
624
|
+
);
|
|
506
625
|
} else {
|
|
507
626
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
508
627
|
}
|
|
509
628
|
} else if (this.registerDevice(device)) {
|
|
510
629
|
// the accessory does not yet exist, so we need to create it
|
|
511
|
-
this.infoLog(
|
|
630
|
+
this.infoLog(
|
|
631
|
+
`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
|
|
632
|
+
);
|
|
512
633
|
|
|
513
634
|
// create a new accessory
|
|
514
635
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -524,27 +645,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
524
645
|
// create the accessory handler for the newly create accessory
|
|
525
646
|
// this is imported from `platformAccessory.ts`
|
|
526
647
|
new Humidifier(this, accessory, device);
|
|
527
|
-
this.debugLog(
|
|
648
|
+
this.debugLog(
|
|
649
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
|
|
650
|
+
);
|
|
528
651
|
|
|
529
652
|
// link the accessory to your platform
|
|
530
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
653
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
654
|
+
accessory,
|
|
655
|
+
]);
|
|
531
656
|
this.accessories.push(accessory);
|
|
532
657
|
} else {
|
|
533
|
-
this.debugLog(
|
|
658
|
+
this.debugLog(
|
|
659
|
+
`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
|
|
660
|
+
);
|
|
534
661
|
}
|
|
535
662
|
}
|
|
536
663
|
|
|
537
|
-
private async createBot(device: device & devicesConfig) {
|
|
538
|
-
const uuid = this.api.hap.uuid.generate(
|
|
664
|
+
private async createBot(device: settings.device & settings.devicesConfig) {
|
|
665
|
+
const uuid = this.api.hap.uuid.generate(
|
|
666
|
+
`${device.deviceId}-${device.deviceType}`,
|
|
667
|
+
);
|
|
539
668
|
|
|
540
669
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
541
670
|
// the cached devices we stored in the `configureAccessory` method above
|
|
542
|
-
const existingAccessory = this.accessories.find(
|
|
671
|
+
const existingAccessory = this.accessories.find(
|
|
672
|
+
(accessory) => accessory.UUID === uuid,
|
|
673
|
+
);
|
|
543
674
|
|
|
544
675
|
if (existingAccessory) {
|
|
545
676
|
// the accessory already exists
|
|
546
677
|
if (this.registerDevice(device)) {
|
|
547
|
-
this.infoLog(
|
|
678
|
+
this.infoLog(
|
|
679
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
680
|
+
);
|
|
548
681
|
|
|
549
682
|
this.debugLog(JSON.stringify(device.bot?.mode));
|
|
550
683
|
|
|
@@ -559,13 +692,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
559
692
|
// create the accessory handler for the restored accessory
|
|
560
693
|
// this is imported from `platformAccessory.ts`
|
|
561
694
|
new Bot(this, existingAccessory, device);
|
|
562
|
-
this.debugLog(
|
|
695
|
+
this.debugLog(
|
|
696
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
|
|
697
|
+
);
|
|
563
698
|
} else {
|
|
564
699
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
565
700
|
}
|
|
566
701
|
} else if (this.registerDevice(device)) {
|
|
567
702
|
// the accessory does not yet exist, so we need to create it
|
|
568
|
-
this.infoLog(
|
|
703
|
+
this.infoLog(
|
|
704
|
+
`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
|
|
705
|
+
);
|
|
569
706
|
|
|
570
707
|
this.debugLog(JSON.stringify(device.bot?.mode));
|
|
571
708
|
|
|
@@ -584,27 +721,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
584
721
|
// create the accessory handler for the newly create accessory
|
|
585
722
|
// this is imported from `platformAccessory.ts`
|
|
586
723
|
new Bot(this, accessory, device);
|
|
587
|
-
this.debugLog(
|
|
724
|
+
this.debugLog(
|
|
725
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
|
|
726
|
+
);
|
|
588
727
|
|
|
589
728
|
// link the accessory to your platform
|
|
590
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
729
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
730
|
+
accessory,
|
|
731
|
+
]);
|
|
591
732
|
this.accessories.push(accessory);
|
|
592
733
|
} else {
|
|
593
|
-
this.debugLog(
|
|
734
|
+
this.debugLog(
|
|
735
|
+
`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
|
|
736
|
+
);
|
|
594
737
|
}
|
|
595
738
|
}
|
|
596
739
|
|
|
597
|
-
private async createMeter(device: device & devicesConfig) {
|
|
598
|
-
const uuid = this.api.hap.uuid.generate(
|
|
740
|
+
private async createMeter(device: settings.device & settings.devicesConfig) {
|
|
741
|
+
const uuid = this.api.hap.uuid.generate(
|
|
742
|
+
`${device.deviceId}-${device.deviceType}`,
|
|
743
|
+
);
|
|
599
744
|
|
|
600
745
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
601
746
|
// the cached devices we stored in the `configureAccessory` method above
|
|
602
|
-
const existingAccessory = this.accessories.find(
|
|
747
|
+
const existingAccessory = this.accessories.find(
|
|
748
|
+
(accessory) => accessory.UUID === uuid,
|
|
749
|
+
);
|
|
603
750
|
|
|
604
751
|
if (existingAccessory) {
|
|
605
752
|
// the accessory already exists
|
|
606
753
|
if (this.registerDevice(device)) {
|
|
607
|
-
this.infoLog(
|
|
754
|
+
this.infoLog(
|
|
755
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
756
|
+
);
|
|
608
757
|
|
|
609
758
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
610
759
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -617,13 +766,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
617
766
|
// create the accessory handler for the restored accessory
|
|
618
767
|
// this is imported from `platformAccessory.ts`
|
|
619
768
|
new Meter(this, existingAccessory, device);
|
|
620
|
-
this.debugLog(
|
|
769
|
+
this.debugLog(
|
|
770
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
|
|
771
|
+
);
|
|
621
772
|
} else {
|
|
622
773
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
623
774
|
}
|
|
624
775
|
} else if (this.registerDevice(device)) {
|
|
625
776
|
// the accessory does not yet exist, so we need to create it
|
|
626
|
-
this.infoLog(
|
|
777
|
+
this.infoLog(
|
|
778
|
+
`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
|
|
779
|
+
);
|
|
627
780
|
|
|
628
781
|
// create a new accessory
|
|
629
782
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -639,27 +792,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
639
792
|
// create the accessory handler for the newly create accessory
|
|
640
793
|
// this is imported from `platformAccessory.ts`
|
|
641
794
|
new Meter(this, accessory, device);
|
|
642
|
-
this.debugLog(
|
|
795
|
+
this.debugLog(
|
|
796
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
|
|
797
|
+
);
|
|
643
798
|
|
|
644
799
|
// link the accessory to your platform
|
|
645
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
800
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
801
|
+
accessory,
|
|
802
|
+
]);
|
|
646
803
|
this.accessories.push(accessory);
|
|
647
804
|
} else {
|
|
648
|
-
this.debugLog(
|
|
805
|
+
this.debugLog(
|
|
806
|
+
`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
|
|
807
|
+
);
|
|
649
808
|
}
|
|
650
809
|
}
|
|
651
810
|
|
|
652
|
-
private async createMotion(device: device & devicesConfig) {
|
|
653
|
-
const uuid = this.api.hap.uuid.generate(
|
|
811
|
+
private async createMotion(device: settings.device & settings.devicesConfig) {
|
|
812
|
+
const uuid = this.api.hap.uuid.generate(
|
|
813
|
+
`${device.deviceId}-${device.deviceType}`,
|
|
814
|
+
);
|
|
654
815
|
|
|
655
816
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
656
817
|
// the cached devices we stored in the `configureAccessory` method above
|
|
657
|
-
const existingAccessory = this.accessories.find(
|
|
818
|
+
const existingAccessory = this.accessories.find(
|
|
819
|
+
(accessory) => accessory.UUID === uuid,
|
|
820
|
+
);
|
|
658
821
|
|
|
659
822
|
if (existingAccessory) {
|
|
660
823
|
// the accessory already exists
|
|
661
824
|
if (this.registerDevice(device)) {
|
|
662
|
-
this.infoLog(
|
|
825
|
+
this.infoLog(
|
|
826
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
827
|
+
);
|
|
663
828
|
|
|
664
829
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
665
830
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -672,13 +837,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
672
837
|
// create the accessory handler for the restored accessory
|
|
673
838
|
// this is imported from `platformAccessory.ts`
|
|
674
839
|
new Motion(this, existingAccessory, device);
|
|
675
|
-
this.debugLog(
|
|
840
|
+
this.debugLog(
|
|
841
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
|
|
842
|
+
);
|
|
676
843
|
} else {
|
|
677
844
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
678
845
|
}
|
|
679
846
|
} else if (this.registerDevice(device)) {
|
|
680
847
|
// the accessory does not yet exist, so we need to create it
|
|
681
|
-
this.infoLog(
|
|
848
|
+
this.infoLog(
|
|
849
|
+
`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
|
|
850
|
+
);
|
|
682
851
|
|
|
683
852
|
// create a new accessory
|
|
684
853
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -694,27 +863,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
694
863
|
// create the accessory handler for the newly create accessory
|
|
695
864
|
// this is imported from `platformAccessory.ts`
|
|
696
865
|
new Motion(this, accessory, device);
|
|
697
|
-
this.debugLog(
|
|
866
|
+
this.debugLog(
|
|
867
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
|
|
868
|
+
);
|
|
698
869
|
|
|
699
870
|
// link the accessory to your platform
|
|
700
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
871
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
872
|
+
accessory,
|
|
873
|
+
]);
|
|
701
874
|
this.accessories.push(accessory);
|
|
702
875
|
} else {
|
|
703
|
-
this.debugLog(
|
|
876
|
+
this.debugLog(
|
|
877
|
+
`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
|
|
878
|
+
);
|
|
704
879
|
}
|
|
705
880
|
}
|
|
706
881
|
|
|
707
|
-
private async createContact(device: device & devicesConfig) {
|
|
708
|
-
const uuid = this.api.hap.uuid.generate(
|
|
882
|
+
private async createContact(device: settings.device & settings.devicesConfig) {
|
|
883
|
+
const uuid = this.api.hap.uuid.generate(
|
|
884
|
+
`${device.deviceId}-${device.deviceType}`,
|
|
885
|
+
);
|
|
709
886
|
|
|
710
887
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
711
888
|
// the cached devices we stored in the `configureAccessory` method above
|
|
712
|
-
const existingAccessory = this.accessories.find(
|
|
889
|
+
const existingAccessory = this.accessories.find(
|
|
890
|
+
(accessory) => accessory.UUID === uuid,
|
|
891
|
+
);
|
|
713
892
|
|
|
714
893
|
if (existingAccessory) {
|
|
715
894
|
// the accessory already exists
|
|
716
895
|
if (this.registerDevice(device)) {
|
|
717
|
-
this.infoLog(
|
|
896
|
+
this.infoLog(
|
|
897
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
898
|
+
);
|
|
718
899
|
|
|
719
900
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
720
901
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -727,13 +908,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
727
908
|
// create the accessory handler for the restored accessory
|
|
728
909
|
// this is imported from `platformAccessory.ts`
|
|
729
910
|
new Contact(this, existingAccessory, device);
|
|
730
|
-
this.debugLog(
|
|
911
|
+
this.debugLog(
|
|
912
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
|
|
913
|
+
);
|
|
731
914
|
} else {
|
|
732
915
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
733
916
|
}
|
|
734
917
|
} else if (this.registerDevice(device)) {
|
|
735
918
|
// the accessory does not yet exist, so we need to create it
|
|
736
|
-
this.infoLog(
|
|
919
|
+
this.infoLog(
|
|
920
|
+
`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
|
|
921
|
+
);
|
|
737
922
|
|
|
738
923
|
// create a new accessory
|
|
739
924
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -749,27 +934,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
749
934
|
// create the accessory handler for the newly create accessory
|
|
750
935
|
// this is imported from `platformAccessory.ts`
|
|
751
936
|
new Contact(this, accessory, device);
|
|
752
|
-
this.debugLog(
|
|
937
|
+
this.debugLog(
|
|
938
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
|
|
939
|
+
);
|
|
753
940
|
|
|
754
941
|
// link the accessory to your platform
|
|
755
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
942
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
943
|
+
accessory,
|
|
944
|
+
]);
|
|
756
945
|
this.accessories.push(accessory);
|
|
757
946
|
} else {
|
|
758
|
-
this.debugLog(
|
|
947
|
+
this.debugLog(
|
|
948
|
+
`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
|
|
949
|
+
);
|
|
759
950
|
}
|
|
760
951
|
}
|
|
761
952
|
|
|
762
|
-
private async createCurtain(device: device & devicesConfig) {
|
|
763
|
-
const uuid = this.api.hap.uuid.generate(
|
|
953
|
+
private async createCurtain(device: settings.device & settings.devicesConfig) {
|
|
954
|
+
const uuid = this.api.hap.uuid.generate(
|
|
955
|
+
`${device.deviceId}-${device.deviceType}`,
|
|
956
|
+
);
|
|
764
957
|
|
|
765
958
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
766
959
|
// the cached devices we stored in the `configureAccessory` method above
|
|
767
|
-
const existingAccessory = this.accessories.find(
|
|
960
|
+
const existingAccessory = this.accessories.find(
|
|
961
|
+
(accessory) => accessory.UUID === uuid,
|
|
962
|
+
);
|
|
768
963
|
|
|
769
964
|
if (existingAccessory) {
|
|
770
965
|
// the accessory already exists
|
|
771
966
|
if (this.isCurtainGrouped(device)) {
|
|
772
|
-
this.infoLog(
|
|
967
|
+
this.infoLog(
|
|
968
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
969
|
+
);
|
|
773
970
|
|
|
774
971
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
775
972
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -782,22 +979,30 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
782
979
|
// create the accessory handler for the restored accessory
|
|
783
980
|
// this is imported from `platformAccessory.ts`
|
|
784
981
|
new Curtain(this, existingAccessory, device);
|
|
785
|
-
this.debugLog(
|
|
982
|
+
this.debugLog(
|
|
983
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
|
|
984
|
+
);
|
|
786
985
|
} else {
|
|
787
986
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
788
987
|
}
|
|
789
988
|
} else if (this.isCurtainGrouped(device)) {
|
|
790
989
|
// the accessory does not yet exist, so we need to create it
|
|
791
|
-
this.infoLog(
|
|
990
|
+
this.infoLog(
|
|
991
|
+
`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
|
|
992
|
+
);
|
|
792
993
|
|
|
793
994
|
if (device.group && !device.curtain?.disable_group) {
|
|
794
995
|
this.debugLog(`Your Curtains are grouped
|
|
795
996
|
, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
796
997
|
} else {
|
|
797
998
|
if (device.master) {
|
|
798
|
-
this.debugLog(
|
|
999
|
+
this.debugLog(
|
|
1000
|
+
`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`,
|
|
1001
|
+
);
|
|
799
1002
|
} else {
|
|
800
|
-
this.debugLog(
|
|
1003
|
+
this.debugLog(
|
|
1004
|
+
`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`,
|
|
1005
|
+
);
|
|
801
1006
|
}
|
|
802
1007
|
}
|
|
803
1008
|
|
|
@@ -815,40 +1020,58 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
815
1020
|
// create the accessory handler for the newly create accessory
|
|
816
1021
|
// this is imported from `platformAccessory.ts`
|
|
817
1022
|
new Curtain(this, accessory, device);
|
|
818
|
-
this.debugLog(
|
|
1023
|
+
this.debugLog(
|
|
1024
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
|
|
1025
|
+
);
|
|
819
1026
|
|
|
820
1027
|
// link the accessory to your platform
|
|
821
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
1028
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1029
|
+
accessory,
|
|
1030
|
+
]);
|
|
822
1031
|
this.accessories.push(accessory);
|
|
823
1032
|
} else {
|
|
824
|
-
this.debugLog(
|
|
1033
|
+
this.debugLog(
|
|
1034
|
+
`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
|
|
1035
|
+
);
|
|
825
1036
|
}
|
|
826
1037
|
}
|
|
827
1038
|
|
|
828
|
-
private isCurtainGrouped(device: device & devicesConfig) {
|
|
829
|
-
this.debugLog(
|
|
830
|
-
|
|
1039
|
+
private isCurtainGrouped(device: settings.device & settings.devicesConfig) {
|
|
1040
|
+
this.debugLog(
|
|
1041
|
+
`deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},` +
|
|
1042
|
+
` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}`,
|
|
1043
|
+
);
|
|
831
1044
|
|
|
832
1045
|
if (device.group && !device.curtain?.disable_group) {
|
|
833
|
-
this.debugLog(
|
|
1046
|
+
this.debugLog(
|
|
1047
|
+
`[Curtain Config] disable_group: ${device.curtain?.disable_group}`,
|
|
1048
|
+
);
|
|
834
1049
|
return device.master && this.registerDevice(device);
|
|
835
1050
|
} else {
|
|
836
|
-
this.debugLog(
|
|
1051
|
+
this.debugLog(
|
|
1052
|
+
`[Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`,
|
|
1053
|
+
);
|
|
837
1054
|
return this.registerDevice(device);
|
|
838
1055
|
}
|
|
839
1056
|
}
|
|
840
1057
|
|
|
841
|
-
private async createPlug(device: device & devicesConfig) {
|
|
842
|
-
const uuid = this.api.hap.uuid.generate(
|
|
1058
|
+
private async createPlug(device: settings.device & settings.devicesConfig) {
|
|
1059
|
+
const uuid = this.api.hap.uuid.generate(
|
|
1060
|
+
`${device.deviceId}-${device.deviceType}`,
|
|
1061
|
+
);
|
|
843
1062
|
|
|
844
1063
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
845
1064
|
// the cached devices we stored in the `configureAccessory` method above
|
|
846
|
-
const existingAccessory = this.accessories.find(
|
|
1065
|
+
const existingAccessory = this.accessories.find(
|
|
1066
|
+
(accessory) => accessory.UUID === uuid,
|
|
1067
|
+
);
|
|
847
1068
|
|
|
848
1069
|
if (existingAccessory) {
|
|
849
1070
|
// the accessory already exists
|
|
850
1071
|
if (!device.hide_device && device.enableCloudService) {
|
|
851
|
-
this.infoLog(
|
|
1072
|
+
this.infoLog(
|
|
1073
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
1074
|
+
);
|
|
852
1075
|
|
|
853
1076
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
854
1077
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -861,13 +1084,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
861
1084
|
// create the accessory handler for the restored accessory
|
|
862
1085
|
// this is imported from `platformAccessory.ts`
|
|
863
1086
|
new Plug(this, existingAccessory, device);
|
|
864
|
-
this.debugLog(
|
|
1087
|
+
this.debugLog(
|
|
1088
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
|
|
1089
|
+
);
|
|
865
1090
|
} else {
|
|
866
1091
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
867
1092
|
}
|
|
868
1093
|
} else if (!device.hide_device && device.enableCloudService) {
|
|
869
1094
|
// the accessory does not yet exist, so we need to create it
|
|
870
|
-
this.infoLog(
|
|
1095
|
+
this.infoLog(
|
|
1096
|
+
`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
|
|
1097
|
+
);
|
|
871
1098
|
|
|
872
1099
|
// create a new accessory
|
|
873
1100
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -883,27 +1110,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
883
1110
|
// create the accessory handler for the newly create accessory
|
|
884
1111
|
// this is imported from `platformAccessory.ts`
|
|
885
1112
|
new Plug(this, accessory, device);
|
|
886
|
-
this.debugLog(
|
|
1113
|
+
this.debugLog(
|
|
1114
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
|
|
1115
|
+
);
|
|
887
1116
|
|
|
888
1117
|
// link the accessory to your platform
|
|
889
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
1118
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1119
|
+
accessory,
|
|
1120
|
+
]);
|
|
890
1121
|
this.accessories.push(accessory);
|
|
891
1122
|
} else {
|
|
892
|
-
this.debugLog(
|
|
1123
|
+
this.debugLog(
|
|
1124
|
+
`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
|
|
1125
|
+
);
|
|
893
1126
|
}
|
|
894
1127
|
}
|
|
895
1128
|
|
|
896
|
-
private async createColorBulb(device: device & devicesConfig) {
|
|
897
|
-
const uuid = this.api.hap.uuid.generate(
|
|
1129
|
+
private async createColorBulb(device: settings.device & settings.devicesConfig) {
|
|
1130
|
+
const uuid = this.api.hap.uuid.generate(
|
|
1131
|
+
`${device.deviceId}-${device.deviceType}`,
|
|
1132
|
+
);
|
|
898
1133
|
|
|
899
1134
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
900
1135
|
// the cached devices we stored in the `configureAccessory` method above
|
|
901
|
-
const existingAccessory = this.accessories.find(
|
|
1136
|
+
const existingAccessory = this.accessories.find(
|
|
1137
|
+
(accessory) => accessory.UUID === uuid,
|
|
1138
|
+
);
|
|
902
1139
|
|
|
903
1140
|
if (existingAccessory) {
|
|
904
1141
|
// the accessory already exists
|
|
905
1142
|
if (!device.hide_device && device.enableCloudService) {
|
|
906
|
-
this.infoLog(
|
|
1143
|
+
this.infoLog(
|
|
1144
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
1145
|
+
);
|
|
907
1146
|
|
|
908
1147
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
909
1148
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -916,13 +1155,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
916
1155
|
// create the accessory handler for the restored accessory
|
|
917
1156
|
// this is imported from `platformAccessory.ts`
|
|
918
1157
|
new ColorBulb(this, existingAccessory, device);
|
|
919
|
-
this.debugLog(
|
|
1158
|
+
this.debugLog(
|
|
1159
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
|
|
1160
|
+
);
|
|
920
1161
|
} else {
|
|
921
1162
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
922
1163
|
}
|
|
923
1164
|
} else if (!device.hide_device && device.enableCloudService) {
|
|
924
1165
|
// the accessory does not yet exist, so we need to create it
|
|
925
|
-
this.infoLog(
|
|
1166
|
+
this.infoLog(
|
|
1167
|
+
`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
|
|
1168
|
+
);
|
|
926
1169
|
|
|
927
1170
|
// create a new accessory
|
|
928
1171
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -938,25 +1181,37 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
938
1181
|
// create the accessory handler for the newly create accessory
|
|
939
1182
|
// this is imported from `platformAccessory.ts`
|
|
940
1183
|
new ColorBulb(this, accessory, device);
|
|
941
|
-
this.debugLog(
|
|
1184
|
+
this.debugLog(
|
|
1185
|
+
`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
|
|
1186
|
+
);
|
|
942
1187
|
|
|
943
1188
|
// link the accessory to your platform
|
|
944
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
1189
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1190
|
+
accessory,
|
|
1191
|
+
]);
|
|
945
1192
|
this.accessories.push(accessory);
|
|
946
1193
|
} else {
|
|
947
|
-
this.debugLog(
|
|
1194
|
+
this.debugLog(
|
|
1195
|
+
`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
|
|
1196
|
+
);
|
|
948
1197
|
}
|
|
949
1198
|
}
|
|
950
1199
|
|
|
951
|
-
private async createTV(device: irdevice & devicesConfig) {
|
|
952
|
-
const uuid = this.api.hap.uuid.generate(
|
|
1200
|
+
private async createTV(device: settings.irdevice & settings.devicesConfig) {
|
|
1201
|
+
const uuid = this.api.hap.uuid.generate(
|
|
1202
|
+
`${device.deviceId}-${device.remoteType}`,
|
|
1203
|
+
);
|
|
953
1204
|
|
|
954
1205
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
955
1206
|
// the cached devices we stored in the `configureAccessory` method above
|
|
956
|
-
const existingAccessory = this.accessories.find(
|
|
1207
|
+
const existingAccessory = this.accessories.find(
|
|
1208
|
+
(accessory) => accessory.UUID === uuid,
|
|
1209
|
+
);
|
|
957
1210
|
|
|
958
1211
|
if (!device.hide_device && existingAccessory) {
|
|
959
|
-
this.infoLog(
|
|
1212
|
+
this.infoLog(
|
|
1213
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
1214
|
+
);
|
|
960
1215
|
|
|
961
1216
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
962
1217
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -969,10 +1224,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
969
1224
|
// create the accessory handler for the restored accessory
|
|
970
1225
|
// this is imported from `platformAccessory.ts`
|
|
971
1226
|
new TV(this, existingAccessory, device);
|
|
972
|
-
this.debugLog(
|
|
1227
|
+
this.debugLog(
|
|
1228
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
|
|
1229
|
+
);
|
|
973
1230
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
974
1231
|
// the accessory does not yet exist, so we need to create it
|
|
975
|
-
this.infoLog(
|
|
1232
|
+
this.infoLog(
|
|
1233
|
+
`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
|
|
1234
|
+
);
|
|
976
1235
|
|
|
977
1236
|
// create a new accessory
|
|
978
1237
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -988,31 +1247,41 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
988
1247
|
// create the accessory handler for the newly create accessory
|
|
989
1248
|
// this is imported from `platformAccessory.ts`
|
|
990
1249
|
new TV(this, accessory, device);
|
|
991
|
-
this.debugLog(
|
|
1250
|
+
this.debugLog(
|
|
1251
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
|
|
1252
|
+
);
|
|
992
1253
|
|
|
993
1254
|
/**
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);
|
|
1255
|
+
* Publish as external accessory
|
|
1256
|
+
* Only one TV can exist per bridge, to bypass this limitation, you should
|
|
1257
|
+
* publish your TV as an external accessory.
|
|
1258
|
+
*/
|
|
1259
|
+
this.api.publishExternalAccessories(settings.PLUGIN_NAME, [accessory]);
|
|
999
1260
|
this.accessories.push(accessory);
|
|
1000
1261
|
} else {
|
|
1001
|
-
this.debugLog(
|
|
1262
|
+
this.debugLog(
|
|
1263
|
+
`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
|
|
1264
|
+
);
|
|
1002
1265
|
}
|
|
1003
1266
|
}
|
|
1004
1267
|
|
|
1005
|
-
private async createFan(device: irdevice & devicesConfig) {
|
|
1006
|
-
const uuid = this.api.hap.uuid.generate(
|
|
1268
|
+
private async createFan(device: settings.irdevice & settings.devicesConfig) {
|
|
1269
|
+
const uuid = this.api.hap.uuid.generate(
|
|
1270
|
+
`${device.deviceId}-${device.remoteType}`,
|
|
1271
|
+
);
|
|
1007
1272
|
|
|
1008
1273
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1009
1274
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1010
|
-
const existingAccessory = this.accessories.find(
|
|
1275
|
+
const existingAccessory = this.accessories.find(
|
|
1276
|
+
(accessory) => accessory.UUID === uuid,
|
|
1277
|
+
);
|
|
1011
1278
|
|
|
1012
1279
|
if (existingAccessory) {
|
|
1013
1280
|
// the accessory already exists
|
|
1014
1281
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1015
|
-
this.infoLog(
|
|
1282
|
+
this.infoLog(
|
|
1283
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
1284
|
+
);
|
|
1016
1285
|
|
|
1017
1286
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1018
1287
|
|
|
@@ -1026,13 +1295,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1026
1295
|
// create the accessory handler for the restored accessory
|
|
1027
1296
|
// this is imported from `platformAccessory.ts`
|
|
1028
1297
|
new Fan(this, existingAccessory, device);
|
|
1029
|
-
this.debugLog(
|
|
1298
|
+
this.debugLog(
|
|
1299
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
|
|
1300
|
+
);
|
|
1030
1301
|
} else {
|
|
1031
1302
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1032
1303
|
}
|
|
1033
1304
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1034
1305
|
// the accessory does not yet exist, so we need to create it
|
|
1035
|
-
this.infoLog(
|
|
1306
|
+
this.infoLog(
|
|
1307
|
+
`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
|
|
1308
|
+
);
|
|
1036
1309
|
|
|
1037
1310
|
// create a new accessory
|
|
1038
1311
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1048,27 +1321,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1048
1321
|
// create the accessory handler for the newly create accessory
|
|
1049
1322
|
// this is imported from `platformAccessory.ts`
|
|
1050
1323
|
new Fan(this, accessory, device);
|
|
1051
|
-
this.debugLog(
|
|
1324
|
+
this.debugLog(
|
|
1325
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
|
|
1326
|
+
);
|
|
1052
1327
|
|
|
1053
1328
|
// link the accessory to your platform
|
|
1054
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
1329
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1330
|
+
accessory,
|
|
1331
|
+
]);
|
|
1055
1332
|
this.accessories.push(accessory);
|
|
1056
1333
|
} else {
|
|
1057
|
-
this.debugLog(
|
|
1334
|
+
this.debugLog(
|
|
1335
|
+
`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
|
|
1336
|
+
);
|
|
1058
1337
|
}
|
|
1059
1338
|
}
|
|
1060
1339
|
|
|
1061
|
-
private async createLight(device: irdevice & devicesConfig) {
|
|
1062
|
-
const uuid = this.api.hap.uuid.generate(
|
|
1340
|
+
private async createLight(device: settings.irdevice & settings.devicesConfig) {
|
|
1341
|
+
const uuid = this.api.hap.uuid.generate(
|
|
1342
|
+
`${device.deviceId}-${device.remoteType}`,
|
|
1343
|
+
);
|
|
1063
1344
|
|
|
1064
1345
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1065
1346
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1066
|
-
const existingAccessory = this.accessories.find(
|
|
1347
|
+
const existingAccessory = this.accessories.find(
|
|
1348
|
+
(accessory) => accessory.UUID === uuid,
|
|
1349
|
+
);
|
|
1067
1350
|
|
|
1068
1351
|
if (existingAccessory) {
|
|
1069
1352
|
// the accessory already exists
|
|
1070
1353
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1071
|
-
this.infoLog(
|
|
1354
|
+
this.infoLog(
|
|
1355
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
1356
|
+
);
|
|
1072
1357
|
|
|
1073
1358
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1074
1359
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1081,13 +1366,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1081
1366
|
// create the accessory handler for the restored accessory
|
|
1082
1367
|
// this is imported from `platformAccessory.ts`
|
|
1083
1368
|
new Light(this, existingAccessory, device);
|
|
1084
|
-
this.debugLog(
|
|
1369
|
+
this.debugLog(
|
|
1370
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
|
|
1371
|
+
);
|
|
1085
1372
|
} else {
|
|
1086
1373
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1087
1374
|
}
|
|
1088
1375
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1089
1376
|
// the accessory does not yet exist, so we need to create it
|
|
1090
|
-
this.infoLog(
|
|
1377
|
+
this.infoLog(
|
|
1378
|
+
`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
|
|
1379
|
+
);
|
|
1091
1380
|
|
|
1092
1381
|
// create a new accessory
|
|
1093
1382
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1103,27 +1392,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1103
1392
|
// create the accessory handler for the newly create accessory
|
|
1104
1393
|
// this is imported from `platformAccessory.ts`
|
|
1105
1394
|
new Light(this, accessory, device);
|
|
1106
|
-
this.debugLog(
|
|
1395
|
+
this.debugLog(
|
|
1396
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
|
|
1397
|
+
);
|
|
1107
1398
|
|
|
1108
1399
|
// link the accessory to your platform
|
|
1109
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
1400
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1401
|
+
accessory,
|
|
1402
|
+
]);
|
|
1110
1403
|
this.accessories.push(accessory);
|
|
1111
1404
|
} else {
|
|
1112
|
-
this.debugLog(
|
|
1405
|
+
this.debugLog(
|
|
1406
|
+
`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
|
|
1407
|
+
);
|
|
1113
1408
|
}
|
|
1114
1409
|
}
|
|
1115
1410
|
|
|
1116
|
-
private async createAirConditioner(device: irdevice & devicesConfig) {
|
|
1117
|
-
const uuid = this.api.hap.uuid.generate(
|
|
1411
|
+
private async createAirConditioner(device: settings.irdevice & settings.devicesConfig) {
|
|
1412
|
+
const uuid = this.api.hap.uuid.generate(
|
|
1413
|
+
`${device.deviceId}-${device.remoteType}`,
|
|
1414
|
+
);
|
|
1118
1415
|
|
|
1119
1416
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1120
1417
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1121
|
-
const existingAccessory = this.accessories.find(
|
|
1418
|
+
const existingAccessory = this.accessories.find(
|
|
1419
|
+
(accessory) => accessory.UUID === uuid,
|
|
1420
|
+
);
|
|
1122
1421
|
|
|
1123
1422
|
if (existingAccessory) {
|
|
1124
1423
|
// the accessory already exists
|
|
1125
1424
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1126
|
-
this.infoLog(
|
|
1425
|
+
this.infoLog(
|
|
1426
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
1427
|
+
);
|
|
1127
1428
|
|
|
1128
1429
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1129
1430
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1136,13 +1437,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1136
1437
|
// create the accessory handler for the restored accessory
|
|
1137
1438
|
// this is imported from `platformAccessory.ts`
|
|
1138
1439
|
new AirConditioner(this, existingAccessory, device);
|
|
1139
|
-
this.debugLog(
|
|
1440
|
+
this.debugLog(
|
|
1441
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
|
|
1442
|
+
);
|
|
1140
1443
|
} else {
|
|
1141
1444
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1142
1445
|
}
|
|
1143
1446
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1144
1447
|
// the accessory does not yet exist, so we need to create it
|
|
1145
|
-
this.infoLog(
|
|
1448
|
+
this.infoLog(
|
|
1449
|
+
`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
|
|
1450
|
+
);
|
|
1146
1451
|
|
|
1147
1452
|
// create a new accessory
|
|
1148
1453
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1158,27 +1463,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1158
1463
|
// create the accessory handler for the newly create accessory
|
|
1159
1464
|
// this is imported from `platformAccessory.ts`
|
|
1160
1465
|
new AirConditioner(this, accessory, device);
|
|
1161
|
-
this.debugLog(
|
|
1466
|
+
this.debugLog(
|
|
1467
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
|
|
1468
|
+
);
|
|
1162
1469
|
|
|
1163
1470
|
// link the accessory to your platform
|
|
1164
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
1471
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1472
|
+
accessory,
|
|
1473
|
+
]);
|
|
1165
1474
|
this.accessories.push(accessory);
|
|
1166
1475
|
} else {
|
|
1167
|
-
this.debugLog(
|
|
1476
|
+
this.debugLog(
|
|
1477
|
+
`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
|
|
1478
|
+
);
|
|
1168
1479
|
}
|
|
1169
1480
|
}
|
|
1170
1481
|
|
|
1171
|
-
private async createAirPurifier(device: irdevice & devicesConfig) {
|
|
1172
|
-
const uuid = this.api.hap.uuid.generate(
|
|
1482
|
+
private async createAirPurifier(device: settings.irdevice & settings.devicesConfig) {
|
|
1483
|
+
const uuid = this.api.hap.uuid.generate(
|
|
1484
|
+
`${device.deviceId}-${device.remoteType}`,
|
|
1485
|
+
);
|
|
1173
1486
|
|
|
1174
1487
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1175
1488
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1176
|
-
const existingAccessory = this.accessories.find(
|
|
1489
|
+
const existingAccessory = this.accessories.find(
|
|
1490
|
+
(accessory) => accessory.UUID === uuid,
|
|
1491
|
+
);
|
|
1177
1492
|
|
|
1178
1493
|
if (existingAccessory) {
|
|
1179
1494
|
// the accessory already exists
|
|
1180
1495
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1181
|
-
this.infoLog(
|
|
1496
|
+
this.infoLog(
|
|
1497
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
1498
|
+
);
|
|
1182
1499
|
|
|
1183
1500
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1184
1501
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1191,13 +1508,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1191
1508
|
// create the accessory handler for the restored accessory
|
|
1192
1509
|
// this is imported from `platformAccessory.ts`
|
|
1193
1510
|
new AirPurifier(this, existingAccessory, device);
|
|
1194
|
-
this.debugLog(
|
|
1511
|
+
this.debugLog(
|
|
1512
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
|
|
1513
|
+
);
|
|
1195
1514
|
} else {
|
|
1196
1515
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1197
1516
|
}
|
|
1198
1517
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1199
1518
|
// the accessory does not yet exist, so we need to create it
|
|
1200
|
-
this.infoLog(
|
|
1519
|
+
this.infoLog(
|
|
1520
|
+
`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
|
|
1521
|
+
);
|
|
1201
1522
|
|
|
1202
1523
|
// create a new accessory
|
|
1203
1524
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1213,27 +1534,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1213
1534
|
// create the accessory handler for the newly create accessory
|
|
1214
1535
|
// this is imported from `platformAccessory.ts`
|
|
1215
1536
|
new AirPurifier(this, accessory, device);
|
|
1216
|
-
this.debugLog(
|
|
1537
|
+
this.debugLog(
|
|
1538
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
|
|
1539
|
+
);
|
|
1217
1540
|
|
|
1218
1541
|
// link the accessory to your platform
|
|
1219
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
1542
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1543
|
+
accessory,
|
|
1544
|
+
]);
|
|
1220
1545
|
this.accessories.push(accessory);
|
|
1221
1546
|
} else {
|
|
1222
|
-
this.debugLog(
|
|
1547
|
+
this.debugLog(
|
|
1548
|
+
`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
|
|
1549
|
+
);
|
|
1223
1550
|
}
|
|
1224
1551
|
}
|
|
1225
1552
|
|
|
1226
|
-
private async createWaterHeater(device: irdevice & devicesConfig) {
|
|
1227
|
-
const uuid = this.api.hap.uuid.generate(
|
|
1553
|
+
private async createWaterHeater(device: settings.irdevice & settings.devicesConfig) {
|
|
1554
|
+
const uuid = this.api.hap.uuid.generate(
|
|
1555
|
+
`${device.deviceId}-${device.remoteType}`,
|
|
1556
|
+
);
|
|
1228
1557
|
|
|
1229
1558
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1230
1559
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1231
|
-
const existingAccessory = this.accessories.find(
|
|
1560
|
+
const existingAccessory = this.accessories.find(
|
|
1561
|
+
(accessory) => accessory.UUID === uuid,
|
|
1562
|
+
);
|
|
1232
1563
|
|
|
1233
1564
|
if (existingAccessory) {
|
|
1234
1565
|
// the accessory already exists
|
|
1235
1566
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1236
|
-
this.infoLog(
|
|
1567
|
+
this.infoLog(
|
|
1568
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
1569
|
+
);
|
|
1237
1570
|
|
|
1238
1571
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1239
1572
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1246,13 +1579,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1246
1579
|
// create the accessory handler for the restored accessory
|
|
1247
1580
|
// this is imported from `platformAccessory.ts`
|
|
1248
1581
|
new WaterHeater(this, existingAccessory, device);
|
|
1249
|
-
this.debugLog(
|
|
1582
|
+
this.debugLog(
|
|
1583
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
|
|
1584
|
+
);
|
|
1250
1585
|
} else {
|
|
1251
1586
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1252
1587
|
}
|
|
1253
1588
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1254
1589
|
// the accessory does not yet exist, so we need to create it
|
|
1255
|
-
this.infoLog(
|
|
1590
|
+
this.infoLog(
|
|
1591
|
+
`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
|
|
1592
|
+
);
|
|
1256
1593
|
|
|
1257
1594
|
// create a new accessory
|
|
1258
1595
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1268,27 +1605,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1268
1605
|
// create the accessory handler for the newly create accessory
|
|
1269
1606
|
// this is imported from `platformAccessory.ts`
|
|
1270
1607
|
new WaterHeater(this, accessory, device);
|
|
1271
|
-
this.debugLog(
|
|
1608
|
+
this.debugLog(
|
|
1609
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
|
|
1610
|
+
);
|
|
1272
1611
|
|
|
1273
1612
|
// link the accessory to your platform
|
|
1274
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
1613
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1614
|
+
accessory,
|
|
1615
|
+
]);
|
|
1275
1616
|
this.accessories.push(accessory);
|
|
1276
1617
|
} else {
|
|
1277
|
-
this.debugLog(
|
|
1618
|
+
this.debugLog(
|
|
1619
|
+
`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
|
|
1620
|
+
);
|
|
1278
1621
|
}
|
|
1279
1622
|
}
|
|
1280
1623
|
|
|
1281
|
-
private async createVacuumCleaner(device: irdevice & devicesConfig) {
|
|
1282
|
-
const uuid = this.api.hap.uuid.generate(
|
|
1624
|
+
private async createVacuumCleaner(device: settings.irdevice & settings.devicesConfig) {
|
|
1625
|
+
const uuid = this.api.hap.uuid.generate(
|
|
1626
|
+
`${device.deviceId}-${device.remoteType}`,
|
|
1627
|
+
);
|
|
1283
1628
|
|
|
1284
1629
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1285
1630
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1286
|
-
const existingAccessory = this.accessories.find(
|
|
1631
|
+
const existingAccessory = this.accessories.find(
|
|
1632
|
+
(accessory) => accessory.UUID === uuid,
|
|
1633
|
+
);
|
|
1287
1634
|
|
|
1288
1635
|
if (existingAccessory) {
|
|
1289
1636
|
// the accessory already exists
|
|
1290
1637
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1291
|
-
this.infoLog(
|
|
1638
|
+
this.infoLog(
|
|
1639
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
1640
|
+
);
|
|
1292
1641
|
|
|
1293
1642
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1294
1643
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1301,13 +1650,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1301
1650
|
// create the accessory handler for the restored accessory
|
|
1302
1651
|
// this is imported from `platformAccessory.ts`
|
|
1303
1652
|
new VacuumCleaner(this, existingAccessory, device);
|
|
1304
|
-
this.debugLog(
|
|
1653
|
+
this.debugLog(
|
|
1654
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
|
|
1655
|
+
);
|
|
1305
1656
|
} else {
|
|
1306
1657
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1307
1658
|
}
|
|
1308
1659
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1309
1660
|
// the accessory does not yet exist, so we need to create it
|
|
1310
|
-
this.infoLog(
|
|
1661
|
+
this.infoLog(
|
|
1662
|
+
`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
|
|
1663
|
+
);
|
|
1311
1664
|
|
|
1312
1665
|
// create a new accessory
|
|
1313
1666
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1323,27 +1676,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1323
1676
|
// create the accessory handler for the newly create accessory
|
|
1324
1677
|
// this is imported from `platformAccessory.ts`
|
|
1325
1678
|
new VacuumCleaner(this, accessory, device);
|
|
1326
|
-
this.debugLog(
|
|
1679
|
+
this.debugLog(
|
|
1680
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
|
|
1681
|
+
);
|
|
1327
1682
|
|
|
1328
1683
|
// link the accessory to your platform
|
|
1329
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
1684
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1685
|
+
accessory,
|
|
1686
|
+
]);
|
|
1330
1687
|
this.accessories.push(accessory);
|
|
1331
1688
|
} else {
|
|
1332
|
-
this.debugLog(
|
|
1689
|
+
this.debugLog(
|
|
1690
|
+
`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
|
|
1691
|
+
);
|
|
1333
1692
|
}
|
|
1334
1693
|
}
|
|
1335
1694
|
|
|
1336
|
-
private async createCamera(device: irdevice & devicesConfig) {
|
|
1337
|
-
const uuid = this.api.hap.uuid.generate(
|
|
1695
|
+
private async createCamera(device: settings.irdevice & settings.devicesConfig) {
|
|
1696
|
+
const uuid = this.api.hap.uuid.generate(
|
|
1697
|
+
`${device.deviceId}-${device.remoteType}`,
|
|
1698
|
+
);
|
|
1338
1699
|
|
|
1339
1700
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1340
1701
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1341
|
-
const existingAccessory = this.accessories.find(
|
|
1702
|
+
const existingAccessory = this.accessories.find(
|
|
1703
|
+
(accessory) => accessory.UUID === uuid,
|
|
1704
|
+
);
|
|
1342
1705
|
|
|
1343
1706
|
if (existingAccessory) {
|
|
1344
1707
|
// the accessory already exists
|
|
1345
1708
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1346
|
-
this.infoLog(
|
|
1709
|
+
this.infoLog(
|
|
1710
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
1711
|
+
);
|
|
1347
1712
|
|
|
1348
1713
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1349
1714
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1356,13 +1721,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1356
1721
|
// create the accessory handler for the restored accessory
|
|
1357
1722
|
// this is imported from `platformAccessory.ts`
|
|
1358
1723
|
new Camera(this, existingAccessory, device);
|
|
1359
|
-
this.debugLog(
|
|
1724
|
+
this.debugLog(
|
|
1725
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
|
|
1726
|
+
);
|
|
1360
1727
|
} else {
|
|
1361
1728
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1362
1729
|
}
|
|
1363
1730
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1364
1731
|
// the accessory does not yet exist, so we need to create it
|
|
1365
|
-
this.infoLog(
|
|
1732
|
+
this.infoLog(
|
|
1733
|
+
`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
|
|
1734
|
+
);
|
|
1366
1735
|
|
|
1367
1736
|
// create a new accessory
|
|
1368
1737
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1378,27 +1747,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1378
1747
|
// create the accessory handler for the newly create accessory
|
|
1379
1748
|
// this is imported from `platformAccessory.ts`
|
|
1380
1749
|
new Camera(this, accessory, device);
|
|
1381
|
-
this.debugLog(
|
|
1750
|
+
this.debugLog(
|
|
1751
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
|
|
1752
|
+
);
|
|
1382
1753
|
|
|
1383
1754
|
// link the accessory to your platform
|
|
1384
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
1755
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1756
|
+
accessory,
|
|
1757
|
+
]);
|
|
1385
1758
|
this.accessories.push(accessory);
|
|
1386
1759
|
} else {
|
|
1387
|
-
this.debugLog(
|
|
1760
|
+
this.debugLog(
|
|
1761
|
+
`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
|
|
1762
|
+
);
|
|
1388
1763
|
}
|
|
1389
1764
|
}
|
|
1390
1765
|
|
|
1391
|
-
private async createOthers(device: irdevice & devicesConfig) {
|
|
1392
|
-
const uuid = this.api.hap.uuid.generate(
|
|
1766
|
+
private async createOthers(device: settings.irdevice & settings.devicesConfig) {
|
|
1767
|
+
const uuid = this.api.hap.uuid.generate(
|
|
1768
|
+
`${device.deviceId}-${device.remoteType}`,
|
|
1769
|
+
);
|
|
1393
1770
|
|
|
1394
1771
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1395
1772
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1396
|
-
const existingAccessory = this.accessories.find(
|
|
1773
|
+
const existingAccessory = this.accessories.find(
|
|
1774
|
+
(accessory) => accessory.UUID === uuid,
|
|
1775
|
+
);
|
|
1397
1776
|
|
|
1398
1777
|
if (existingAccessory) {
|
|
1399
1778
|
// the accessory already exists
|
|
1400
1779
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1401
|
-
this.infoLog(
|
|
1780
|
+
this.infoLog(
|
|
1781
|
+
`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
|
|
1782
|
+
);
|
|
1402
1783
|
|
|
1403
1784
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1404
1785
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1411,13 +1792,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1411
1792
|
// create the accessory handler for the restored accessory
|
|
1412
1793
|
// this is imported from `platformAccessory.ts`
|
|
1413
1794
|
new Others(this, existingAccessory, device);
|
|
1414
|
-
this.debugLog(
|
|
1795
|
+
this.debugLog(
|
|
1796
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
|
|
1797
|
+
);
|
|
1415
1798
|
} else {
|
|
1416
1799
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1417
1800
|
}
|
|
1418
1801
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1419
1802
|
// the accessory does not yet exist, so we need to create it
|
|
1420
|
-
this.infoLog(
|
|
1803
|
+
this.infoLog(
|
|
1804
|
+
`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
|
|
1805
|
+
);
|
|
1421
1806
|
|
|
1422
1807
|
// create a new accessory
|
|
1423
1808
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1433,69 +1818,92 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1433
1818
|
// create the accessory handler for the newly create accessory
|
|
1434
1819
|
// this is imported from `platformAccessory.ts`
|
|
1435
1820
|
new Others(this, accessory, device);
|
|
1436
|
-
this.debugLog(
|
|
1821
|
+
this.debugLog(
|
|
1822
|
+
`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
|
|
1823
|
+
);
|
|
1437
1824
|
|
|
1438
1825
|
// link the accessory to your platform
|
|
1439
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
1826
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1827
|
+
accessory,
|
|
1828
|
+
]);
|
|
1440
1829
|
this.accessories.push(accessory);
|
|
1441
1830
|
} else {
|
|
1442
|
-
this.debugLog(
|
|
1831
|
+
this.debugLog(
|
|
1832
|
+
`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
|
|
1833
|
+
);
|
|
1443
1834
|
}
|
|
1444
1835
|
}
|
|
1445
1836
|
|
|
1446
1837
|
public async connectionTypeNewAccessory(
|
|
1447
|
-
device: device & devicesConfig,
|
|
1448
|
-
accessory: PlatformAccessory
|
|
1838
|
+
device: settings.device & settings.devicesConfig,
|
|
1839
|
+
accessory: PlatformAccessory,
|
|
1840
|
+
) {
|
|
1449
1841
|
if (device.ble) {
|
|
1450
|
-
accessory.context.connectionType =
|
|
1842
|
+
accessory.context.connectionType = "BLE";
|
|
1451
1843
|
} else {
|
|
1452
|
-
accessory.context.connectionType =
|
|
1844
|
+
accessory.context.connectionType = "OpenAPI";
|
|
1453
1845
|
}
|
|
1454
1846
|
}
|
|
1455
1847
|
|
|
1456
1848
|
public async connectionTypeExistingAccessory(
|
|
1457
|
-
device: device & devicesConfig,
|
|
1849
|
+
device: settings.device & settings.devicesConfig,
|
|
1458
1850
|
existingAccessory: PlatformAccessory,
|
|
1459
1851
|
) {
|
|
1460
1852
|
if (device.ble) {
|
|
1461
|
-
existingAccessory.context.connectionType =
|
|
1853
|
+
existingAccessory.context.connectionType = "BLE";
|
|
1462
1854
|
} else {
|
|
1463
|
-
existingAccessory.context.connectionType =
|
|
1855
|
+
existingAccessory.context.connectionType = "OpenAPI";
|
|
1464
1856
|
}
|
|
1465
1857
|
}
|
|
1466
1858
|
|
|
1467
|
-
public async connectionTypeNewIRAccessory(
|
|
1468
|
-
accessory
|
|
1469
|
-
accessory.context.connectionType = 'IR wirth OpenAPI';
|
|
1859
|
+
public async connectionTypeNewIRAccessory(accessory: PlatformAccessory) {
|
|
1860
|
+
accessory.context.connectionType = "IR wirth OpenAPI";
|
|
1470
1861
|
}
|
|
1471
1862
|
|
|
1472
1863
|
public async connectionTypeExistingIRAccessory(
|
|
1473
1864
|
existingAccessory: PlatformAccessory,
|
|
1474
1865
|
) {
|
|
1475
|
-
existingAccessory.context.connectionType =
|
|
1866
|
+
existingAccessory.context.connectionType = "IR with OpenAPI";
|
|
1476
1867
|
}
|
|
1477
1868
|
|
|
1478
1869
|
public unregisterPlatformAccessories(existingAccessory: PlatformAccessory) {
|
|
1479
1870
|
// remove platform accessories when no longer present
|
|
1480
|
-
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
|
1481
|
-
|
|
1871
|
+
this.api.unregisterPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1872
|
+
existingAccessory,
|
|
1873
|
+
]);
|
|
1874
|
+
this.infoLog(
|
|
1875
|
+
"Removing existing accessory from cache:",
|
|
1876
|
+
existingAccessory.displayName,
|
|
1877
|
+
);
|
|
1482
1878
|
}
|
|
1483
1879
|
|
|
1484
|
-
public deviceListInfo(devices: deviceResponses) {
|
|
1485
|
-
if (this.platformLogging ===
|
|
1880
|
+
public deviceListInfo(devices: settings.deviceResponses) {
|
|
1881
|
+
if (this.platformLogging === "debug") {
|
|
1486
1882
|
this.warnLog(`deviceListInfoStatus: ${JSON.stringify(devices)}`);
|
|
1487
1883
|
}
|
|
1488
1884
|
}
|
|
1489
1885
|
|
|
1490
|
-
public async deviceInfo(
|
|
1491
|
-
|
|
1886
|
+
public async deviceInfo(
|
|
1887
|
+
device: (settings.irdevice & settings.devicesConfig) | (settings.device & settings.devicesConfig),
|
|
1888
|
+
) {
|
|
1889
|
+
if (this.platformLogging === "debug") {
|
|
1492
1890
|
this.warnLog(JSON.stringify(device));
|
|
1493
|
-
this.deviceStatus = (
|
|
1494
|
-
|
|
1495
|
-
|
|
1891
|
+
this.deviceStatus = (
|
|
1892
|
+
await this.axios.get(`${settings.DeviceURL}/${device.deviceId}/status`)
|
|
1893
|
+
).data;
|
|
1894
|
+
if (this.deviceStatus.message === "success") {
|
|
1895
|
+
this.warnLog(
|
|
1896
|
+
`${device.deviceName} deviceInfoStatus: ${JSON.stringify(
|
|
1897
|
+
this.deviceStatus,
|
|
1898
|
+
)}`,
|
|
1899
|
+
);
|
|
1496
1900
|
} else {
|
|
1497
|
-
this.warnLog(
|
|
1498
|
-
|
|
1901
|
+
this.warnLog(
|
|
1902
|
+
`${device.deviceName} deviceInfoStatus: ${JSON.stringify(
|
|
1903
|
+
this.deviceStatus.message,
|
|
1904
|
+
)}`,
|
|
1905
|
+
);
|
|
1906
|
+
this.warnLog("Unable to retreive deviceInfoStatus.");
|
|
1499
1907
|
}
|
|
1500
1908
|
}
|
|
1501
1909
|
}
|
|
@@ -1505,7 +1913,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1505
1913
|
let Switchbot: new () => any;
|
|
1506
1914
|
let switchbot: any;
|
|
1507
1915
|
try {
|
|
1508
|
-
Switchbot = require(
|
|
1916
|
+
Switchbot = require("node-switchbot");
|
|
1509
1917
|
switchbot = new Switchbot();
|
|
1510
1918
|
} catch (e) {
|
|
1511
1919
|
switchbot = false;
|
|
@@ -1538,15 +1946,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1538
1946
|
|
|
1539
1947
|
debugLog(...log: any[]) {
|
|
1540
1948
|
if (this.enablingPlatfromLogging()) {
|
|
1541
|
-
if (this.platformLogging ===
|
|
1949
|
+
if (this.platformLogging === "debugMode") {
|
|
1542
1950
|
this.log.debug(String(...log));
|
|
1543
|
-
} else if (this.platformLogging ===
|
|
1544
|
-
this.log.info(
|
|
1951
|
+
} else if (this.platformLogging === "debug") {
|
|
1952
|
+
this.log.info("[DEBUG]", String(...log));
|
|
1545
1953
|
}
|
|
1546
1954
|
}
|
|
1547
1955
|
}
|
|
1548
1956
|
|
|
1549
1957
|
enablingPlatfromLogging(): boolean {
|
|
1550
|
-
return
|
|
1958
|
+
return (
|
|
1959
|
+
this.platformLogging?.includes("debug") ||
|
|
1960
|
+
this.platformLogging === "standard"
|
|
1961
|
+
);
|
|
1551
1962
|
}
|
|
1552
1963
|
}
|