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