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