@switchbot/homebridge-switchbot 1.8.2-beta.0 → 1.8.3-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +1 -1
- package/.vscode/extensions.json +5 -0
- package/.vscode/settings.json +15 -0
- package/CHANGELOG.md +7 -0
- package/dist/devices/bots.d.ts +34 -35
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +242 -185
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +50 -50
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +146 -132
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +27 -29
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +139 -116
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +29 -31
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +212 -177
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +33 -33
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +215 -190
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +30 -31
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +125 -101
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +25 -26
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +121 -103
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +23 -23
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +82 -64
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +6 -6
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +106 -80
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +5 -5
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +57 -43
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +5 -5
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +32 -28
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +5 -5
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +46 -39
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +5 -5
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +38 -34
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +5 -5
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +35 -30
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +5 -5
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +92 -77
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +5 -5
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +32 -28
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +5 -5
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +32 -28
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +13 -13
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +269 -184
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +2 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/package.json +4 -3
- package/src/devices/bots.ts +928 -443
- package/src/devices/colorbulb.ts +474 -247
- package/src/devices/contact.ts +382 -209
- package/src/devices/curtains.ts +614 -322
- package/src/devices/humidifiers.ts +595 -324
- package/src/devices/meters.ts +332 -187
- package/src/devices/motion.ts +328 -185
- package/src/devices/plugs.ts +176 -108
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +361 -150
- package/src/irdevices/airpurifiers.ts +179 -81
- package/src/irdevices/cameras.ts +110 -52
- package/src/irdevices/fans.ts +175 -78
- package/src/irdevices/lights.ts +111 -58
- package/src/irdevices/others.ts +138 -63
- package/src/irdevices/tvs.ts +250 -125
- package/src/irdevices/vacuumcleaners.ts +113 -53
- package/src/irdevices/waterheaters.ts +116 -54
- package/src/platform.ts +797 -371
- package/src/settings.ts +18 -24
package/dist/platform.js
CHANGED
|
@@ -1,28 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
23
|
};
|
|
5
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
25
|
exports.SwitchBotPlatform = void 0;
|
|
26
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
27
|
const bots_1 = require("./devices/bots");
|
|
8
|
-
const
|
|
9
|
-
const meters_1 = require("./devices/meters");
|
|
10
|
-
const motion_1 = require("./devices/motion");
|
|
28
|
+
const colorbulb_1 = require("./devices/colorbulb");
|
|
11
29
|
const contact_1 = require("./devices/contact");
|
|
12
30
|
const curtains_1 = require("./devices/curtains");
|
|
13
|
-
const colorbulb_1 = require("./devices/colorbulb");
|
|
14
31
|
const humidifiers_1 = require("./devices/humidifiers");
|
|
15
|
-
const
|
|
32
|
+
const meters_1 = require("./devices/meters");
|
|
33
|
+
const motion_1 = require("./devices/motion");
|
|
34
|
+
const plugs_1 = require("./devices/plugs");
|
|
35
|
+
const airconditioners_1 = require("./irdevices/airconditioners");
|
|
36
|
+
const airpurifiers_1 = require("./irdevices/airpurifiers");
|
|
37
|
+
const cameras_1 = require("./irdevices/cameras");
|
|
16
38
|
const fans_1 = require("./irdevices/fans");
|
|
17
39
|
const lights_1 = require("./irdevices/lights");
|
|
18
40
|
const others_1 = require("./irdevices/others");
|
|
19
|
-
const
|
|
20
|
-
const airpurifiers_1 = require("./irdevices/airpurifiers");
|
|
21
|
-
const waterheaters_1 = require("./irdevices/waterheaters");
|
|
41
|
+
const tvs_1 = require("./irdevices/tvs");
|
|
22
42
|
const vacuumcleaners_1 = require("./irdevices/vacuumcleaners");
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const settings_1 = require("./settings");
|
|
43
|
+
const waterheaters_1 = require("./irdevices/waterheaters");
|
|
44
|
+
const settings = __importStar(require("./settings"));
|
|
26
45
|
/**
|
|
27
46
|
* HomebridgePlatform
|
|
28
47
|
* This class is the main constructor for your plugin, this is where you should
|
|
@@ -38,28 +57,28 @@ class SwitchBotPlatform {
|
|
|
38
57
|
// this is used to track restored cached accessories
|
|
39
58
|
this.accessories = [];
|
|
40
59
|
this.axios = axios_1.default.create({
|
|
41
|
-
responseType:
|
|
60
|
+
responseType: "json",
|
|
42
61
|
});
|
|
43
|
-
this.version = require(
|
|
62
|
+
this.version = require("../package.json").version; // eslint-disable-line @typescript-eslint/no-var-requires
|
|
44
63
|
this.logs();
|
|
45
|
-
this.debugLog(
|
|
64
|
+
this.debugLog("Finished initializing platform:", this.config.name);
|
|
46
65
|
// only load if configured
|
|
47
66
|
if (!this.config) {
|
|
48
67
|
return;
|
|
49
68
|
}
|
|
50
69
|
// HOOBS notice
|
|
51
|
-
if (__dirname.includes(
|
|
52
|
-
this.log.warn(
|
|
53
|
-
|
|
70
|
+
if (__dirname.includes("hoobs")) {
|
|
71
|
+
this.log.warn("This plugin has not been tested under HOOBS, it is highly recommended that " +
|
|
72
|
+
"you switch to Homebridge: https://git.io/Jtxb0");
|
|
54
73
|
}
|
|
55
74
|
// verify the config
|
|
56
75
|
try {
|
|
57
76
|
this.verifyConfig();
|
|
58
|
-
this.debugLog(
|
|
77
|
+
this.debugLog("Config OK");
|
|
59
78
|
}
|
|
60
79
|
catch (e) {
|
|
61
80
|
this.errorLog(JSON.stringify(e.message));
|
|
62
|
-
if (this.platformLogging ===
|
|
81
|
+
if (this.platformLogging === "debugMode") {
|
|
63
82
|
this.errorLog(JSON.stringify(e));
|
|
64
83
|
}
|
|
65
84
|
return;
|
|
@@ -67,44 +86,49 @@ class SwitchBotPlatform {
|
|
|
67
86
|
// setup axios interceptor to add headers / api key to each request
|
|
68
87
|
this.axios.interceptors.request.use((request) => {
|
|
69
88
|
request.headers.Authorization = this.config.credentials?.openToken;
|
|
70
|
-
request.headers[
|
|
89
|
+
request.headers["Content-Type"] = "application/json; charset=utf8";
|
|
71
90
|
return request;
|
|
72
91
|
});
|
|
73
92
|
// When this event is fired it means Homebridge has restored all cached accessories from disk.
|
|
74
93
|
// Dynamic Platform plugins should only register new accessories after this event was fired,
|
|
75
94
|
// in order to ensure they weren't added to homebridge already. This event can also be used
|
|
76
95
|
// to start discovery of new accessories.
|
|
77
|
-
this.api.on(
|
|
78
|
-
this.debugLog(
|
|
96
|
+
this.api.on("didFinishLaunching", async () => {
|
|
97
|
+
this.debugLog("Executed didFinishLaunching callback");
|
|
79
98
|
// run the method to discover / register your devices as accessories
|
|
80
99
|
try {
|
|
81
100
|
this.discoverDevices();
|
|
82
101
|
}
|
|
83
102
|
catch (e) {
|
|
84
|
-
this.errorLog(
|
|
85
|
-
if (this.platformLogging ===
|
|
103
|
+
this.errorLog("Failed to Discover Devices.", JSON.stringify(e.message));
|
|
104
|
+
if (this.platformLogging === "debugMode") {
|
|
86
105
|
this.errorLog(JSON.stringify(e));
|
|
87
106
|
}
|
|
88
107
|
}
|
|
89
108
|
});
|
|
90
109
|
}
|
|
91
110
|
logs() {
|
|
92
|
-
this.debugMode =
|
|
93
|
-
|
|
111
|
+
this.debugMode =
|
|
112
|
+
process.argv.includes("-D") || process.argv.includes("--debug");
|
|
113
|
+
if (this.config.options?.logging === "debug" ||
|
|
114
|
+
this.config.options?.logging === "standard" ||
|
|
115
|
+
this.config.options?.logging === "none") {
|
|
94
116
|
this.platformLogging = this.config.options.logging;
|
|
95
|
-
if (this.
|
|
117
|
+
if (this.platformLogging.includes("debug")) {
|
|
96
118
|
this.log.warn(`Using Config Logging: ${this.platformLogging}`);
|
|
97
119
|
}
|
|
98
120
|
}
|
|
99
121
|
else if (this.debugMode) {
|
|
100
|
-
|
|
101
|
-
|
|
122
|
+
this.platformLogging = "debugMode";
|
|
123
|
+
if (this.platformLogging?.includes("debug")) {
|
|
124
|
+
this.log.warn(`Using ${this.platformLogging} Logging`);
|
|
102
125
|
}
|
|
103
|
-
this.platformLogging = 'debugMode';
|
|
104
126
|
}
|
|
105
127
|
else {
|
|
106
|
-
this.
|
|
107
|
-
this.platformLogging
|
|
128
|
+
this.platformLogging = "standard";
|
|
129
|
+
if (this.platformLogging?.includes("debug")) {
|
|
130
|
+
this.log.warn(`Using ${this.platformLogging} Logging`);
|
|
131
|
+
}
|
|
108
132
|
}
|
|
109
133
|
}
|
|
110
134
|
/**
|
|
@@ -120,21 +144,30 @@ class SwitchBotPlatform {
|
|
|
120
144
|
* Verify the config passed to the plugin is valid
|
|
121
145
|
*/
|
|
122
146
|
verifyConfig() {
|
|
123
|
-
/**
|
|
124
|
-
* Hidden Device Discovery Option
|
|
125
|
-
* This will disable adding any device and will just output info.
|
|
126
|
-
*/
|
|
127
147
|
this.config.options = this.config.options || {};
|
|
148
|
+
const platformConfig = {};
|
|
149
|
+
if (this.config.options.logging) {
|
|
150
|
+
platformConfig["logging"] = this.config.options.logging;
|
|
151
|
+
}
|
|
152
|
+
if (this.config.options.logging) {
|
|
153
|
+
platformConfig["refreshRate"] = this.config.options.refreshRate;
|
|
154
|
+
}
|
|
155
|
+
if (this.config.options.logging) {
|
|
156
|
+
platformConfig["pushRate"] = this.config.options.pushRate;
|
|
157
|
+
}
|
|
158
|
+
if (Object.entries(platformConfig).length !== 0) {
|
|
159
|
+
this.warnLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
160
|
+
}
|
|
128
161
|
if (this.config.options) {
|
|
129
162
|
// Device Config
|
|
130
163
|
if (this.config.options.devices) {
|
|
131
164
|
for (const deviceConfig of this.config.options.devices) {
|
|
132
165
|
if (!deviceConfig.hide_device) {
|
|
133
166
|
if (!deviceConfig.deviceId) {
|
|
134
|
-
throw new Error(
|
|
167
|
+
throw new Error("The devices config section is missing the *Device ID* in the config, Check Your Conifg.");
|
|
135
168
|
}
|
|
136
169
|
if (!deviceConfig.configDeviceType && deviceConfig.ble) {
|
|
137
|
-
throw new Error(
|
|
170
|
+
throw new Error("The devices config section is missing the *Device Type* in the config, Check Your Conifg.");
|
|
138
171
|
}
|
|
139
172
|
}
|
|
140
173
|
}
|
|
@@ -144,60 +177,51 @@ class SwitchBotPlatform {
|
|
|
144
177
|
for (const irDeviceConfig of this.config.options.irdevices) {
|
|
145
178
|
if (!irDeviceConfig.hide_device) {
|
|
146
179
|
if (!irDeviceConfig.deviceId) {
|
|
147
|
-
this.errorLog(
|
|
180
|
+
this.errorLog("The devices config section is missing the *Device ID* in the config, Check Your Conifg.");
|
|
148
181
|
}
|
|
149
182
|
if (!irDeviceConfig.deviceId && !irDeviceConfig.configRemoteType) {
|
|
150
|
-
this.errorLog(
|
|
183
|
+
this.errorLog("The devices config section is missing the *Device Type* in the config, Check Your Conifg.");
|
|
151
184
|
}
|
|
152
185
|
}
|
|
153
186
|
}
|
|
154
187
|
}
|
|
155
188
|
}
|
|
156
189
|
if (this.config.options.refreshRate < 30) {
|
|
157
|
-
throw new Error(
|
|
190
|
+
throw new Error("Refresh Rate must be above 30 (30 seconds).");
|
|
158
191
|
}
|
|
159
192
|
if (!this.config.options.refreshRate) {
|
|
160
193
|
// default 120 seconds (2 minutes)
|
|
161
194
|
this.config.options.refreshRate = 120;
|
|
162
|
-
if (this.
|
|
163
|
-
this.
|
|
195
|
+
if (this.platformLogging?.includes("debug")) {
|
|
196
|
+
this.debugLog("Using Default Refresh Rate (2 minutes).");
|
|
164
197
|
}
|
|
165
198
|
if (!this.config.options.pushRate) {
|
|
166
199
|
// default 100 milliseconds
|
|
167
200
|
this.config.options.pushRate = 0.1;
|
|
168
|
-
if (this.
|
|
169
|
-
this.warnLog(
|
|
201
|
+
if (this.platformLogging?.includes("debug")) {
|
|
202
|
+
this.warnLog("Using Default Push Rate.");
|
|
170
203
|
}
|
|
171
204
|
}
|
|
172
205
|
if (!this.config.credentials) {
|
|
173
|
-
this.
|
|
206
|
+
if (this.platformLogging?.includes("debug")) {
|
|
207
|
+
this.debugLog("Missing Credentials");
|
|
208
|
+
}
|
|
174
209
|
}
|
|
175
210
|
if (!this.config.credentials?.openToken) {
|
|
176
|
-
this.
|
|
177
|
-
|
|
211
|
+
if (this.platformLogging?.includes("debug")) {
|
|
212
|
+
this.errorLog("Missing openToken");
|
|
213
|
+
this.warnLog("Cloud Enabled SwitchBot Devices & IR Devices will not work");
|
|
214
|
+
}
|
|
178
215
|
}
|
|
179
216
|
}
|
|
180
217
|
}
|
|
181
|
-
connectBLE() {
|
|
182
|
-
let Switchbot;
|
|
183
|
-
let switchbot;
|
|
184
|
-
try {
|
|
185
|
-
Switchbot = require('node-switchbot');
|
|
186
|
-
switchbot = new Switchbot();
|
|
187
|
-
}
|
|
188
|
-
catch (e) {
|
|
189
|
-
switchbot = false;
|
|
190
|
-
this.errorLog(`Was 'node-switchbot' found: ${switchbot}`);
|
|
191
|
-
}
|
|
192
|
-
return switchbot;
|
|
193
|
-
}
|
|
194
218
|
/**
|
|
195
|
-
|
|
196
|
-
|
|
219
|
+
* this method discovers devices
|
|
220
|
+
*/
|
|
197
221
|
async discoverDevices() {
|
|
198
222
|
try {
|
|
199
223
|
if (this.config.credentials?.openToken) {
|
|
200
|
-
const devicesAPI = (await this.axios.get(
|
|
224
|
+
const devicesAPI = (await this.axios.get(settings.DeviceURL)).data;
|
|
201
225
|
this.deviceListInfo(devicesAPI);
|
|
202
226
|
this.debugLog(JSON.stringify(devicesAPI));
|
|
203
227
|
// SwitchBot Devices
|
|
@@ -215,11 +239,14 @@ class SwitchBotPlatform {
|
|
|
215
239
|
}
|
|
216
240
|
}
|
|
217
241
|
}
|
|
218
|
-
else if (this.config.credentials?.openToken &&
|
|
242
|
+
else if (this.config.credentials?.openToken &&
|
|
243
|
+
this.config.options.devices) {
|
|
219
244
|
this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
220
245
|
const deviceConfigs = this.config.options?.devices;
|
|
221
246
|
const mergeBydeviceId = (a1, a2) => a1.map((itm) => ({
|
|
222
|
-
...a2.find((item) =>
|
|
247
|
+
...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, "") ===
|
|
248
|
+
itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, "") &&
|
|
249
|
+
item),
|
|
223
250
|
...itm,
|
|
224
251
|
}));
|
|
225
252
|
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
@@ -234,7 +261,7 @@ class SwitchBotPlatform {
|
|
|
234
261
|
}
|
|
235
262
|
}
|
|
236
263
|
else {
|
|
237
|
-
this.errorLog(
|
|
264
|
+
this.errorLog("Neither SwitchBot OpenToken or Device Config are not set.");
|
|
238
265
|
}
|
|
239
266
|
// IR Devices
|
|
240
267
|
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
@@ -252,7 +279,9 @@ class SwitchBotPlatform {
|
|
|
252
279
|
this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
253
280
|
const irDeviceConfig = this.config.options?.irdevices;
|
|
254
281
|
const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
|
|
255
|
-
...a2.find((item) =>
|
|
282
|
+
...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, "") ===
|
|
283
|
+
itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, "") &&
|
|
284
|
+
item),
|
|
256
285
|
...itm,
|
|
257
286
|
}));
|
|
258
287
|
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
@@ -264,7 +293,8 @@ class SwitchBotPlatform {
|
|
|
264
293
|
}
|
|
265
294
|
}
|
|
266
295
|
}
|
|
267
|
-
else if (!this.config.credentials?.openToken &&
|
|
296
|
+
else if (!this.config.credentials?.openToken &&
|
|
297
|
+
this.config.options?.devices) {
|
|
268
298
|
this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
269
299
|
const deviceConfigs = this.config.options?.devices;
|
|
270
300
|
const devices = deviceConfigs.map((v) => v);
|
|
@@ -277,7 +307,7 @@ class SwitchBotPlatform {
|
|
|
277
307
|
}
|
|
278
308
|
}
|
|
279
309
|
else {
|
|
280
|
-
this.errorLog(
|
|
310
|
+
this.errorLog("Neither SwitchBot OpenToken or Device Config are not set.");
|
|
281
311
|
}
|
|
282
312
|
}
|
|
283
313
|
catch (e) {
|
|
@@ -285,167 +315,167 @@ class SwitchBotPlatform {
|
|
|
285
315
|
}
|
|
286
316
|
}
|
|
287
317
|
deviceError(e) {
|
|
288
|
-
if (e.message.includes(
|
|
289
|
-
this.errorLog(
|
|
290
|
-
this.debugLog(
|
|
318
|
+
if (e.message.includes("400")) {
|
|
319
|
+
this.errorLog("Failed to Discover Devices: Bad Request");
|
|
320
|
+
this.debugLog("The client has issued an invalid request. This is commonly used to specify validation errors in a request payload.");
|
|
291
321
|
}
|
|
292
|
-
else if (e.message.includes(
|
|
293
|
-
this.errorLog(
|
|
294
|
-
this.debugLog(
|
|
322
|
+
else if (e.message.includes("401")) {
|
|
323
|
+
this.errorLog("Failed to Discover Devices: Unauthorized Request");
|
|
324
|
+
this.debugLog("Authorization for the API is required, but the request has not been authenticated.");
|
|
295
325
|
}
|
|
296
|
-
else if (e.message.includes(
|
|
297
|
-
this.errorLog(
|
|
298
|
-
this.debugLog(
|
|
326
|
+
else if (e.message.includes("403")) {
|
|
327
|
+
this.errorLog("Failed to Discover Devices: Forbidden Request");
|
|
328
|
+
this.debugLog("The request has been authenticated but does not have appropriate permissions, or a requested resource is not found.");
|
|
299
329
|
}
|
|
300
|
-
else if (e.message.includes(
|
|
301
|
-
this.errorLog(
|
|
302
|
-
this.debugLog(
|
|
330
|
+
else if (e.message.includes("404")) {
|
|
331
|
+
this.errorLog("Failed to Discover Devices: Requst Not Found");
|
|
332
|
+
this.debugLog("Specifies the requested path does not exist.");
|
|
303
333
|
}
|
|
304
|
-
else if (e.message.includes(
|
|
305
|
-
this.errorLog(
|
|
306
|
-
this.debugLog(
|
|
334
|
+
else if (e.message.includes("406")) {
|
|
335
|
+
this.errorLog("Failed to Discover Devices: Request Not Acceptable");
|
|
336
|
+
this.debugLog("The client has requested a MIME type via the Accept header for a value not supported by the server.");
|
|
307
337
|
}
|
|
308
|
-
else if (e.message.includes(
|
|
309
|
-
this.errorLog(
|
|
310
|
-
this.debugLog(
|
|
338
|
+
else if (e.message.includes("415")) {
|
|
339
|
+
this.errorLog("Failed to Discover Devices: Unsupported Requst Header");
|
|
340
|
+
this.debugLog("The client has defined a contentType header that is not supported by the server.");
|
|
311
341
|
}
|
|
312
|
-
else if (e.message.includes(
|
|
313
|
-
this.errorLog(
|
|
314
|
-
this.debugLog(
|
|
315
|
-
|
|
342
|
+
else if (e.message.includes("422")) {
|
|
343
|
+
this.errorLog("Failed to Discover Devices: Unprocessable Entity");
|
|
344
|
+
this.debugLog("The client has made a valid request, but the server cannot process it." +
|
|
345
|
+
" This is often used for APIs for which certain limits have been exceeded.");
|
|
316
346
|
}
|
|
317
|
-
else if (e.message.includes(
|
|
318
|
-
this.errorLog(
|
|
319
|
-
this.debugLog(
|
|
347
|
+
else if (e.message.includes("429")) {
|
|
348
|
+
this.errorLog("Failed to Discover Devices: Too Many Requests");
|
|
349
|
+
this.debugLog("The client has exceeded the number of requests allowed for a given time window.");
|
|
320
350
|
}
|
|
321
|
-
else if (e.message.includes(
|
|
322
|
-
this.errorLog(
|
|
323
|
-
this.debugLog(
|
|
351
|
+
else if (e.message.includes("500")) {
|
|
352
|
+
this.errorLog("Failed to Discover Devices: Internal Server Error");
|
|
353
|
+
this.debugLog("An unexpected error on the SmartThings servers has occurred. These errors should be rare.");
|
|
324
354
|
}
|
|
325
355
|
else {
|
|
326
|
-
this.errorLog(
|
|
356
|
+
this.errorLog("Failed to Discover Devices");
|
|
327
357
|
}
|
|
328
|
-
if (this.platformLogging ===
|
|
358
|
+
if (this.platformLogging === "debug") {
|
|
329
359
|
this.errorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}`);
|
|
330
360
|
}
|
|
331
|
-
if (this.platformLogging ===
|
|
361
|
+
if (this.platformLogging === "debugMode") {
|
|
332
362
|
this.errorLog(`Failed to Discover Devices, Error: ${JSON.stringify(e)}`);
|
|
333
363
|
}
|
|
334
364
|
}
|
|
335
365
|
createDevice(device) {
|
|
336
366
|
switch (device.deviceType) {
|
|
337
|
-
case
|
|
367
|
+
case "Humidifier":
|
|
338
368
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
339
369
|
this.createHumidifier(device);
|
|
340
370
|
break;
|
|
341
|
-
case
|
|
371
|
+
case "Hub Mini":
|
|
342
372
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
343
373
|
break;
|
|
344
|
-
case
|
|
374
|
+
case "Hub Plus":
|
|
345
375
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
346
376
|
break;
|
|
347
|
-
case
|
|
377
|
+
case "Bot":
|
|
348
378
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
349
379
|
this.createBot(device);
|
|
350
380
|
break;
|
|
351
|
-
case
|
|
381
|
+
case "Meter":
|
|
352
382
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
353
383
|
this.createMeter(device);
|
|
354
384
|
break;
|
|
355
|
-
case
|
|
385
|
+
case "Motion Sensor":
|
|
356
386
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
357
387
|
this.createMotion(device);
|
|
358
388
|
break;
|
|
359
|
-
case
|
|
389
|
+
case "Contact Sensor":
|
|
360
390
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
361
391
|
this.createContact(device);
|
|
362
392
|
break;
|
|
363
|
-
case
|
|
393
|
+
case "Curtain":
|
|
364
394
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
365
395
|
this.createCurtain(device);
|
|
366
396
|
break;
|
|
367
|
-
case
|
|
397
|
+
case "Plug":
|
|
368
398
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
369
399
|
this.createPlug(device);
|
|
370
400
|
break;
|
|
371
|
-
case
|
|
401
|
+
case "Color Bulb":
|
|
372
402
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
373
403
|
this.createColorBulb(device);
|
|
374
404
|
break;
|
|
375
|
-
case
|
|
405
|
+
case "Indoor Cam":
|
|
376
406
|
this.deviceInfo(device);
|
|
377
407
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
378
408
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
|
|
379
409
|
break;
|
|
380
|
-
case
|
|
410
|
+
case "Remote":
|
|
381
411
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId} is Not Supported.`);
|
|
382
412
|
break;
|
|
383
413
|
default:
|
|
384
414
|
this.deviceInfo(device);
|
|
385
415
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
|
|
386
|
-
this.warnLog(
|
|
416
|
+
this.warnLog("Submit Feature Requests Here: https://git.io/JL14Z");
|
|
387
417
|
}
|
|
388
418
|
}
|
|
389
419
|
createIRDevice(device) {
|
|
390
420
|
switch (device.remoteType) {
|
|
391
|
-
case
|
|
392
|
-
case
|
|
393
|
-
case
|
|
394
|
-
case
|
|
395
|
-
case
|
|
396
|
-
case
|
|
397
|
-
case
|
|
398
|
-
case
|
|
399
|
-
case
|
|
400
|
-
case
|
|
401
|
-
case
|
|
402
|
-
case
|
|
421
|
+
case "TV":
|
|
422
|
+
case "DIY TV":
|
|
423
|
+
case "Projector":
|
|
424
|
+
case "DIY Projector":
|
|
425
|
+
case "Set Top Box":
|
|
426
|
+
case "DIY Set Top Box":
|
|
427
|
+
case "IPTV":
|
|
428
|
+
case "DIY IPTV":
|
|
429
|
+
case "DVD":
|
|
430
|
+
case "DIY DVD":
|
|
431
|
+
case "Speaker":
|
|
432
|
+
case "DIY Speaker":
|
|
403
433
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
404
434
|
this.createTV(device);
|
|
405
435
|
break;
|
|
406
|
-
case
|
|
407
|
-
case
|
|
436
|
+
case "Fan":
|
|
437
|
+
case "DIY Fan":
|
|
408
438
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
409
439
|
this.createFan(device);
|
|
410
440
|
break;
|
|
411
|
-
case
|
|
412
|
-
case
|
|
441
|
+
case "Air Conditioner":
|
|
442
|
+
case "DIY Air Conditioner":
|
|
413
443
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
414
444
|
this.createAirConditioner(device);
|
|
415
445
|
break;
|
|
416
|
-
case
|
|
417
|
-
case
|
|
446
|
+
case "Light":
|
|
447
|
+
case "DIY Light":
|
|
418
448
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
419
449
|
this.createLight(device);
|
|
420
450
|
break;
|
|
421
|
-
case
|
|
422
|
-
case
|
|
451
|
+
case "Air Purifier":
|
|
452
|
+
case "DIY Air Purifier":
|
|
423
453
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
424
454
|
this.createAirPurifier(device);
|
|
425
455
|
break;
|
|
426
|
-
case
|
|
427
|
-
case
|
|
456
|
+
case "Water Heater":
|
|
457
|
+
case "DIY Water Heater":
|
|
428
458
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
429
459
|
this.createWaterHeater(device);
|
|
430
460
|
break;
|
|
431
|
-
case
|
|
432
|
-
case
|
|
461
|
+
case "Vacuum Cleaner":
|
|
462
|
+
case "DIY Vacuum Cleaner":
|
|
433
463
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
434
464
|
this.createVacuumCleaner(device);
|
|
435
465
|
break;
|
|
436
|
-
case
|
|
437
|
-
case
|
|
466
|
+
case "Camera":
|
|
467
|
+
case "DIY Camera":
|
|
438
468
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
439
469
|
this.createCamera(device);
|
|
440
470
|
break;
|
|
441
|
-
case
|
|
471
|
+
case "Others":
|
|
442
472
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
443
473
|
this.createOthers(device);
|
|
444
474
|
break;
|
|
445
475
|
default:
|
|
446
476
|
this.deviceInfo(device);
|
|
447
477
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`);
|
|
448
|
-
this.warnLog(
|
|
478
|
+
this.warnLog("Submit Feature Requests Here: https://git.io/JL14Z");
|
|
449
479
|
}
|
|
450
480
|
}
|
|
451
481
|
registerDevice(device) {
|
|
@@ -453,11 +483,17 @@ class SwitchBotPlatform {
|
|
|
453
483
|
this.registeringDevice = true;
|
|
454
484
|
this.debugLog(`Device: ${device.deviceName} Both OpenAPI and BLE Connections Enabled`);
|
|
455
485
|
}
|
|
456
|
-
else if (!device.hide_device &&
|
|
486
|
+
else if (!device.hide_device &&
|
|
487
|
+
device.deviceId &&
|
|
488
|
+
device.configDeviceType &&
|
|
489
|
+
device.configDeviceName &&
|
|
490
|
+
!device.enableCloudService) {
|
|
457
491
|
this.registeringDevice = true;
|
|
458
492
|
this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled`);
|
|
459
493
|
}
|
|
460
|
-
else if (!device.hide_device &&
|
|
494
|
+
else if (!device.hide_device &&
|
|
495
|
+
device.enableCloudService &&
|
|
496
|
+
!device.ble) {
|
|
461
497
|
this.registeringDevice = true;
|
|
462
498
|
this.debugLog(`Device: ${device.deviceName} OpenAPI Connection Enabled`);
|
|
463
499
|
}
|
|
@@ -512,7 +548,9 @@ class SwitchBotPlatform {
|
|
|
512
548
|
new humidifiers_1.Humidifier(this, accessory, device);
|
|
513
549
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
514
550
|
// link the accessory to your platform
|
|
515
|
-
this.api.registerPlatformAccessories(
|
|
551
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
552
|
+
accessory,
|
|
553
|
+
]);
|
|
516
554
|
this.accessories.push(accessory);
|
|
517
555
|
}
|
|
518
556
|
else {
|
|
@@ -566,7 +604,9 @@ class SwitchBotPlatform {
|
|
|
566
604
|
new bots_1.Bot(this, accessory, device);
|
|
567
605
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
568
606
|
// link the accessory to your platform
|
|
569
|
-
this.api.registerPlatformAccessories(
|
|
607
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
608
|
+
accessory,
|
|
609
|
+
]);
|
|
570
610
|
this.accessories.push(accessory);
|
|
571
611
|
}
|
|
572
612
|
else {
|
|
@@ -617,7 +657,9 @@ class SwitchBotPlatform {
|
|
|
617
657
|
new meters_1.Meter(this, accessory, device);
|
|
618
658
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
619
659
|
// link the accessory to your platform
|
|
620
|
-
this.api.registerPlatformAccessories(
|
|
660
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
661
|
+
accessory,
|
|
662
|
+
]);
|
|
621
663
|
this.accessories.push(accessory);
|
|
622
664
|
}
|
|
623
665
|
else {
|
|
@@ -668,7 +710,9 @@ class SwitchBotPlatform {
|
|
|
668
710
|
new motion_1.Motion(this, accessory, device);
|
|
669
711
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
670
712
|
// link the accessory to your platform
|
|
671
|
-
this.api.registerPlatformAccessories(
|
|
713
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
714
|
+
accessory,
|
|
715
|
+
]);
|
|
672
716
|
this.accessories.push(accessory);
|
|
673
717
|
}
|
|
674
718
|
else {
|
|
@@ -719,7 +763,9 @@ class SwitchBotPlatform {
|
|
|
719
763
|
new contact_1.Contact(this, accessory, device);
|
|
720
764
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
721
765
|
// link the accessory to your platform
|
|
722
|
-
this.api.registerPlatformAccessories(
|
|
766
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
767
|
+
accessory,
|
|
768
|
+
]);
|
|
723
769
|
this.accessories.push(accessory);
|
|
724
770
|
}
|
|
725
771
|
else {
|
|
@@ -782,7 +828,9 @@ class SwitchBotPlatform {
|
|
|
782
828
|
new curtains_1.Curtain(this, accessory, device);
|
|
783
829
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
784
830
|
// link the accessory to your platform
|
|
785
|
-
this.api.registerPlatformAccessories(
|
|
831
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
832
|
+
accessory,
|
|
833
|
+
]);
|
|
786
834
|
this.accessories.push(accessory);
|
|
787
835
|
}
|
|
788
836
|
else {
|
|
@@ -790,8 +838,8 @@ class SwitchBotPlatform {
|
|
|
790
838
|
}
|
|
791
839
|
}
|
|
792
840
|
isCurtainGrouped(device) {
|
|
793
|
-
this.debugLog(`deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},`
|
|
794
|
-
|
|
841
|
+
this.debugLog(`deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},` +
|
|
842
|
+
` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}`);
|
|
795
843
|
if (device.group && !device.curtain?.disable_group) {
|
|
796
844
|
this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}`);
|
|
797
845
|
return device.master && this.registerDevice(device);
|
|
@@ -845,7 +893,9 @@ class SwitchBotPlatform {
|
|
|
845
893
|
new plugs_1.Plug(this, accessory, device);
|
|
846
894
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
847
895
|
// link the accessory to your platform
|
|
848
|
-
this.api.registerPlatformAccessories(
|
|
896
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
897
|
+
accessory,
|
|
898
|
+
]);
|
|
849
899
|
this.accessories.push(accessory);
|
|
850
900
|
}
|
|
851
901
|
else {
|
|
@@ -896,7 +946,9 @@ class SwitchBotPlatform {
|
|
|
896
946
|
new colorbulb_1.ColorBulb(this, accessory, device);
|
|
897
947
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
898
948
|
// link the accessory to your platform
|
|
899
|
-
this.api.registerPlatformAccessories(
|
|
949
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
950
|
+
accessory,
|
|
951
|
+
]);
|
|
900
952
|
this.accessories.push(accessory);
|
|
901
953
|
}
|
|
902
954
|
else {
|
|
@@ -941,11 +993,11 @@ class SwitchBotPlatform {
|
|
|
941
993
|
new tvs_1.TV(this, accessory, device);
|
|
942
994
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
943
995
|
/**
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
this.api.publishExternalAccessories(
|
|
996
|
+
* Publish as external accessory
|
|
997
|
+
* Only one TV can exist per bridge, to bypass this limitation, you should
|
|
998
|
+
* publish your TV as an external accessory.
|
|
999
|
+
*/
|
|
1000
|
+
this.api.publishExternalAccessories(settings.PLUGIN_NAME, [accessory]);
|
|
949
1001
|
this.accessories.push(accessory);
|
|
950
1002
|
}
|
|
951
1003
|
else {
|
|
@@ -996,7 +1048,9 @@ class SwitchBotPlatform {
|
|
|
996
1048
|
new fans_1.Fan(this, accessory, device);
|
|
997
1049
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
998
1050
|
// link the accessory to your platform
|
|
999
|
-
this.api.registerPlatformAccessories(
|
|
1051
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1052
|
+
accessory,
|
|
1053
|
+
]);
|
|
1000
1054
|
this.accessories.push(accessory);
|
|
1001
1055
|
}
|
|
1002
1056
|
else {
|
|
@@ -1047,7 +1101,9 @@ class SwitchBotPlatform {
|
|
|
1047
1101
|
new lights_1.Light(this, accessory, device);
|
|
1048
1102
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1049
1103
|
// link the accessory to your platform
|
|
1050
|
-
this.api.registerPlatformAccessories(
|
|
1104
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1105
|
+
accessory,
|
|
1106
|
+
]);
|
|
1051
1107
|
this.accessories.push(accessory);
|
|
1052
1108
|
}
|
|
1053
1109
|
else {
|
|
@@ -1098,7 +1154,9 @@ class SwitchBotPlatform {
|
|
|
1098
1154
|
new airconditioners_1.AirConditioner(this, accessory, device);
|
|
1099
1155
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1100
1156
|
// link the accessory to your platform
|
|
1101
|
-
this.api.registerPlatformAccessories(
|
|
1157
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1158
|
+
accessory,
|
|
1159
|
+
]);
|
|
1102
1160
|
this.accessories.push(accessory);
|
|
1103
1161
|
}
|
|
1104
1162
|
else {
|
|
@@ -1149,7 +1207,9 @@ class SwitchBotPlatform {
|
|
|
1149
1207
|
new airpurifiers_1.AirPurifier(this, accessory, device);
|
|
1150
1208
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1151
1209
|
// link the accessory to your platform
|
|
1152
|
-
this.api.registerPlatformAccessories(
|
|
1210
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1211
|
+
accessory,
|
|
1212
|
+
]);
|
|
1153
1213
|
this.accessories.push(accessory);
|
|
1154
1214
|
}
|
|
1155
1215
|
else {
|
|
@@ -1200,7 +1260,9 @@ class SwitchBotPlatform {
|
|
|
1200
1260
|
new waterheaters_1.WaterHeater(this, accessory, device);
|
|
1201
1261
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1202
1262
|
// link the accessory to your platform
|
|
1203
|
-
this.api.registerPlatformAccessories(
|
|
1263
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1264
|
+
accessory,
|
|
1265
|
+
]);
|
|
1204
1266
|
this.accessories.push(accessory);
|
|
1205
1267
|
}
|
|
1206
1268
|
else {
|
|
@@ -1251,7 +1313,9 @@ class SwitchBotPlatform {
|
|
|
1251
1313
|
new vacuumcleaners_1.VacuumCleaner(this, accessory, device);
|
|
1252
1314
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1253
1315
|
// link the accessory to your platform
|
|
1254
|
-
this.api.registerPlatformAccessories(
|
|
1316
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1317
|
+
accessory,
|
|
1318
|
+
]);
|
|
1255
1319
|
this.accessories.push(accessory);
|
|
1256
1320
|
}
|
|
1257
1321
|
else {
|
|
@@ -1302,7 +1366,9 @@ class SwitchBotPlatform {
|
|
|
1302
1366
|
new cameras_1.Camera(this, accessory, device);
|
|
1303
1367
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1304
1368
|
// link the accessory to your platform
|
|
1305
|
-
this.api.registerPlatformAccessories(
|
|
1369
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1370
|
+
accessory,
|
|
1371
|
+
]);
|
|
1306
1372
|
this.accessories.push(accessory);
|
|
1307
1373
|
}
|
|
1308
1374
|
else {
|
|
@@ -1353,7 +1419,9 @@ class SwitchBotPlatform {
|
|
|
1353
1419
|
new others_1.Others(this, accessory, device);
|
|
1354
1420
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1355
1421
|
// link the accessory to your platform
|
|
1356
|
-
this.api.registerPlatformAccessories(
|
|
1422
|
+
this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1423
|
+
accessory,
|
|
1424
|
+
]);
|
|
1357
1425
|
this.accessories.push(accessory);
|
|
1358
1426
|
}
|
|
1359
1427
|
else {
|
|
@@ -1362,49 +1430,65 @@ class SwitchBotPlatform {
|
|
|
1362
1430
|
}
|
|
1363
1431
|
async connectionTypeNewAccessory(device, accessory) {
|
|
1364
1432
|
if (device.ble) {
|
|
1365
|
-
accessory.context.connectionType =
|
|
1433
|
+
accessory.context.connectionType = "BLE";
|
|
1366
1434
|
}
|
|
1367
1435
|
else {
|
|
1368
|
-
accessory.context.connectionType =
|
|
1436
|
+
accessory.context.connectionType = "OpenAPI";
|
|
1369
1437
|
}
|
|
1370
1438
|
}
|
|
1371
1439
|
async connectionTypeExistingAccessory(device, existingAccessory) {
|
|
1372
1440
|
if (device.ble) {
|
|
1373
|
-
existingAccessory.context.connectionType =
|
|
1441
|
+
existingAccessory.context.connectionType = "BLE";
|
|
1374
1442
|
}
|
|
1375
1443
|
else {
|
|
1376
|
-
existingAccessory.context.connectionType =
|
|
1444
|
+
existingAccessory.context.connectionType = "OpenAPI";
|
|
1377
1445
|
}
|
|
1378
1446
|
}
|
|
1379
1447
|
async connectionTypeNewIRAccessory(accessory) {
|
|
1380
|
-
accessory.context.connectionType =
|
|
1448
|
+
accessory.context.connectionType = "IR wirth OpenAPI";
|
|
1381
1449
|
}
|
|
1382
1450
|
async connectionTypeExistingIRAccessory(existingAccessory) {
|
|
1383
|
-
existingAccessory.context.connectionType =
|
|
1451
|
+
existingAccessory.context.connectionType = "IR with OpenAPI";
|
|
1384
1452
|
}
|
|
1385
1453
|
unregisterPlatformAccessories(existingAccessory) {
|
|
1386
1454
|
// remove platform accessories when no longer present
|
|
1387
|
-
this.api.unregisterPlatformAccessories(
|
|
1388
|
-
|
|
1455
|
+
this.api.unregisterPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
|
|
1456
|
+
existingAccessory,
|
|
1457
|
+
]);
|
|
1458
|
+
this.infoLog("Removing existing accessory from cache:", existingAccessory.displayName);
|
|
1389
1459
|
}
|
|
1390
1460
|
deviceListInfo(devices) {
|
|
1391
|
-
if (this.platformLogging ===
|
|
1461
|
+
if (this.platformLogging === "debug") {
|
|
1392
1462
|
this.warnLog(`deviceListInfoStatus: ${JSON.stringify(devices)}`);
|
|
1393
1463
|
}
|
|
1394
1464
|
}
|
|
1395
1465
|
async deviceInfo(device) {
|
|
1396
|
-
if (this.platformLogging ===
|
|
1466
|
+
if (this.platformLogging === "debug") {
|
|
1397
1467
|
this.warnLog(JSON.stringify(device));
|
|
1398
|
-
this.deviceStatus = (await this.axios.get(`${
|
|
1399
|
-
if (this.deviceStatus.message ===
|
|
1468
|
+
this.deviceStatus = (await this.axios.get(`${settings.DeviceURL}/${device.deviceId}/status`)).data;
|
|
1469
|
+
if (this.deviceStatus.message === "success") {
|
|
1400
1470
|
this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
1401
1471
|
}
|
|
1402
1472
|
else {
|
|
1403
1473
|
this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus.message)}`);
|
|
1404
|
-
this.warnLog(
|
|
1474
|
+
this.warnLog("Unable to retreive deviceInfoStatus.");
|
|
1405
1475
|
}
|
|
1406
1476
|
}
|
|
1407
1477
|
}
|
|
1478
|
+
// BLE Connection
|
|
1479
|
+
connectBLE() {
|
|
1480
|
+
let Switchbot;
|
|
1481
|
+
let switchbot;
|
|
1482
|
+
try {
|
|
1483
|
+
Switchbot = require("node-switchbot");
|
|
1484
|
+
switchbot = new Switchbot();
|
|
1485
|
+
}
|
|
1486
|
+
catch (e) {
|
|
1487
|
+
switchbot = false;
|
|
1488
|
+
this.errorLog(`Was 'node-switchbot' found: ${switchbot}`);
|
|
1489
|
+
}
|
|
1490
|
+
return switchbot;
|
|
1491
|
+
}
|
|
1408
1492
|
/**
|
|
1409
1493
|
* If device level logging is turned on, log to log.warn
|
|
1410
1494
|
* Otherwise send debug logs to log.debug
|
|
@@ -1426,16 +1510,17 @@ class SwitchBotPlatform {
|
|
|
1426
1510
|
}
|
|
1427
1511
|
debugLog(...log) {
|
|
1428
1512
|
if (this.enablingPlatfromLogging()) {
|
|
1429
|
-
if (this.platformLogging ===
|
|
1513
|
+
if (this.platformLogging === "debugMode") {
|
|
1430
1514
|
this.log.debug(String(...log));
|
|
1431
1515
|
}
|
|
1432
|
-
else if (this.platformLogging ===
|
|
1433
|
-
this.log.info(
|
|
1516
|
+
else if (this.platformLogging === "debug") {
|
|
1517
|
+
this.log.info("[DEBUG]", String(...log));
|
|
1434
1518
|
}
|
|
1435
1519
|
}
|
|
1436
1520
|
}
|
|
1437
1521
|
enablingPlatfromLogging() {
|
|
1438
|
-
return this.platformLogging?.includes(
|
|
1522
|
+
return (this.platformLogging?.includes("debug") ||
|
|
1523
|
+
this.platformLogging === "standard");
|
|
1439
1524
|
}
|
|
1440
1525
|
}
|
|
1441
1526
|
exports.SwitchBotPlatform = SwitchBotPlatform;
|