@switchbot/homebridge-switchbot 1.11.0 → 1.11.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/CHANGELOG.md +10 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +15 -7
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +22 -22
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +44 -44
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +12 -9
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +20 -20
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +10 -7
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +11 -11
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +12 -9
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +29 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +10 -7
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +13 -13
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +12 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +17 -17
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +13 -10
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +25 -25
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +10 -7
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +13 -13
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +10 -7
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +16 -16
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/device/colorbulb.ts +15 -9
- package/src/irdevice/airconditioner.ts +54 -54
- package/src/irdevice/airpurifier.ts +30 -30
- package/src/irdevice/camera.ts +19 -19
- package/src/irdevice/fan.ts +40 -40
- package/src/irdevice/light.ts +23 -23
- package/src/irdevice/other.ts +25 -25
- package/src/irdevice/tv.ts +42 -42
- package/src/irdevice/vacuumcleaner.ts +21 -21
- package/src/irdevice/waterheater.ts +24 -24
- package/src/platform.ts +4 -4
package/src/irdevice/other.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
|
10
10
|
*/
|
|
11
11
|
export class Others {
|
|
12
12
|
// Services
|
|
13
|
-
|
|
13
|
+
fanService?: Service;
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
Active!: CharacteristicValue;
|
|
@@ -46,38 +46,38 @@ export class Others {
|
|
|
46
46
|
if (this.otherDeviceType === undefined) {
|
|
47
47
|
this.errorLog(`Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${device.other?.deviceType}`);
|
|
48
48
|
}
|
|
49
|
-
this.
|
|
50
|
-
accessory.removeService(this.
|
|
51
|
-
} else if (!this.
|
|
49
|
+
this.fanService = this.accessory.getService(this.platform.Service.Fanv2);
|
|
50
|
+
accessory.removeService(this.fanService!);
|
|
51
|
+
} else if (!this.fanService && this.otherDeviceType === 'Fan') {
|
|
52
52
|
this.debugLog(`Other: ${accessory.displayName} Add Fanv2 Service`);
|
|
53
|
-
(this.
|
|
53
|
+
(this.fanService = this.accessory.getService(this.platform.Service.Fanv2) || this.accessory.addService(this.platform.Service.Fanv2)),
|
|
54
54
|
`${accessory.displayName} Fan`;
|
|
55
55
|
|
|
56
|
-
this.
|
|
56
|
+
this.fanService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Fan`);
|
|
57
57
|
|
|
58
|
-
this.
|
|
58
|
+
this.fanService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
59
59
|
} else {
|
|
60
60
|
this.debugLog(`Other: ${accessory.displayName} Fanv2 Service Not Added, deviceType: ${device.other?.deviceType}`);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
65
65
|
this.debugLog(`Other: ${this.accessory.displayName} On: ${value}`);
|
|
66
66
|
if (this.Active) {
|
|
67
|
-
this.pushOnChanges();
|
|
67
|
+
await this.pushOnChanges();
|
|
68
68
|
} else {
|
|
69
|
-
this.pushOffChanges();
|
|
69
|
+
await this.pushOffChanges();
|
|
70
70
|
}
|
|
71
71
|
this.Active = value;
|
|
72
72
|
this.ActiveCached = this.Active;
|
|
73
73
|
this.accessory.context.Active = this.ActiveCached;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
77
77
|
if (this.Active === undefined) {
|
|
78
78
|
this.debugLog(`Other: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
79
79
|
} else {
|
|
80
|
-
this.
|
|
80
|
+
this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
81
81
|
this.debugLog(`Other: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -92,7 +92,7 @@ export class Others {
|
|
|
92
92
|
* Light: "command" "channelAdd" "default" = next channel
|
|
93
93
|
* Light: "command" "channelSub" "default" = previous channel
|
|
94
94
|
*/
|
|
95
|
-
async pushOnChanges() {
|
|
95
|
+
async pushOnChanges(): Promise<void> {
|
|
96
96
|
if (this.platform.config.options) {
|
|
97
97
|
if (this.device.other) {
|
|
98
98
|
if (this.device.other.commandOn) {
|
|
@@ -115,7 +115,7 @@ export class Others {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
async pushOffChanges() {
|
|
118
|
+
async pushOffChanges(): Promise<void> {
|
|
119
119
|
if (this.platform.config.options) {
|
|
120
120
|
if (this.device.other) {
|
|
121
121
|
if (this.device.other.commandOff) {
|
|
@@ -138,7 +138,7 @@ export class Others {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
async pushChanges(payload: payload): Promise<void> {
|
|
142
142
|
try {
|
|
143
143
|
this.infoLog(
|
|
144
144
|
`Other: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -164,7 +164,7 @@ export class Others {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void>{
|
|
168
168
|
switch (push.data.statusCode) {
|
|
169
169
|
case 151:
|
|
170
170
|
this.errorLog(`Other: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -195,12 +195,12 @@ export class Others {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
this.
|
|
198
|
+
async apiError(e: any): Promise<void> {
|
|
199
|
+
this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
200
200
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
deviceType(device: irdevice & irDevicesConfig) {
|
|
203
|
+
async deviceType(device: irdevice & irDevicesConfig): Promise<void> {
|
|
204
204
|
if (device.other?.deviceType) {
|
|
205
205
|
this.otherDeviceType = this.accessory.context.deviceType = device.other.deviceType;
|
|
206
206
|
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
@@ -211,7 +211,7 @@ export class Others {
|
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
config(device: irdevice & irDevicesConfig) {
|
|
214
|
+
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
215
215
|
let config = {};
|
|
216
216
|
if (device.other) {
|
|
217
217
|
config = device.other;
|
|
@@ -224,7 +224,7 @@ export class Others {
|
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
logs(device: irdevice & irDevicesConfig) {
|
|
227
|
+
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
228
228
|
if (this.platform.debugMode) {
|
|
229
229
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
230
230
|
this.debugLog(`Other: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -243,25 +243,25 @@ export class Others {
|
|
|
243
243
|
/**
|
|
244
244
|
* Logging for Device
|
|
245
245
|
*/
|
|
246
|
-
infoLog(...log: any[]) {
|
|
246
|
+
infoLog(...log: any[]): void {
|
|
247
247
|
if (this.enablingDeviceLogging()) {
|
|
248
248
|
this.platform.log.info(String(...log));
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
warnLog(...log: any[]) {
|
|
252
|
+
warnLog(...log: any[]): void {
|
|
253
253
|
if (this.enablingDeviceLogging()) {
|
|
254
254
|
this.platform.log.warn(String(...log));
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
errorLog(...log: any[]) {
|
|
258
|
+
errorLog(...log: any[]): void {
|
|
259
259
|
if (this.enablingDeviceLogging()) {
|
|
260
260
|
this.platform.log.error(String(...log));
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
debugLog(...log: any[]) {
|
|
264
|
+
debugLog(...log: any[]): void {
|
|
265
265
|
if (this.enablingDeviceLogging()) {
|
|
266
266
|
if (this.deviceLogging === 'debug') {
|
|
267
267
|
this.platform.log.info('[DEBUG]', String(...log));
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } f
|
|
|
10
10
|
*/
|
|
11
11
|
export class TV {
|
|
12
12
|
// Services
|
|
13
|
-
|
|
13
|
+
tvService!: Service;
|
|
14
14
|
speakerService: Service;
|
|
15
15
|
|
|
16
16
|
// Characteristic Values
|
|
@@ -47,13 +47,13 @@ export class TV {
|
|
|
47
47
|
case 'Speaker':
|
|
48
48
|
case 'DIY Speaker':
|
|
49
49
|
accessory.category = this.platform.api.hap.Categories.SPEAKER;
|
|
50
|
-
(this.
|
|
50
|
+
(this.tvService = accessory.getService(this.platform.Service.Television) || accessory.addService(this.platform.Service.Television)),
|
|
51
51
|
`${accessory.displayName} Speaker`;
|
|
52
52
|
break;
|
|
53
53
|
case 'IPTV':
|
|
54
54
|
case 'DIY IPTV':
|
|
55
55
|
accessory.category = this.platform.api.hap.Categories.TV_STREAMING_STICK;
|
|
56
|
-
(this.
|
|
56
|
+
(this.tvService = accessory.getService(this.platform.Service.Television) || accessory.addService(this.platform.Service.Television)),
|
|
57
57
|
`${accessory.displayName} Streaming Stick`;
|
|
58
58
|
break;
|
|
59
59
|
case 'DVD':
|
|
@@ -61,7 +61,7 @@ export class TV {
|
|
|
61
61
|
case 'Set Top Box':
|
|
62
62
|
case 'DIY Set Top Box':
|
|
63
63
|
accessory.category = this.platform.api.hap.Categories.TV_SET_TOP_BOX;
|
|
64
|
-
(this.
|
|
64
|
+
(this.tvService = accessory.getService(this.platform.Service.Television) || accessory.addService(this.platform.Service.Television)),
|
|
65
65
|
`${accessory.displayName} Set Top Box`;
|
|
66
66
|
break;
|
|
67
67
|
default:
|
|
@@ -69,7 +69,7 @@ export class TV {
|
|
|
69
69
|
|
|
70
70
|
// get the Television service if it exists, otherwise create a new Television service
|
|
71
71
|
// you can create multiple services for each accessory
|
|
72
|
-
(this.
|
|
72
|
+
(this.tvService = accessory.getService(this.platform.Service.Television) || accessory.addService(this.platform.Service.Television)),
|
|
73
73
|
`${accessory.displayName} TV`;
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -79,24 +79,24 @@ export class TV {
|
|
|
79
79
|
|
|
80
80
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
81
81
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
82
|
-
this.
|
|
82
|
+
this.tvService.getCharacteristic(this.platform.Characteristic.ConfiguredName);
|
|
83
83
|
|
|
84
84
|
// set sleep discovery characteristic
|
|
85
|
-
this.
|
|
85
|
+
this.tvService.setCharacteristic(
|
|
86
86
|
this.platform.Characteristic.SleepDiscoveryMode,
|
|
87
87
|
this.platform.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE,
|
|
88
88
|
);
|
|
89
89
|
|
|
90
90
|
// handle on / off events using the Active characteristic
|
|
91
|
-
this.
|
|
91
|
+
this.tvService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
92
92
|
|
|
93
|
-
this.
|
|
93
|
+
this.tvService.setCharacteristic(this.platform.Characteristic.ActiveIdentifier, 1);
|
|
94
94
|
|
|
95
95
|
// handle input source changes
|
|
96
|
-
this.
|
|
96
|
+
this.tvService.getCharacteristic(this.platform.Characteristic.ActiveIdentifier).onSet(this.ActiveIdentifierSet.bind(this));
|
|
97
97
|
|
|
98
98
|
// handle remote control input
|
|
99
|
-
this.
|
|
99
|
+
this.tvService.getCharacteristic(this.platform.Characteristic.RemoteKey).onSet(this.RemoteKeySet.bind(this));
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* Create a speaker service to allow volume control
|
|
@@ -116,7 +116,7 @@ export class TV {
|
|
|
116
116
|
this.speakerService.getCharacteristic(this.platform.Characteristic.VolumeSelector).onSet(this.VolumeSelectorSet.bind(this));
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
async VolumeSelectorSet(value: CharacteristicValue): Promise<void> {
|
|
120
120
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} VolumeSelector: ${value}`);
|
|
121
121
|
if (value === this.platform.Characteristic.VolumeSelector.INCREMENT) {
|
|
122
122
|
this.pushVolumeUpChanges();
|
|
@@ -125,7 +125,7 @@ export class TV {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
async RemoteKeySet(value: CharacteristicValue): Promise<void> {
|
|
129
129
|
switch (value) {
|
|
130
130
|
case this.platform.Characteristic.RemoteKey.REWIND: {
|
|
131
131
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: REWIND`);
|
|
@@ -189,18 +189,18 @@ export class TV {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
|
|
192
|
+
async ActiveIdentifierSet(value: CharacteristicValue): Promise<void> {
|
|
193
193
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${value}`);
|
|
194
194
|
this.ActiveIdentifier = value;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
|
|
197
|
+
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
198
198
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
|
|
199
199
|
if (!this.device.irtv?.disable_power) {
|
|
200
200
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
201
|
-
this.pushTvOffChanges();
|
|
201
|
+
await this.pushTvOffChanges();
|
|
202
202
|
} else {
|
|
203
|
-
this.pushTvOnChanges();
|
|
203
|
+
await this.pushTvOnChanges();
|
|
204
204
|
}
|
|
205
205
|
this.Active = value;
|
|
206
206
|
this.ActiveCached = this.Active;
|
|
@@ -208,17 +208,17 @@ export class TV {
|
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
|
|
211
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
212
212
|
if (this.Active === undefined) {
|
|
213
213
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
214
214
|
} else {
|
|
215
|
-
this.
|
|
215
|
+
this.tvService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
216
216
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
217
217
|
}
|
|
218
218
|
if (this.ActiveIdentifier === undefined) {
|
|
219
219
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`);
|
|
220
220
|
} else {
|
|
221
|
-
this.
|
|
221
|
+
this.tvService?.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
|
|
222
222
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
@@ -233,7 +233,7 @@ export class TV {
|
|
|
233
233
|
* TV: "command" "channelAdd" "default" = next channel
|
|
234
234
|
* TV: "command" "channelSub" "default" = previous channel
|
|
235
235
|
*/
|
|
236
|
-
async pushTvOnChanges() {
|
|
236
|
+
async pushTvOnChanges(): Promise<void> {
|
|
237
237
|
if (this.Active !== 1) {
|
|
238
238
|
const payload = {
|
|
239
239
|
commandType: 'command',
|
|
@@ -244,7 +244,7 @@ export class TV {
|
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
async pushTvOffChanges() {
|
|
247
|
+
async pushTvOffChanges(): Promise<void> {
|
|
248
248
|
const payload = {
|
|
249
249
|
commandType: 'command',
|
|
250
250
|
parameter: 'default',
|
|
@@ -253,7 +253,7 @@ export class TV {
|
|
|
253
253
|
await this.pushTVChanges(payload);
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
async pushOkChanges() {
|
|
256
|
+
async pushOkChanges(): Promise<void> {
|
|
257
257
|
const payload = {
|
|
258
258
|
commandType: 'command',
|
|
259
259
|
parameter: 'default',
|
|
@@ -262,7 +262,7 @@ export class TV {
|
|
|
262
262
|
await this.pushTVChanges(payload);
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
async pushBackChanges() {
|
|
265
|
+
async pushBackChanges(): Promise<void> {
|
|
266
266
|
const payload = {
|
|
267
267
|
commandType: 'command',
|
|
268
268
|
parameter: 'default',
|
|
@@ -271,7 +271,7 @@ export class TV {
|
|
|
271
271
|
await this.pushTVChanges(payload);
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
async pushMenuChanges() {
|
|
274
|
+
async pushMenuChanges(): Promise<void> {
|
|
275
275
|
const payload = {
|
|
276
276
|
commandType: 'command',
|
|
277
277
|
parameter: 'default',
|
|
@@ -280,7 +280,7 @@ export class TV {
|
|
|
280
280
|
await this.pushTVChanges(payload);
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
-
async pushUpChanges() {
|
|
283
|
+
async pushUpChanges(): Promise<void> {
|
|
284
284
|
const payload = {
|
|
285
285
|
commandType: 'command',
|
|
286
286
|
parameter: 'default',
|
|
@@ -289,7 +289,7 @@ export class TV {
|
|
|
289
289
|
await this.pushTVChanges(payload);
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
async pushDownChanges() {
|
|
292
|
+
async pushDownChanges(): Promise<void> {
|
|
293
293
|
const payload = {
|
|
294
294
|
commandType: 'command',
|
|
295
295
|
parameter: 'default',
|
|
@@ -298,7 +298,7 @@ export class TV {
|
|
|
298
298
|
await this.pushTVChanges(payload);
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
async pushRightChanges() {
|
|
301
|
+
async pushRightChanges(): Promise<void> {
|
|
302
302
|
const payload = {
|
|
303
303
|
commandType: 'command',
|
|
304
304
|
parameter: 'default',
|
|
@@ -307,7 +307,7 @@ export class TV {
|
|
|
307
307
|
await this.pushTVChanges(payload);
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
async pushLeftChanges() {
|
|
310
|
+
async pushLeftChanges(): Promise<void> {
|
|
311
311
|
const payload = {
|
|
312
312
|
commandType: 'command',
|
|
313
313
|
parameter: 'default',
|
|
@@ -316,7 +316,7 @@ export class TV {
|
|
|
316
316
|
await this.pushTVChanges(payload);
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
-
async pushVolumeUpChanges() {
|
|
319
|
+
async pushVolumeUpChanges(): Promise<void> {
|
|
320
320
|
const payload = {
|
|
321
321
|
commandType: 'command',
|
|
322
322
|
parameter: 'default',
|
|
@@ -325,7 +325,7 @@ export class TV {
|
|
|
325
325
|
await this.pushTVChanges(payload);
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
-
async pushVolumeDownChanges() {
|
|
328
|
+
async pushVolumeDownChanges(): Promise<void> {
|
|
329
329
|
const payload = {
|
|
330
330
|
commandType: 'command',
|
|
331
331
|
parameter: 'default',
|
|
@@ -334,7 +334,7 @@ export class TV {
|
|
|
334
334
|
await this.pushTVChanges(payload);
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
|
|
337
|
+
async pushTVChanges(payload: payload): Promise<void> {
|
|
338
338
|
try {
|
|
339
339
|
this.infoLog(
|
|
340
340
|
`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -363,7 +363,7 @@ export class TV {
|
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
-
|
|
366
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void>{
|
|
367
367
|
switch (push.data.statusCode) {
|
|
368
368
|
case 151:
|
|
369
369
|
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -395,13 +395,13 @@ export class TV {
|
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
-
|
|
399
|
-
this.
|
|
400
|
-
this.
|
|
398
|
+
async apiError(e: any): Promise<void> {
|
|
399
|
+
this.tvService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
400
|
+
this.tvService.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, e);
|
|
401
401
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
-
config(device: irdevice & irDevicesConfig) {
|
|
404
|
+
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
405
405
|
let config = {};
|
|
406
406
|
if (device.irtv) {
|
|
407
407
|
config = device.irtv;
|
|
@@ -414,7 +414,7 @@ export class TV {
|
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
416
|
|
|
417
|
-
logs(device: irdevice & irDevicesConfig) {
|
|
417
|
+
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
418
418
|
if (this.platform.debugMode) {
|
|
419
419
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
420
420
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -433,25 +433,25 @@ export class TV {
|
|
|
433
433
|
/**
|
|
434
434
|
* Logging for Device
|
|
435
435
|
*/
|
|
436
|
-
infoLog(...log: any[]) {
|
|
436
|
+
infoLog(...log: any[]): void {
|
|
437
437
|
if (this.enablingDeviceLogging()) {
|
|
438
438
|
this.platform.log.info(String(...log));
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
441
|
|
|
442
|
-
warnLog(...log: any[]) {
|
|
442
|
+
warnLog(...log: any[]): void {
|
|
443
443
|
if (this.enablingDeviceLogging()) {
|
|
444
444
|
this.platform.log.warn(String(...log));
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
447
|
|
|
448
|
-
errorLog(...log: any[]) {
|
|
448
|
+
errorLog(...log: any[]): void {
|
|
449
449
|
if (this.enablingDeviceLogging()) {
|
|
450
450
|
this.platform.log.error(String(...log));
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
453
|
|
|
454
|
-
debugLog(...log: any[]) {
|
|
454
|
+
debugLog(...log: any[]): void {
|
|
455
455
|
if (this.enablingDeviceLogging()) {
|
|
456
456
|
if (this.deviceLogging === 'debug') {
|
|
457
457
|
this.platform.log.info('[DEBUG]', String(...log));
|
|
@@ -10,7 +10,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
|
10
10
|
*/
|
|
11
11
|
export class VacuumCleaner {
|
|
12
12
|
// Services
|
|
13
|
-
|
|
13
|
+
switchService!: Service;
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
On!: CharacteristicValue;
|
|
@@ -38,7 +38,7 @@ export class VacuumCleaner {
|
|
|
38
38
|
|
|
39
39
|
// get the Television service if it exists, otherwise create a new Television service
|
|
40
40
|
// you can create multiple services for each accessory
|
|
41
|
-
(this.
|
|
41
|
+
(this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
|
|
42
42
|
`${accessory.displayName} Vacuum`;
|
|
43
43
|
|
|
44
44
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -47,27 +47,27 @@ export class VacuumCleaner {
|
|
|
47
47
|
|
|
48
48
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
49
49
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
50
|
-
this.
|
|
50
|
+
this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
51
51
|
|
|
52
52
|
// handle on / off events using the On characteristic
|
|
53
|
-
this.
|
|
53
|
+
this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
57
57
|
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} On: ${value}`);
|
|
58
58
|
this.On = value;
|
|
59
59
|
if (this.On) {
|
|
60
|
-
this.pushOnChanges();
|
|
60
|
+
await this.pushOnChanges();
|
|
61
61
|
} else {
|
|
62
|
-
this.pushOffChanges();
|
|
62
|
+
await this.pushOffChanges();
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
67
67
|
if (this.On === undefined) {
|
|
68
68
|
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} On: ${this.On}`);
|
|
69
69
|
} else {
|
|
70
|
-
this.
|
|
70
|
+
this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
71
71
|
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -82,7 +82,7 @@ export class VacuumCleaner {
|
|
|
82
82
|
* Light: "command" "channelAdd" "default" = next channel
|
|
83
83
|
* Light: "command" "channelSub" "default" = previous channel
|
|
84
84
|
*/
|
|
85
|
-
async pushOnChanges() {
|
|
85
|
+
async pushOnChanges(): Promise<void> {
|
|
86
86
|
if (this.On) {
|
|
87
87
|
const payload = {
|
|
88
88
|
commandType: 'command',
|
|
@@ -93,7 +93,7 @@ export class VacuumCleaner {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
async pushOffChanges() {
|
|
96
|
+
async pushOffChanges(): Promise<void> {
|
|
97
97
|
if (!this.On) {
|
|
98
98
|
const payload = {
|
|
99
99
|
commandType: 'command',
|
|
@@ -104,7 +104,7 @@ export class VacuumCleaner {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
async pushChanges(payload: payload): Promise<void> {
|
|
108
108
|
try {
|
|
109
109
|
this.infoLog(
|
|
110
110
|
`Vacuum Cleaner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -133,7 +133,7 @@ export class VacuumCleaner {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void>{
|
|
137
137
|
switch (push.data.statusCode) {
|
|
138
138
|
case 151:
|
|
139
139
|
this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -164,12 +164,12 @@ export class VacuumCleaner {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
this.
|
|
167
|
+
async apiError(e: any): Promise<void> {
|
|
168
|
+
this.switchService.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
169
169
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
config(device: irdevice & irDevicesConfig) {
|
|
172
|
+
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
173
173
|
let config = {};
|
|
174
174
|
if (device.irvc) {
|
|
175
175
|
config = device.irvc;
|
|
@@ -182,7 +182,7 @@ export class VacuumCleaner {
|
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
logs(device: irdevice & irDevicesConfig) {
|
|
185
|
+
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
186
186
|
if (this.platform.debugMode) {
|
|
187
187
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
188
188
|
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -201,25 +201,25 @@ export class VacuumCleaner {
|
|
|
201
201
|
/**
|
|
202
202
|
* Logging for Device
|
|
203
203
|
*/
|
|
204
|
-
infoLog(...log: any[]) {
|
|
204
|
+
infoLog(...log: any[]): void {
|
|
205
205
|
if (this.enablingDeviceLogging()) {
|
|
206
206
|
this.platform.log.info(String(...log));
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
warnLog(...log: any[]) {
|
|
210
|
+
warnLog(...log: any[]): void {
|
|
211
211
|
if (this.enablingDeviceLogging()) {
|
|
212
212
|
this.platform.log.warn(String(...log));
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
errorLog(...log: any[]) {
|
|
216
|
+
errorLog(...log: any[]): void {
|
|
217
217
|
if (this.enablingDeviceLogging()) {
|
|
218
218
|
this.platform.log.error(String(...log));
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
debugLog(...log: any[]) {
|
|
222
|
+
debugLog(...log: any[]): void {
|
|
223
223
|
if (this.enablingDeviceLogging()) {
|
|
224
224
|
if (this.deviceLogging === 'debug') {
|
|
225
225
|
this.platform.log.info('[DEBUG]', String(...log));
|