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