@switchbot/homebridge-switchbot 1.8.2 → 1.8.3-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +1 -1
- package/.vscode/extensions.json +5 -0
- package/.vscode/settings.json +15 -0
- package/dist/devices/bots.d.ts +34 -35
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +241 -184
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +50 -50
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +145 -131
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +27 -29
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +138 -115
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +29 -31
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +211 -176
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +33 -33
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +214 -189
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +30 -31
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +124 -100
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +25 -26
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +120 -102
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +23 -23
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +81 -63
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +6 -6
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +105 -79
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +5 -5
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +56 -42
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +5 -5
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +31 -27
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +5 -5
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +45 -38
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +5 -5
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +37 -33
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +5 -5
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +34 -29
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +5 -5
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +91 -76
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +5 -5
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +31 -27
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +5 -5
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +31 -27
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +12 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +241 -172
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/package.json +72 -71
- package/src/devices/bots.ts +927 -442
- package/src/devices/colorbulb.ts +473 -246
- package/src/devices/contact.ts +381 -208
- package/src/devices/curtains.ts +613 -321
- package/src/devices/humidifiers.ts +594 -323
- package/src/devices/meters.ts +331 -186
- package/src/devices/motion.ts +327 -184
- package/src/devices/plugs.ts +175 -107
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +360 -149
- package/src/irdevices/airpurifiers.ts +178 -80
- package/src/irdevices/cameras.ts +109 -51
- package/src/irdevices/fans.ts +174 -77
- package/src/irdevices/lights.ts +110 -57
- package/src/irdevices/others.ts +137 -62
- package/src/irdevices/tvs.ts +249 -124
- package/src/irdevices/vacuumcleaners.ts +112 -52
- package/src/irdevices/waterheaters.ts +115 -53
- package/src/platform.ts +768 -357
- package/src/settings.ts +17 -23
package/src/devices/plugs.ts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
1
|
+
import * as axios from "axios";
|
|
2
|
+
import * as rxjs from "rxjs";
|
|
3
|
+
import * as platform_1 from "../platform";
|
|
4
|
+
import * as operators from "rxjs/operators";
|
|
5
|
+
import * as homebridge from "homebridge";
|
|
6
|
+
import * as settings from "../settings";
|
|
8
7
|
|
|
9
8
|
export class Plug {
|
|
10
9
|
// Services
|
|
11
|
-
private service: Service;
|
|
10
|
+
private service: homebridge.Service;
|
|
12
11
|
|
|
13
12
|
// Characteristic Values
|
|
14
|
-
On!: CharacteristicValue;
|
|
15
|
-
OnCached!: CharacteristicValue;
|
|
13
|
+
On!: homebridge.CharacteristicValue;
|
|
14
|
+
OnCached!: homebridge.CharacteristicValue;
|
|
16
15
|
|
|
17
16
|
// OpenAPI Others
|
|
18
|
-
power: deviceStatus[
|
|
19
|
-
deviceStatus!: deviceStatusResponse;
|
|
17
|
+
power: settings.deviceStatus["power"];
|
|
18
|
+
deviceStatus!: settings.deviceStatusResponse;
|
|
20
19
|
|
|
21
20
|
// Config
|
|
22
21
|
scanDuration!: number;
|
|
@@ -25,12 +24,12 @@ export class Plug {
|
|
|
25
24
|
|
|
26
25
|
// Updates
|
|
27
26
|
plugUpdateInProgress!: boolean;
|
|
28
|
-
doPlugUpdate!: Subject<void>;
|
|
27
|
+
doPlugUpdate!: rxjs.Subject<void>;
|
|
29
28
|
|
|
30
29
|
constructor(
|
|
31
|
-
private readonly platform: SwitchBotPlatform,
|
|
32
|
-
private accessory: PlatformAccessory,
|
|
33
|
-
public device: device & devicesConfig,
|
|
30
|
+
private readonly platform: platform_1.SwitchBotPlatform,
|
|
31
|
+
private accessory: homebridge.PlatformAccessory,
|
|
32
|
+
public device: settings.device & settings.devicesConfig,
|
|
34
33
|
) {
|
|
35
34
|
// default placeholders
|
|
36
35
|
this.logs(device);
|
|
@@ -43,11 +42,8 @@ export class Plug {
|
|
|
43
42
|
this.On = this.accessory.context.On;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
// Plug Config
|
|
47
|
-
this.debugLog(`Plug: ${this.accessory.displayName} Config: (offline: ${device.offline})`);
|
|
48
|
-
|
|
49
45
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
50
|
-
this.doPlugUpdate = new Subject();
|
|
46
|
+
this.doPlugUpdate = new rxjs.Subject();
|
|
51
47
|
this.plugUpdateInProgress = false;
|
|
52
48
|
|
|
53
49
|
// Retrieve initial values and updateHomekit
|
|
@@ -56,15 +52,22 @@ export class Plug {
|
|
|
56
52
|
// set accessory information
|
|
57
53
|
accessory
|
|
58
54
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
59
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
60
|
-
.setCharacteristic(
|
|
61
|
-
|
|
55
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
|
|
56
|
+
.setCharacteristic(
|
|
57
|
+
this.platform.Characteristic.Model,
|
|
58
|
+
"SWITCHBOT-PLUG-SP11",
|
|
59
|
+
)
|
|
60
|
+
.setCharacteristic(
|
|
61
|
+
this.platform.Characteristic.SerialNumber,
|
|
62
|
+
device.deviceId!,
|
|
63
|
+
);
|
|
62
64
|
|
|
63
65
|
// get the WindowCovering service if it exists, otherwise create a new WindowCovering service
|
|
64
66
|
// you can create multiple services for each accessory
|
|
65
67
|
(this.service =
|
|
66
68
|
accessory.getService(this.platform.Service.Outlet) ||
|
|
67
|
-
accessory.addService(this.platform.Service.Outlet)),
|
|
69
|
+
accessory.addService(this.platform.Service.Outlet)),
|
|
70
|
+
`${device.deviceName} ${device.deviceType}`;
|
|
68
71
|
|
|
69
72
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
70
73
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -72,20 +75,25 @@ export class Plug {
|
|
|
72
75
|
|
|
73
76
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
74
77
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
75
|
-
this.service.setCharacteristic(
|
|
78
|
+
this.service.setCharacteristic(
|
|
79
|
+
this.platform.Characteristic.Name,
|
|
80
|
+
accessory.displayName,
|
|
81
|
+
);
|
|
76
82
|
|
|
77
83
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
78
84
|
// see https://developers.homebridge.io/#/service/WindowCovering
|
|
79
85
|
|
|
80
86
|
// create handlers for required characteristics
|
|
81
|
-
this.service
|
|
87
|
+
this.service
|
|
88
|
+
.getCharacteristic(this.platform.Characteristic.On)
|
|
89
|
+
.onSet(this.OnSet.bind(this));
|
|
82
90
|
|
|
83
91
|
// Update Homekit
|
|
84
92
|
this.updateHomeKitCharacteristics();
|
|
85
93
|
|
|
86
94
|
// Start an update interval
|
|
87
|
-
interval(this.deviceRefreshRate * 1000)
|
|
88
|
-
.pipe(skipWhile(() => this.plugUpdateInProgress))
|
|
95
|
+
rxjs.interval(this.deviceRefreshRate * 1000)
|
|
96
|
+
.pipe(operators.skipWhile(() => this.plugUpdateInProgress))
|
|
89
97
|
.subscribe(() => {
|
|
90
98
|
this.refreshStatus();
|
|
91
99
|
});
|
|
@@ -94,23 +102,23 @@ export class Plug {
|
|
|
94
102
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
95
103
|
this.doPlugUpdate
|
|
96
104
|
.pipe(
|
|
97
|
-
tap(() => {
|
|
105
|
+
operators.tap(() => {
|
|
98
106
|
this.plugUpdateInProgress = true;
|
|
99
107
|
}),
|
|
100
|
-
debounceTime(this.platform.config.options!.pushRate! * 1000),
|
|
108
|
+
operators.debounceTime(this.platform.config.options!.pushRate! * 1000),
|
|
101
109
|
)
|
|
102
110
|
.subscribe(async () => {
|
|
103
111
|
try {
|
|
104
112
|
await this.pushChanges();
|
|
105
113
|
} catch (e: any) {
|
|
106
|
-
this.errorLog(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
this.errorLog(
|
|
115
|
+
`Plug: ${this.accessory.displayName} failed pushChanges`,
|
|
116
|
+
);
|
|
117
|
+
if (this.deviceLogging.includes("debug")) {
|
|
118
|
+
this.errorLog(
|
|
119
|
+
`Plug: ${this.accessory.displayName} failed pushChanges,` +
|
|
120
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
121
|
+
);
|
|
114
122
|
}
|
|
115
123
|
this.apiError(e);
|
|
116
124
|
}
|
|
@@ -120,7 +128,7 @@ export class Plug {
|
|
|
120
128
|
|
|
121
129
|
parseStatus() {
|
|
122
130
|
switch (this.power) {
|
|
123
|
-
case
|
|
131
|
+
case "on":
|
|
124
132
|
this.On = true;
|
|
125
133
|
break;
|
|
126
134
|
default:
|
|
@@ -131,57 +139,74 @@ export class Plug {
|
|
|
131
139
|
|
|
132
140
|
private async refreshStatus() {
|
|
133
141
|
try {
|
|
134
|
-
this.deviceStatus = (
|
|
135
|
-
|
|
142
|
+
this.deviceStatus = (
|
|
143
|
+
await this.platform.axios.get(
|
|
144
|
+
`${settings.DeviceURL}/${this.device.deviceId}/status`,
|
|
145
|
+
)
|
|
146
|
+
).data;
|
|
147
|
+
this.debugLog(
|
|
148
|
+
`Plug: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(
|
|
149
|
+
this.deviceStatus,
|
|
150
|
+
)}`,
|
|
151
|
+
);
|
|
136
152
|
this.power = this.deviceStatus.body.power;
|
|
137
153
|
this.parseStatus();
|
|
138
154
|
this.updateHomeKitCharacteristics();
|
|
139
155
|
} catch (e: any) {
|
|
140
|
-
this.errorLog(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
156
|
+
this.errorLog(
|
|
157
|
+
`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`,
|
|
158
|
+
);
|
|
159
|
+
if (this.deviceLogging.includes("debug")) {
|
|
160
|
+
this.errorLog(
|
|
161
|
+
`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
162
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
163
|
+
);
|
|
148
164
|
}
|
|
149
165
|
this.apiError(e);
|
|
150
166
|
}
|
|
151
167
|
}
|
|
152
168
|
|
|
153
169
|
/**
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
170
|
+
* Pushes the requested changes to the SwitchBot API
|
|
171
|
+
* deviceType commandType Command command parameter Description
|
|
172
|
+
* Plug - "command" "turnOff" "default" = set to OFF state
|
|
173
|
+
* Plug - "command" "turnOn" "default" = set to ON state
|
|
174
|
+
*/
|
|
159
175
|
async pushChanges() {
|
|
160
176
|
if (this.On !== this.OnCached) {
|
|
161
177
|
const payload = {
|
|
162
|
-
commandType:
|
|
163
|
-
parameter:
|
|
164
|
-
} as payload;
|
|
178
|
+
commandType: "command",
|
|
179
|
+
parameter: "default",
|
|
180
|
+
} as settings.payload;
|
|
165
181
|
|
|
166
182
|
if (this.On) {
|
|
167
|
-
payload.command =
|
|
183
|
+
payload.command = "turnOn";
|
|
168
184
|
} else {
|
|
169
|
-
payload.command =
|
|
185
|
+
payload.command = "turnOff";
|
|
170
186
|
}
|
|
171
187
|
|
|
172
|
-
this.infoLog(
|
|
173
|
-
|
|
188
|
+
this.infoLog(
|
|
189
|
+
`Plug: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
190
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
191
|
+
);
|
|
174
192
|
|
|
175
193
|
// Make the API request
|
|
176
|
-
const push: any =
|
|
177
|
-
|
|
194
|
+
const push: any = await this.platform.axios.post(
|
|
195
|
+
`${settings.DeviceURL}/${this.device.deviceId}/commands`,
|
|
196
|
+
payload,
|
|
197
|
+
);
|
|
198
|
+
this.debugLog(
|
|
199
|
+
`Plug: ${this.accessory.displayName} pushchanges: ${JSON.stringify(
|
|
200
|
+
push.data,
|
|
201
|
+
)}`,
|
|
202
|
+
);
|
|
178
203
|
this.statusCode(push);
|
|
179
204
|
this.OnCached = this.On;
|
|
180
205
|
this.accessory.context.On = this.OnCached;
|
|
181
206
|
}
|
|
182
|
-
interval(5000)
|
|
183
|
-
.pipe(skipWhile(() => this.plugUpdateInProgress))
|
|
184
|
-
.pipe(take(1))
|
|
207
|
+
rxjs.interval(5000)
|
|
208
|
+
.pipe(operators.skipWhile(() => this.plugUpdateInProgress))
|
|
209
|
+
.pipe(operators.take(1))
|
|
185
210
|
.subscribe(() => {
|
|
186
211
|
this.refreshStatus();
|
|
187
212
|
});
|
|
@@ -191,8 +216,13 @@ export class Plug {
|
|
|
191
216
|
if (this.On === undefined) {
|
|
192
217
|
this.debugLog(`Plug: ${this.accessory.displayName} On: ${this.On}`);
|
|
193
218
|
} else {
|
|
194
|
-
this.service.updateCharacteristic(
|
|
195
|
-
|
|
219
|
+
this.service.updateCharacteristic(
|
|
220
|
+
this.platform.Characteristic.On,
|
|
221
|
+
this.On,
|
|
222
|
+
);
|
|
223
|
+
this.debugLog(
|
|
224
|
+
`Plug: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
|
|
225
|
+
);
|
|
196
226
|
}
|
|
197
227
|
}
|
|
198
228
|
|
|
@@ -201,119 +231,155 @@ export class Plug {
|
|
|
201
231
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
202
232
|
}
|
|
203
233
|
|
|
204
|
-
private statusCode(push: AxiosResponse<{ statusCode: number
|
|
234
|
+
private statusCode(push: axios.AxiosResponse<{ statusCode: number }>) {
|
|
205
235
|
switch (push.data.statusCode) {
|
|
206
236
|
case 151:
|
|
207
|
-
this.errorLog(
|
|
237
|
+
this.errorLog(
|
|
238
|
+
`Plug: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
239
|
+
);
|
|
208
240
|
break;
|
|
209
241
|
case 152:
|
|
210
242
|
this.errorLog(`Plug: ${this.accessory.displayName} Device not found.`);
|
|
211
243
|
break;
|
|
212
244
|
case 160:
|
|
213
|
-
this.errorLog(
|
|
245
|
+
this.errorLog(
|
|
246
|
+
`Plug: ${this.accessory.displayName} Command is not supported.`,
|
|
247
|
+
);
|
|
214
248
|
break;
|
|
215
249
|
case 161:
|
|
216
250
|
this.errorLog(`Plug: ${this.accessory.displayName} Device is offline.`);
|
|
217
251
|
this.offlineOff();
|
|
218
252
|
break;
|
|
219
253
|
case 171:
|
|
220
|
-
this.errorLog(
|
|
254
|
+
this.errorLog(
|
|
255
|
+
`Plug: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
256
|
+
);
|
|
221
257
|
this.offlineOff();
|
|
222
258
|
break;
|
|
223
259
|
case 190:
|
|
224
|
-
this.errorLog(
|
|
225
|
-
|
|
260
|
+
this.errorLog(
|
|
261
|
+
`Plug: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
262
|
+
` Or command: ${JSON.stringify(push.data)} format is invalid`,
|
|
263
|
+
);
|
|
226
264
|
break;
|
|
227
265
|
case 100:
|
|
228
|
-
this.debugLog(
|
|
266
|
+
this.debugLog(
|
|
267
|
+
`Plug: ${this.accessory.displayName} Command successfully sent.`,
|
|
268
|
+
);
|
|
229
269
|
break;
|
|
230
270
|
default:
|
|
231
|
-
this.debugLog(
|
|
271
|
+
this.debugLog(
|
|
272
|
+
`Plug: ${this.accessory.displayName} Unknown statusCode.`,
|
|
273
|
+
);
|
|
232
274
|
}
|
|
233
275
|
}
|
|
234
276
|
|
|
235
277
|
private offlineOff() {
|
|
236
278
|
if (this.device.offline) {
|
|
237
279
|
this.On = false;
|
|
238
|
-
this.service
|
|
280
|
+
this.service
|
|
281
|
+
.getCharacteristic(this.platform.Characteristic.On)
|
|
282
|
+
.updateValue(this.On);
|
|
239
283
|
}
|
|
240
284
|
}
|
|
241
285
|
|
|
242
286
|
/**
|
|
243
287
|
* Handle requests to set the value of the "On" characteristic
|
|
244
288
|
*/
|
|
245
|
-
OnSet(value: CharacteristicValue) {
|
|
289
|
+
OnSet(value: homebridge.CharacteristicValue) {
|
|
246
290
|
this.debugLog(`Plug: ${this.accessory.displayName} - Set On: ${value}`);
|
|
247
291
|
|
|
248
292
|
this.On = value;
|
|
249
293
|
this.doPlugUpdate.next();
|
|
250
294
|
}
|
|
251
295
|
|
|
252
|
-
config(device: device & devicesConfig) {
|
|
296
|
+
config(device: settings.device & settings.devicesConfig) {
|
|
253
297
|
let config = {};
|
|
254
298
|
if (device.plug) {
|
|
255
299
|
config = device.plug;
|
|
256
300
|
}
|
|
257
301
|
if (device.ble !== undefined) {
|
|
258
|
-
config[
|
|
302
|
+
config["ble"] = device.ble;
|
|
259
303
|
}
|
|
260
304
|
if (device.logging !== undefined) {
|
|
261
|
-
config[
|
|
305
|
+
config["logging"] = device.logging;
|
|
262
306
|
}
|
|
263
307
|
if (device.refreshRate !== undefined) {
|
|
264
|
-
config[
|
|
308
|
+
config["refreshRate"] = device.refreshRate;
|
|
265
309
|
}
|
|
266
310
|
if (device.scanDuration !== undefined) {
|
|
267
|
-
config[
|
|
311
|
+
config["scanDuration"] = device.scanDuration;
|
|
268
312
|
}
|
|
269
313
|
if (Object.entries(config).length !== 0) {
|
|
270
|
-
this.warnLog(
|
|
314
|
+
this.warnLog(
|
|
315
|
+
`Plug: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`,
|
|
316
|
+
);
|
|
271
317
|
}
|
|
272
318
|
}
|
|
273
319
|
|
|
274
|
-
refreshRate(device: device & devicesConfig) {
|
|
320
|
+
refreshRate(device: settings.device & settings.devicesConfig) {
|
|
275
321
|
if (device.refreshRate) {
|
|
276
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
277
|
-
|
|
322
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
323
|
+
device.refreshRate;
|
|
324
|
+
this.debugLog(
|
|
325
|
+
`Plug: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`,
|
|
326
|
+
);
|
|
278
327
|
} else if (this.platform.config.options!.refreshRate) {
|
|
279
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
280
|
-
|
|
328
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
329
|
+
this.platform.config.options!.refreshRate;
|
|
330
|
+
this.debugLog(
|
|
331
|
+
`Plug: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`,
|
|
332
|
+
);
|
|
281
333
|
}
|
|
282
334
|
}
|
|
283
335
|
|
|
284
|
-
scan(device: device & devicesConfig) {
|
|
336
|
+
scan(device: settings.device & settings.devicesConfig) {
|
|
285
337
|
if (device.scanDuration) {
|
|
286
|
-
this.scanDuration = this.accessory.context.scanDuration =
|
|
338
|
+
this.scanDuration = this.accessory.context.scanDuration =
|
|
339
|
+
device.scanDuration;
|
|
287
340
|
if (device.ble) {
|
|
288
|
-
this.debugLog(
|
|
341
|
+
this.debugLog(
|
|
342
|
+
`Plug: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`,
|
|
343
|
+
);
|
|
289
344
|
}
|
|
290
345
|
} else {
|
|
291
346
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
292
347
|
if (this.device.ble) {
|
|
293
|
-
this.debugLog(
|
|
348
|
+
this.debugLog(
|
|
349
|
+
`Plug: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`,
|
|
350
|
+
);
|
|
294
351
|
}
|
|
295
352
|
}
|
|
296
353
|
}
|
|
297
354
|
|
|
298
|
-
logs(device: device & devicesConfig) {
|
|
355
|
+
logs(device: settings.device & settings.devicesConfig) {
|
|
299
356
|
if (this.platform.debugMode) {
|
|
300
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
301
|
-
this.debugLog(
|
|
357
|
+
this.deviceLogging = this.accessory.context.logging = "debugMode";
|
|
358
|
+
this.debugLog(
|
|
359
|
+
`Plug: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
360
|
+
);
|
|
302
361
|
} else if (device.logging) {
|
|
303
362
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
304
|
-
this.debugLog(
|
|
363
|
+
this.debugLog(
|
|
364
|
+
`Plug: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
365
|
+
);
|
|
305
366
|
} else if (this.platform.config.options?.logging) {
|
|
306
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
307
|
-
|
|
367
|
+
this.deviceLogging = this.accessory.context.logging =
|
|
368
|
+
this.platform.config.options?.logging;
|
|
369
|
+
this.debugLog(
|
|
370
|
+
`Plug: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
371
|
+
);
|
|
308
372
|
} else {
|
|
309
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
310
|
-
this.debugLog(
|
|
373
|
+
this.deviceLogging = this.accessory.context.logging = "standard";
|
|
374
|
+
this.debugLog(
|
|
375
|
+
`Plug: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
376
|
+
);
|
|
311
377
|
}
|
|
312
378
|
}
|
|
313
379
|
|
|
314
380
|
/**
|
|
315
|
-
|
|
316
|
-
|
|
381
|
+
* Logging for Device
|
|
382
|
+
*/
|
|
317
383
|
infoLog(...log: any[]) {
|
|
318
384
|
if (this.enablingDeviceLogging()) {
|
|
319
385
|
this.platform.log.info(String(...log));
|
|
@@ -334,8 +400,8 @@ export class Plug {
|
|
|
334
400
|
|
|
335
401
|
debugLog(...log: any[]) {
|
|
336
402
|
if (this.enablingDeviceLogging()) {
|
|
337
|
-
if (this.deviceLogging ===
|
|
338
|
-
this.platform.log.info(
|
|
403
|
+
if (this.deviceLogging === "debug") {
|
|
404
|
+
this.platform.log.info("[DEBUG]", String(...log));
|
|
339
405
|
} else {
|
|
340
406
|
this.platform.log.debug(String(...log));
|
|
341
407
|
}
|
|
@@ -343,6 +409,8 @@ export class Plug {
|
|
|
343
409
|
}
|
|
344
410
|
|
|
345
411
|
enablingDeviceLogging(): boolean {
|
|
346
|
-
return
|
|
412
|
+
return (
|
|
413
|
+
this.deviceLogging.includes("debug") || this.deviceLogging === "standard"
|
|
414
|
+
);
|
|
347
415
|
}
|
|
348
|
-
}
|
|
416
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import * as homebridge from "homebridge";
|
|
2
|
+
import * as settings from "./settings";
|
|
3
|
+
import * as platform from "./platform";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* This method registers the platform with Homebridge
|
|
7
7
|
*/
|
|
8
|
-
export = (api: API): void => {
|
|
9
|
-
api.registerPlatform(PLATFORM_NAME, SwitchBotPlatform);
|
|
8
|
+
export = (api: homebridge.API): void => {
|
|
9
|
+
api.registerPlatform(settings.PLATFORM_NAME, platform.SwitchBotPlatform);
|
|
10
10
|
};
|