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