@switchbot/homebridge-switchbot 0.1.2-beta.7 → 0.2.0-alpha.1
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/.github/ISSUE_TEMPLATE/feature-request.yml +1 -1
- package/.github/dependabot.yml +2 -0
- package/.github/workflows/codeql-analysis.yml +71 -0
- package/CHANGELOG.md +5 -1
- package/README.md +2 -1
- package/config.schema.json +420 -471
- package/dist/devices/bots.d.ts +19 -5
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +172 -148
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/bulb.d.ts +8 -6
- package/dist/devices/bulb.d.ts.map +1 -1
- package/dist/devices/bulb.js +45 -28
- package/dist/devices/bulb.js.map +1 -1
- package/dist/devices/contact.d.ts +10 -5
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +94 -63
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +14 -5
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +174 -120
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +6 -6
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +78 -94
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/indoorcam.d.ts +43 -0
- package/dist/devices/indoorcam.d.ts.map +1 -0
- package/dist/devices/indoorcam.js +241 -0
- package/dist/devices/indoorcam.js.map +1 -0
- package/dist/devices/meters.d.ts +8 -5
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +126 -92
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +9 -5
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +74 -59
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +5 -4
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +65 -56
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +3 -3
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +12 -7
- 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 +1 -1
- 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 +1 -1
- 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 +11 -12
- 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 +1 -1
- 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 +8 -8
- 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 +16 -6
- 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 +2 -3
- 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 +2 -2
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +14 -5
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +420 -418
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +18 -15
- package/dist/settings.d.ts.map +1 -1
- package/package.json +65 -65
- package/src/devices/bots.ts +188 -165
- package/src/devices/bulb.ts +48 -40
- package/src/devices/contact.ts +100 -73
- package/src/devices/curtains.ts +192 -140
- package/src/devices/humidifiers.ts +82 -124
- package/src/devices/indoorcam.ts +303 -0
- package/src/devices/meters.ts +130 -110
- package/src/devices/motion.ts +80 -69
- package/src/devices/plugs.ts +67 -65
- package/src/irdevices/airconditioners.ts +14 -10
- package/src/irdevices/airpurifiers.ts +4 -4
- package/src/irdevices/cameras.ts +4 -4
- package/src/irdevices/fans.ts +14 -18
- package/src/irdevices/lights.ts +4 -4
- package/src/irdevices/others.ts +12 -14
- package/src/irdevices/tvs.ts +21 -10
- package/src/irdevices/vacuumcleaners.ts +5 -9
- package/src/irdevices/waterheaters.ts +5 -5
- package/src/platform.ts +455 -619
- package/src/settings.ts +19 -15
- package/.github/workflows/issue-validate.yml +0 -18
package/src/devices/plugs.ts
CHANGED
|
@@ -2,8 +2,7 @@ import { Service, PlatformAccessory, CharacteristicValue, MacAddress } from 'hom
|
|
|
2
2
|
import { SwitchBotPlatform } from '../platform';
|
|
3
3
|
import { interval, Subject } from 'rxjs';
|
|
4
4
|
import { debounceTime, skipWhile, tap } from 'rxjs/operators';
|
|
5
|
-
import { DeviceURL, device,
|
|
6
|
-
import { AxiosResponse } from 'axios';
|
|
5
|
+
import { DeviceURL, device, devicesConfig } from '../settings';
|
|
7
6
|
|
|
8
7
|
export class Plug {
|
|
9
8
|
// Services
|
|
@@ -14,7 +13,7 @@ export class Plug {
|
|
|
14
13
|
OutletInUse!: CharacteristicValue;
|
|
15
14
|
|
|
16
15
|
// Others
|
|
17
|
-
deviceStatus!:
|
|
16
|
+
deviceStatus!: any;
|
|
18
17
|
switchbot!: {
|
|
19
18
|
discover: (
|
|
20
19
|
arg0:
|
|
@@ -37,23 +36,21 @@ export class Plug {
|
|
|
37
36
|
constructor(
|
|
38
37
|
private readonly platform: SwitchBotPlatform,
|
|
39
38
|
private accessory: PlatformAccessory,
|
|
40
|
-
public device: device,
|
|
39
|
+
public device: device & devicesConfig,
|
|
41
40
|
) {
|
|
42
41
|
// default placeholders
|
|
43
42
|
this.On = false;
|
|
44
43
|
this.OutletInUse = true;
|
|
45
44
|
|
|
46
45
|
// BLE Connections
|
|
47
|
-
if (
|
|
46
|
+
if (device.ble) {
|
|
48
47
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
49
48
|
const SwitchBot = require('node-switchbot');
|
|
50
49
|
this.switchbot = new SwitchBot();
|
|
51
50
|
const colon = device.deviceId!.match(/.{1,2}/g);
|
|
52
51
|
const bleMac = colon!.join(':'); //returns 1A:23:B4:56:78:9A;
|
|
53
52
|
this.device.bleMac = bleMac.toLowerCase();
|
|
54
|
-
|
|
55
|
-
this.platform.log.warn(this.device.bleMac.toLowerCase());
|
|
56
|
-
}
|
|
53
|
+
this.platform.device(this.device.bleMac.toLowerCase());
|
|
57
54
|
}
|
|
58
55
|
|
|
59
56
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
@@ -135,76 +132,75 @@ export class Plug {
|
|
|
135
132
|
}
|
|
136
133
|
|
|
137
134
|
async refreshStatus() {
|
|
138
|
-
if (this.
|
|
139
|
-
this.platform.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
135
|
+
if (this.device.ble) {
|
|
136
|
+
this.platform.device('BLE');
|
|
137
|
+
await this.BLErefreshStatus();
|
|
138
|
+
} else {
|
|
139
|
+
this.platform.device('OpenAPI');
|
|
140
|
+
await this.openAPIRefreshStatus();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private async BLErefreshStatus() {
|
|
145
|
+
this.platform.debug('Plug BLE Device RefreshStatus');
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
147
|
+
const Switchbot = require('node-switchbot');
|
|
148
|
+
const switchbot = new Switchbot();
|
|
149
|
+
const colon = this.device.deviceId!.match(/.{1,2}/g);
|
|
150
|
+
const bleMac = colon!.join(':'); //returns 1A:23:B4:56:78:9A;
|
|
151
|
+
this.device.bleMac = bleMac.toLowerCase();
|
|
152
|
+
this.platform.device(this.device.bleMac!);
|
|
153
|
+
switchbot.onadvertisement = (ad: any) => {
|
|
154
|
+
this.platform.debug(JSON.stringify(ad, null, ' '));
|
|
155
|
+
this.platform.device('ad:', JSON.stringify(ad));
|
|
156
|
+
};
|
|
157
|
+
this.parseStatus();
|
|
158
|
+
this.updateHomeKitCharacteristics();
|
|
159
|
+
switchbot
|
|
160
|
+
.startScan({
|
|
161
|
+
id: this.device.bleMac,
|
|
162
|
+
})
|
|
163
|
+
.then(() => {
|
|
164
|
+
return switchbot.wait(this.platform.config.options!.refreshRate! * 1000);
|
|
165
|
+
})
|
|
166
|
+
.then(() => {
|
|
167
|
+
switchbot.stopScan();
|
|
168
|
+
})
|
|
169
|
+
.catch(async (error: any) => {
|
|
170
|
+
this.platform.log.error(error);
|
|
171
|
+
await this.openAPIRefreshStatus();
|
|
172
|
+
});
|
|
173
|
+
setInterval(() => {
|
|
174
|
+
this.platform.log.info('Start scan ' + this.device.deviceName + '(' + this.device.bleMac + ')');
|
|
153
175
|
switchbot
|
|
154
176
|
.startScan({
|
|
155
|
-
|
|
177
|
+
mode: 'T',
|
|
178
|
+
id: bleMac,
|
|
156
179
|
})
|
|
157
180
|
.then(() => {
|
|
158
181
|
return switchbot.wait(this.platform.config.options!.refreshRate! * 1000);
|
|
159
182
|
})
|
|
160
183
|
.then(() => {
|
|
161
184
|
switchbot.stopScan();
|
|
185
|
+
this.platform.log.info('Stop scan ' + this.device.deviceName + '(' + this.device.bleMac + ')');
|
|
162
186
|
})
|
|
163
187
|
.catch(async (error: any) => {
|
|
164
188
|
this.platform.log.error(error);
|
|
165
189
|
await this.openAPIRefreshStatus();
|
|
166
190
|
});
|
|
167
|
-
|
|
168
|
-
this.platform.log.info('Start scan ' + this.device.deviceName + '(' + this.device.bleMac + ')');
|
|
169
|
-
switchbot
|
|
170
|
-
.startScan({
|
|
171
|
-
mode: 'T',
|
|
172
|
-
id: bleMac,
|
|
173
|
-
})
|
|
174
|
-
.then(() => {
|
|
175
|
-
return switchbot.wait(this.platform.config.options!.refreshRate! * 1000);
|
|
176
|
-
})
|
|
177
|
-
.then(() => {
|
|
178
|
-
switchbot.stopScan();
|
|
179
|
-
this.platform.log.info('Stop scan ' + this.device.deviceName + '(' + this.device.bleMac + ')');
|
|
180
|
-
})
|
|
181
|
-
.catch(async (error: any) => {
|
|
182
|
-
this.platform.log.error(error);
|
|
183
|
-
await this.openAPIRefreshStatus();
|
|
184
|
-
});
|
|
185
|
-
}, this.platform.config.options!.refreshRate! * 60000);
|
|
186
|
-
} else {
|
|
187
|
-
await this.openAPIRefreshStatus();
|
|
188
|
-
}
|
|
191
|
+
}, this.platform.config.options!.refreshRate! * 60000);
|
|
189
192
|
}
|
|
190
193
|
|
|
191
194
|
private async openAPIRefreshStatus() {
|
|
192
195
|
try {
|
|
193
196
|
this.platform.debug('Plug - Reading', `${DeviceURL}/${this.device.deviceId}/status`);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
this.deviceStatus = deviceStatus;
|
|
199
|
-
this.platform.log.warn(`Plug ${this.accessory.displayName} refreshStatus - ${JSON.stringify(this.deviceStatus)}`);
|
|
200
|
-
this.parseStatus();
|
|
201
|
-
this.updateHomeKitCharacteristics();
|
|
202
|
-
}
|
|
197
|
+
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
198
|
+
this.platform.device(`Plug ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
199
|
+
this.parseStatus();
|
|
200
|
+
this.updateHomeKitCharacteristics();
|
|
203
201
|
} catch (e: any) {
|
|
204
|
-
this.platform.log.error(
|
|
205
|
-
|
|
206
|
-
JSON.stringify(e.message),
|
|
207
|
-
this.platform.debug(`Plug ${this.accessory.displayName} - ${JSON.stringify(e)}`));
|
|
202
|
+
this.platform.log.error(`Plug ${this.accessory.displayName} failed to refresh status, Error Message: ${JSON.stringify(e.message)}`);
|
|
203
|
+
this.platform.debug(`Plug ${this.accessory.displayName}, Error: ${JSON.stringify(e)}`);
|
|
208
204
|
this.apiError(e);
|
|
209
205
|
}
|
|
210
206
|
}
|
|
@@ -237,20 +233,26 @@ export class Plug {
|
|
|
237
233
|
'commandType:',
|
|
238
234
|
payload.commandType,
|
|
239
235
|
);
|
|
240
|
-
this.platform.debug(`Plug ${this.accessory.displayName}
|
|
236
|
+
this.platform.debug(`Plug ${this.accessory.displayName} pushchanges: ${JSON.stringify(payload)}`);
|
|
241
237
|
|
|
242
238
|
// Make the API request
|
|
243
|
-
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
244
|
-
this.platform.debug(`Plug ${this.accessory.displayName} Changes pushed
|
|
239
|
+
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
240
|
+
this.platform.debug(`Plug ${this.accessory.displayName} Changes pushed: ${JSON.stringify(push.data)}`);
|
|
245
241
|
this.statusCode(push);
|
|
246
242
|
}
|
|
247
243
|
|
|
248
244
|
updateHomeKitCharacteristics() {
|
|
249
|
-
if (this.On
|
|
245
|
+
if (this.On === undefined) {
|
|
246
|
+
this.platform.debug(`Plug ${this.accessory.displayName} On: ${this.On}`);
|
|
247
|
+
} else {
|
|
250
248
|
this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
249
|
+
this.platform.device(`Plug ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
251
250
|
}
|
|
252
|
-
if (this.OutletInUse
|
|
251
|
+
if (this.OutletInUse === undefined) {
|
|
252
|
+
this.platform.debug(`Plug ${this.accessory.displayName} OutletInUse: ${this.OutletInUse}`);
|
|
253
|
+
} else {
|
|
253
254
|
this.service.updateCharacteristic(this.platform.Characteristic.OutletInUse, this.OutletInUse);
|
|
255
|
+
this.platform.device(`Plug ${this.accessory.displayName} updateCharacteristic OutletInUse: ${this.OutletInUse}`);
|
|
254
256
|
}
|
|
255
257
|
}
|
|
256
258
|
|
|
@@ -260,7 +262,7 @@ export class Plug {
|
|
|
260
262
|
}
|
|
261
263
|
|
|
262
264
|
|
|
263
|
-
private statusCode(push:
|
|
265
|
+
private statusCode(push: { data: { statusCode: any; }; }) {
|
|
264
266
|
switch (push.data.statusCode) {
|
|
265
267
|
case 151:
|
|
266
268
|
this.platform.log.error('Command not supported by this device type.');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
|
-
import { DeviceURL, irdevice } from '../settings';
|
|
4
|
+
import { devicesConfig, DeviceURL, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -32,20 +32,20 @@ export class AirConditioner {
|
|
|
32
32
|
constructor(
|
|
33
33
|
private readonly platform: SwitchBotPlatform,
|
|
34
34
|
private accessory: PlatformAccessory,
|
|
35
|
-
public device: irdevice,
|
|
35
|
+
public device: irdevice & devicesConfig,
|
|
36
36
|
) {
|
|
37
37
|
// set accessory information
|
|
38
38
|
accessory
|
|
39
39
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
40
40
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
41
41
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
42
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
|
|
42
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
43
43
|
|
|
44
44
|
// get the Television service if it exists, otherwise create a new Television service
|
|
45
45
|
// you can create multiple services for each accessory
|
|
46
46
|
(this.service =
|
|
47
47
|
accessory.getService(this.platform.Service.HeaterCooler) ||
|
|
48
|
-
accessory.addService(this.platform.Service.HeaterCooler)), `${
|
|
48
|
+
accessory.addService(this.platform.Service.HeaterCooler)), `${accessory.displayName} Air Conditioner`;
|
|
49
49
|
|
|
50
50
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
51
51
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -66,10 +66,10 @@ export class AirConditioner {
|
|
|
66
66
|
minStep: 0.01,
|
|
67
67
|
})
|
|
68
68
|
.onGet((value: CharacteristicValue) => {
|
|
69
|
-
return this.CurrentTemperatureGet(value);
|
|
69
|
+
return this.CurrentTemperatureGet(Number(value));
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
if (
|
|
72
|
+
if (device.irair?.hide_automode) {
|
|
73
73
|
this.ValidValues = [1, 2];
|
|
74
74
|
} else {
|
|
75
75
|
this.ValidValues = [0, 1, 2];
|
|
@@ -159,10 +159,14 @@ export class AirConditioner {
|
|
|
159
159
|
private CurrentTemperatureGet(value: CharacteristicValue) {
|
|
160
160
|
this.platform.debug('Trigger Get CurrentTemperture');
|
|
161
161
|
|
|
162
|
-
this.
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
if (Number.isNaN(this.CurrentTemperature)) {
|
|
163
|
+
this.CurrentTemperature = 24;
|
|
164
|
+
} else {
|
|
165
|
+
this.service
|
|
166
|
+
.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
|
|
167
|
+
.updateValue(Number(this.CurrentTemperature) || 24);
|
|
168
|
+
}
|
|
169
|
+
return (this.CurrentTemperature === Number(value));
|
|
166
170
|
}
|
|
167
171
|
|
|
168
172
|
private TargetHeaterCoolerStateSet(value: CharacteristicValue) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
|
-
import { DeviceURL, irdevice } from '../settings';
|
|
4
|
+
import { devicesConfig, DeviceURL, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -31,20 +31,20 @@ export class AirPurifier {
|
|
|
31
31
|
constructor(
|
|
32
32
|
private readonly platform: SwitchBotPlatform,
|
|
33
33
|
private accessory: PlatformAccessory,
|
|
34
|
-
public device: irdevice,
|
|
34
|
+
public device: irdevice & devicesConfig,
|
|
35
35
|
) {
|
|
36
36
|
// set accessory information
|
|
37
37
|
accessory
|
|
38
38
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
39
39
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
40
40
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
41
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
|
|
41
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
42
42
|
|
|
43
43
|
// get the Television service if it exists, otherwise create a new Television service
|
|
44
44
|
// you can create multiple services for each accessory
|
|
45
45
|
(this.service =
|
|
46
46
|
accessory.getService(this.platform.Service.AirPurifier) ||
|
|
47
|
-
accessory.addService(this.platform.Service.AirPurifier)), `${
|
|
47
|
+
accessory.addService(this.platform.Service.AirPurifier)), `${accessory.displayName} Air Purifier`;
|
|
48
48
|
|
|
49
49
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
50
50
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
package/src/irdevices/cameras.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
|
-
import { DeviceURL, irdevice } from '../settings';
|
|
4
|
+
import { devicesConfig, DeviceURL, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -16,20 +16,20 @@ export class Camera {
|
|
|
16
16
|
constructor(
|
|
17
17
|
private readonly platform: SwitchBotPlatform,
|
|
18
18
|
private accessory: PlatformAccessory,
|
|
19
|
-
public device: irdevice,
|
|
19
|
+
public device: irdevice & devicesConfig,
|
|
20
20
|
) {
|
|
21
21
|
// set accessory information
|
|
22
22
|
accessory
|
|
23
23
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
24
24
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
25
25
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
26
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
|
|
26
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
27
27
|
|
|
28
28
|
// get the Television service if it exists, otherwise create a new Television service
|
|
29
29
|
// you can create multiple services for each accessory
|
|
30
30
|
(this.service =
|
|
31
31
|
accessory.getService(this.platform.Service.Switch) ||
|
|
32
|
-
accessory.addService(this.platform.Service.Switch)), `${
|
|
32
|
+
accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Camera`;
|
|
33
33
|
|
|
34
34
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
35
35
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
package/src/irdevices/fans.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
|
-
import { DeviceURL, irdevice, deviceStatusResponse } from '../settings';
|
|
4
|
+
import { DeviceURL, irdevice, deviceStatusResponse, devicesConfig } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -24,20 +24,20 @@ export class Fan {
|
|
|
24
24
|
constructor(
|
|
25
25
|
private readonly platform: SwitchBotPlatform,
|
|
26
26
|
private accessory: PlatformAccessory,
|
|
27
|
-
public device: irdevice,
|
|
27
|
+
public device: irdevice & devicesConfig,
|
|
28
28
|
) {
|
|
29
29
|
// set accessory information
|
|
30
30
|
accessory
|
|
31
31
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
32
32
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
33
33
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
34
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
|
|
34
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
35
35
|
|
|
36
36
|
// get the Television service if it exists, otherwise create a new Television service
|
|
37
37
|
// you can create multiple services for each accessory
|
|
38
38
|
(this.service =
|
|
39
39
|
accessory.getService(this.platform.Service.Fanv2) ||
|
|
40
|
-
accessory.addService(this.platform.Service.Fanv2)), `${
|
|
40
|
+
accessory.addService(this.platform.Service.Fanv2)), `${accessory.displayName} Fan`;
|
|
41
41
|
|
|
42
42
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
43
43
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -50,19 +50,19 @@ export class Fan {
|
|
|
50
50
|
// handle on / off events using the Active characteristic
|
|
51
51
|
this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
52
52
|
|
|
53
|
-
if (
|
|
54
|
-
if (
|
|
55
|
-
this.minStep =
|
|
53
|
+
if (device.fan?.rotation_speed) {
|
|
54
|
+
if (device.fan?.set_minStep) {
|
|
55
|
+
this.minStep = device.fan?.set_minStep;
|
|
56
56
|
} else {
|
|
57
57
|
this.minStep = 1;
|
|
58
58
|
}
|
|
59
|
-
if (
|
|
60
|
-
this.minValue =
|
|
59
|
+
if (device.fan?.set_min) {
|
|
60
|
+
this.minValue = device.fan?.set_min;
|
|
61
61
|
} else {
|
|
62
62
|
this.minValue = 1;
|
|
63
63
|
}
|
|
64
|
-
if (
|
|
65
|
-
this.maxValue =
|
|
64
|
+
if (device.fan?.set_max) {
|
|
65
|
+
this.maxValue = device.fan?.set_max;
|
|
66
66
|
} else {
|
|
67
67
|
this.maxValue = 100;
|
|
68
68
|
}
|
|
@@ -77,8 +77,7 @@ export class Fan {
|
|
|
77
77
|
.onSet(this.RotationSpeedSet.bind(this));
|
|
78
78
|
} else if (
|
|
79
79
|
this.service.testCharacteristic(this.platform.Characteristic.RotationSpeed) &&
|
|
80
|
-
!
|
|
81
|
-
) {
|
|
80
|
+
!device.fan?.swing_mode) {
|
|
82
81
|
const characteristic = this.service.getCharacteristic(this.platform.Characteristic.RotationSpeed);
|
|
83
82
|
this.service.removeCharacteristic(characteristic);
|
|
84
83
|
this.platform.log.warn('Rotation Speed Characteristic was removed.');
|
|
@@ -88,13 +87,10 @@ export class Fan {
|
|
|
88
87
|
);
|
|
89
88
|
}
|
|
90
89
|
|
|
91
|
-
if (
|
|
90
|
+
if (device.fan?.swing_mode) {
|
|
92
91
|
// handle Osolcation events using the SwingMode characteristic
|
|
93
92
|
this.service.getCharacteristic(this.platform.Characteristic.SwingMode).onSet(this.SwingModeSet.bind(this));
|
|
94
|
-
} else if (
|
|
95
|
-
this.service.testCharacteristic(this.platform.Characteristic.SwingMode) &&
|
|
96
|
-
!this.platform.config.options?.fan?.swing_mode?.includes(device.deviceId)
|
|
97
|
-
) {
|
|
93
|
+
} else if (this.service.testCharacteristic(this.platform.Characteristic.SwingMode) && !device.fan?.swing_mode) {
|
|
98
94
|
const characteristic = this.service.getCharacteristic(this.platform.Characteristic.SwingMode);
|
|
99
95
|
this.service.removeCharacteristic(characteristic);
|
|
100
96
|
this.platform.log.warn('Swing Mode Characteristic was removed.');
|
package/src/irdevices/lights.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
|
-
import { DeviceURL, irdevice } from '../settings';
|
|
4
|
+
import { devicesConfig, DeviceURL, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -16,20 +16,20 @@ export class Light {
|
|
|
16
16
|
constructor(
|
|
17
17
|
private readonly platform: SwitchBotPlatform,
|
|
18
18
|
private accessory: PlatformAccessory,
|
|
19
|
-
public device: irdevice,
|
|
19
|
+
public device: irdevice & devicesConfig,
|
|
20
20
|
) {
|
|
21
21
|
// set accessory information
|
|
22
22
|
accessory
|
|
23
23
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
24
24
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
25
25
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
26
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
|
|
26
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
27
27
|
|
|
28
28
|
// get the Television service if it exists, otherwise create a new Television service
|
|
29
29
|
// you can create multiple services for each accessory
|
|
30
30
|
(this.service =
|
|
31
31
|
accessory.getService(this.platform.Service.Lightbulb) ||
|
|
32
|
-
accessory.addService(this.platform.Service.Lightbulb)), `${
|
|
32
|
+
accessory.addService(this.platform.Service.Lightbulb)), `${accessory.displayName} Light Bulb`;
|
|
33
33
|
|
|
34
34
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
35
35
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
package/src/irdevices/others.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
|
-
import { DeviceURL, irdevice } from '../settings';
|
|
4
|
+
import { devicesConfig, DeviceURL, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -16,23 +16,21 @@ export class Others {
|
|
|
16
16
|
constructor(
|
|
17
17
|
private readonly platform: SwitchBotPlatform,
|
|
18
18
|
private accessory: PlatformAccessory,
|
|
19
|
-
public device: irdevice,
|
|
19
|
+
public device: irdevice & devicesConfig,
|
|
20
20
|
) {
|
|
21
21
|
// set accessory information
|
|
22
22
|
accessory
|
|
23
23
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
24
24
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
25
25
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
26
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
|
|
26
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
27
27
|
|
|
28
28
|
// get the Television service if it exists, otherwise create a new Television service
|
|
29
29
|
// you can create multiple services for each accessory
|
|
30
30
|
this.service = accessory.getService(this.platform.Service.Fanv2);
|
|
31
|
-
if (!this.service &&
|
|
32
|
-
this.service = accessory.addService(
|
|
33
|
-
|
|
34
|
-
`${device.deviceName} ${device.remoteType} Fan`,
|
|
35
|
-
);
|
|
31
|
+
if (!this.service && device?.other?.deviceType === 'Fan') {
|
|
32
|
+
this.service = accessory.addService(this.platform.Service.Fanv2, `${accessory.displayName} Fan`);
|
|
33
|
+
|
|
36
34
|
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
37
35
|
|
|
38
36
|
this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
@@ -64,13 +62,13 @@ export class Others {
|
|
|
64
62
|
*/
|
|
65
63
|
async pushOnChanges() {
|
|
66
64
|
if (this.platform.config.options) {
|
|
67
|
-
if (this.
|
|
68
|
-
if (this.
|
|
65
|
+
if (this.device.other) {
|
|
66
|
+
if (this.device.other.commandOn) {
|
|
69
67
|
if (this.Active) {
|
|
70
68
|
const payload = {
|
|
71
69
|
commandType: 'customize',
|
|
72
70
|
parameter: 'default',
|
|
73
|
-
command: `${this.
|
|
71
|
+
command: `${this.device.other.commandOn}`,
|
|
74
72
|
} as any;
|
|
75
73
|
await this.pushChanges(payload);
|
|
76
74
|
}
|
|
@@ -87,13 +85,13 @@ export class Others {
|
|
|
87
85
|
|
|
88
86
|
async pushOffChanges() {
|
|
89
87
|
if (this.platform.config.options) {
|
|
90
|
-
if (this.
|
|
91
|
-
if (this.
|
|
88
|
+
if (this.device.other) {
|
|
89
|
+
if (this.device.other.commandOff) {
|
|
92
90
|
if (!this.Active) {
|
|
93
91
|
const payload = {
|
|
94
92
|
commandType: 'customize',
|
|
95
93
|
parameter: 'default',
|
|
96
|
-
command: `${this.
|
|
94
|
+
command: `${this.device.other.commandOff}`,
|
|
97
95
|
} as any;
|
|
98
96
|
await this.pushChanges(payload);
|
|
99
97
|
}
|
package/src/irdevices/tvs.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
|
-
import { DeviceURL, irdevice, deviceStatusResponse } from '../settings';
|
|
4
|
+
import { DeviceURL, irdevice, deviceStatusResponse, devicesConfig } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -19,7 +19,7 @@ export class TV {
|
|
|
19
19
|
constructor(
|
|
20
20
|
private readonly platform: SwitchBotPlatform,
|
|
21
21
|
private accessory: PlatformAccessory,
|
|
22
|
-
public device: irdevice,
|
|
22
|
+
public device: irdevice & devicesConfig,
|
|
23
23
|
) {
|
|
24
24
|
// set accessory information
|
|
25
25
|
accessory
|
|
@@ -27,33 +27,42 @@ export class TV {
|
|
|
27
27
|
.setCharacteristic(this.platform.Characteristic.Name, `${device.deviceName} ${device.remoteType}`)
|
|
28
28
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
29
29
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
30
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
|
|
30
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
31
31
|
|
|
32
32
|
// set the accessory category
|
|
33
33
|
switch (device.remoteType) {
|
|
34
34
|
case 'Speaker':
|
|
35
35
|
case 'DIY Speaker':
|
|
36
36
|
accessory.category = this.platform.api.hap.Categories.SPEAKER;
|
|
37
|
+
(this.service =
|
|
38
|
+
accessory.getService(this.platform.Service.Television) ||
|
|
39
|
+
accessory.addService(this.platform.Service.Television)), `${accessory.displayName} Speaker`;
|
|
37
40
|
break;
|
|
38
41
|
case 'IPTV':
|
|
39
42
|
case 'DIY IPTV':
|
|
40
43
|
accessory.category = this.platform.api.hap.Categories.TV_STREAMING_STICK;
|
|
44
|
+
(this.service =
|
|
45
|
+
accessory.getService(this.platform.Service.Television) ||
|
|
46
|
+
accessory.addService(this.platform.Service.Television)), `${accessory.displayName} Streaming Stick`;
|
|
41
47
|
break;
|
|
42
48
|
case 'DVD':
|
|
43
49
|
case 'DIY DVD':
|
|
44
50
|
case 'Set Top Box':
|
|
45
51
|
case 'DIY Set Top Box':
|
|
46
52
|
accessory.category = this.platform.api.hap.Categories.TV_SET_TOP_BOX;
|
|
53
|
+
(this.service =
|
|
54
|
+
accessory.getService(this.platform.Service.Television) ||
|
|
55
|
+
accessory.addService(this.platform.Service.Television)), `${accessory.displayName} Set Top Box`;
|
|
47
56
|
break;
|
|
48
57
|
default:
|
|
49
58
|
accessory.category = this.platform.api.hap.Categories.TELEVISION;
|
|
50
|
-
}
|
|
51
59
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
// get the Television service if it exists, otherwise create a new Television service
|
|
61
|
+
// you can create multiple services for each accessory
|
|
62
|
+
(this.service =
|
|
63
|
+
accessory.getService(this.platform.Service.Television) ||
|
|
64
|
+
accessory.addService(this.platform.Service.Television)), `${accessory.displayName} TV`;
|
|
65
|
+
}
|
|
57
66
|
|
|
58
67
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
59
68
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -86,7 +95,9 @@ export class TV {
|
|
|
86
95
|
// create a new Television Speaker service
|
|
87
96
|
(this.speakerService =
|
|
88
97
|
accessory.getService(this.platform.Service.TelevisionSpeaker) ||
|
|
89
|
-
accessory.addService(this.platform.Service.TelevisionSpeaker)), `${
|
|
98
|
+
accessory.addService(this.platform.Service.TelevisionSpeaker)), `${accessory.displayName} Speaker`;
|
|
99
|
+
|
|
100
|
+
this.speakerService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Speaker`);
|
|
90
101
|
|
|
91
102
|
this.speakerService
|
|
92
103
|
.setCharacteristic(this.platform.Characteristic.Active, this.platform.Characteristic.Active.ACTIVE)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
|
-
import { DeviceURL, irdevice } from '../settings';
|
|
4
|
+
import { devicesConfig, DeviceURL, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -16,21 +16,20 @@ export class VacuumCleaner {
|
|
|
16
16
|
constructor(
|
|
17
17
|
private readonly platform: SwitchBotPlatform,
|
|
18
18
|
private accessory: PlatformAccessory,
|
|
19
|
-
public device: irdevice,
|
|
19
|
+
public device: irdevice & devicesConfig,
|
|
20
20
|
) {
|
|
21
21
|
// set accessory information
|
|
22
22
|
accessory
|
|
23
23
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
24
24
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
25
25
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
26
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
|
|
26
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
27
27
|
|
|
28
28
|
// get the Television service if it exists, otherwise create a new Television service
|
|
29
29
|
// you can create multiple services for each accessory
|
|
30
30
|
(this.service =
|
|
31
31
|
accessory.getService(this.platform.Service.Switch) ||
|
|
32
|
-
accessory.addService(this.platform.Service.Switch)),
|
|
33
|
-
`${device.deviceName} ${device.remoteType}`;
|
|
32
|
+
accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Vacuum`;
|
|
34
33
|
|
|
35
34
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
36
35
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -38,10 +37,7 @@ export class VacuumCleaner {
|
|
|
38
37
|
|
|
39
38
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
40
39
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
41
|
-
this.service.setCharacteristic(
|
|
42
|
-
this.platform.Characteristic.Name,
|
|
43
|
-
`${device.deviceName} ${device.remoteType}`,
|
|
44
|
-
);
|
|
40
|
+
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
45
41
|
|
|
46
42
|
// handle on / off events using the On characteristic
|
|
47
43
|
this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
|