@switchbot/homebridge-switchbot 2.8.0-beta.0 → 2.8.0-beta.10
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/.prettierrc +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +10 -0
- package/config.schema.json +8 -0
- package/dist/device/blindtilt.d.ts +1 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +58 -65
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +52 -55
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -0
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +68 -68
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +76 -75
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +67 -59
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +81 -94
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +197 -30
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +58 -62
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -0
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +28 -26
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -0
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +68 -67
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +51 -47
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +75 -74
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +4 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +74 -74
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +66 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +39 -39
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -0
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +74 -53
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +64 -66
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +32 -34
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +20 -23
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -2
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +30 -32
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +26 -29
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +22 -23
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -2
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +47 -50
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +20 -23
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +22 -23
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +46 -44
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/device/blindtilt.ts +114 -78
- package/src/device/bot.ts +102 -63
- package/src/device/ceilinglight.ts +113 -73
- package/src/device/colorbulb.ts +144 -87
- package/src/device/contact.ts +98 -63
- package/src/device/curtain.ts +160 -134
- package/src/device/hub.ts +228 -39
- package/src/device/humidifier.ts +136 -85
- package/src/device/iosensor.ts +52 -32
- package/src/device/lightstrip.ts +118 -72
- package/src/device/lock.ts +85 -50
- package/src/device/meter.ts +104 -80
- package/src/device/meterplus.ts +103 -80
- package/src/device/motion.ts +95 -59
- package/src/device/plug.ts +70 -44
- package/src/device/robotvacuumcleaner.ts +107 -56
- package/src/irdevice/airconditioner.ts +116 -86
- package/src/irdevice/airpurifier.ts +60 -39
- package/src/irdevice/camera.ts +40 -28
- package/src/irdevice/fan.ts +52 -38
- package/src/irdevice/light.ts +48 -34
- package/src/irdevice/other.ts +44 -28
- package/src/irdevice/tv.ts +70 -56
- package/src/irdevice/vacuumcleaner.ts +40 -28
- package/src/irdevice/waterheater.ts +48 -32
- package/src/platform.ts +87 -56
- package/src/settings.ts +41 -40
- package/src/utils.ts +1 -1
package/src/irdevice/camera.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
1
2
|
import { request } from 'undici';
|
|
2
3
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import { irDevicesConfig, irdevice
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
4
|
+
import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -20,13 +20,17 @@ export class Camera {
|
|
|
20
20
|
disablePushOff?: boolean;
|
|
21
21
|
deviceLogging!: string;
|
|
22
22
|
|
|
23
|
-
constructor(
|
|
23
|
+
constructor(
|
|
24
|
+
private readonly platform: SwitchBotPlatform,
|
|
25
|
+
private accessory: PlatformAccessory,
|
|
26
|
+
public device: irdevice & irDevicesConfig,
|
|
27
|
+
) {
|
|
24
28
|
// default placeholders
|
|
25
29
|
this.logs(device);
|
|
26
|
-
this.config(device);
|
|
27
30
|
this.context();
|
|
28
31
|
this.disablePushOnChanges({ device });
|
|
29
32
|
this.disablePushOffChanges({ device });
|
|
33
|
+
this.config(device);
|
|
30
34
|
|
|
31
35
|
// set accessory information
|
|
32
36
|
accessory
|
|
@@ -80,30 +84,30 @@ export class Camera {
|
|
|
80
84
|
* Camera - "command" "channelSub" "default" = previous channel
|
|
81
85
|
*/
|
|
82
86
|
async pushOnChanges(): Promise<void> {
|
|
83
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${this.On},`
|
|
84
|
-
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
87
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${this.On},` + ` disablePushOn: ${this.disablePushOn}`);
|
|
85
88
|
if (this.On && !this.disablePushOn) {
|
|
86
89
|
const commandType: string = await this.commandType();
|
|
87
90
|
const command: string = await this.commandOn();
|
|
88
91
|
const bodyChange = JSON.stringify({
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
command: command,
|
|
93
|
+
parameter: 'default',
|
|
94
|
+
commandType: commandType,
|
|
92
95
|
});
|
|
93
96
|
await this.pushChanges(bodyChange);
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
async pushOffChanges(): Promise<void> {
|
|
98
|
-
this.debugLog(
|
|
99
|
-
+ ` disablePushOff: ${this.disablePushOff}
|
|
101
|
+
this.debugLog(
|
|
102
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges On: ${this.On},` + ` disablePushOff: ${this.disablePushOff}`,
|
|
103
|
+
);
|
|
100
104
|
if (!this.On && !this.disablePushOff) {
|
|
101
105
|
const commandType: string = await this.commandType();
|
|
102
106
|
const command: string = await this.commandOff();
|
|
103
107
|
const bodyChange = JSON.stringify({
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
command: command,
|
|
109
|
+
parameter: 'default',
|
|
110
|
+
commandType: commandType,
|
|
107
111
|
});
|
|
108
112
|
await this.pushChanges(bodyChange);
|
|
109
113
|
}
|
|
@@ -112,7 +116,7 @@ export class Camera {
|
|
|
112
116
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
113
117
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
114
118
|
if (this.device.connectionType === 'OpenAPI') {
|
|
115
|
-
this.
|
|
119
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
116
120
|
try {
|
|
117
121
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
118
122
|
body: bodyChange,
|
|
@@ -126,13 +130,16 @@ export class Camera {
|
|
|
126
130
|
this.updateHomeKitCharacteristics();
|
|
127
131
|
} catch (e: any) {
|
|
128
132
|
this.apiError(e);
|
|
129
|
-
this.errorLog(
|
|
130
|
-
|
|
133
|
+
this.errorLog(
|
|
134
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
|
|
135
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
131
136
|
);
|
|
132
137
|
}
|
|
133
138
|
} else {
|
|
134
|
-
this.warnLog(
|
|
135
|
-
|
|
139
|
+
this.warnLog(
|
|
140
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` +
|
|
141
|
+
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
142
|
+
);
|
|
136
143
|
}
|
|
137
144
|
}
|
|
138
145
|
|
|
@@ -146,7 +153,7 @@ export class Camera {
|
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
155
|
|
|
149
|
-
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig
|
|
156
|
+
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
150
157
|
if (device.disablePushOn === undefined) {
|
|
151
158
|
this.disablePushOn = false;
|
|
152
159
|
} else {
|
|
@@ -154,7 +161,7 @@ export class Camera {
|
|
|
154
161
|
}
|
|
155
162
|
}
|
|
156
163
|
|
|
157
|
-
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig
|
|
164
|
+
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
158
165
|
if (device.disablePushOff === undefined) {
|
|
159
166
|
this.disablePushOff = false;
|
|
160
167
|
} else {
|
|
@@ -207,8 +214,10 @@ export class Camera {
|
|
|
207
214
|
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
208
215
|
break;
|
|
209
216
|
case 171:
|
|
210
|
-
this.errorLog(
|
|
211
|
-
|
|
217
|
+
this.errorLog(
|
|
218
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
219
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
220
|
+
);
|
|
212
221
|
break;
|
|
213
222
|
case 190:
|
|
214
223
|
this.errorLog(
|
|
@@ -223,8 +232,10 @@ export class Camera {
|
|
|
223
232
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
224
233
|
break;
|
|
225
234
|
default:
|
|
226
|
-
this.infoLog(
|
|
227
|
-
|
|
235
|
+
this.infoLog(
|
|
236
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
237
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
238
|
+
);
|
|
228
239
|
}
|
|
229
240
|
}
|
|
230
241
|
|
|
@@ -234,8 +245,9 @@ export class Camera {
|
|
|
234
245
|
|
|
235
246
|
FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
|
|
236
247
|
let FirmwareRevision: string;
|
|
237
|
-
this.debugLog(
|
|
238
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
248
|
+
this.debugLog(
|
|
249
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
250
|
+
);
|
|
239
251
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
240
252
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
241
253
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -286,7 +298,7 @@ export class Camera {
|
|
|
286
298
|
config['disablePushOff'] = device.disablePushOff;
|
|
287
299
|
}
|
|
288
300
|
if (Object.entries(config).length !== 0) {
|
|
289
|
-
this.
|
|
301
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
290
302
|
}
|
|
291
303
|
}
|
|
292
304
|
|
package/src/irdevice/fan.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
1
2
|
import { request } from 'undici';
|
|
2
3
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import {
|
|
4
|
-
import { irdevice, irDevicesConfig, Devices } from '../settings';
|
|
4
|
+
import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -30,13 +30,17 @@ export class Fan {
|
|
|
30
30
|
disablePushOff?: boolean;
|
|
31
31
|
deviceLogging!: string;
|
|
32
32
|
|
|
33
|
-
constructor(
|
|
33
|
+
constructor(
|
|
34
|
+
private readonly platform: SwitchBotPlatform,
|
|
35
|
+
private accessory: PlatformAccessory,
|
|
36
|
+
public device: irdevice & irDevicesConfig,
|
|
37
|
+
) {
|
|
34
38
|
// default placeholders
|
|
35
39
|
this.logs(device);
|
|
36
|
-
this.config(device);
|
|
37
40
|
this.context();
|
|
38
41
|
this.disablePushOnChanges({ device });
|
|
39
42
|
this.disablePushOffChanges({ device });
|
|
43
|
+
this.config(device);
|
|
40
44
|
|
|
41
45
|
// set accessory information
|
|
42
46
|
accessory
|
|
@@ -170,30 +174,33 @@ export class Fan {
|
|
|
170
174
|
* Fan - "command" "highSpeed" "default" = fan speed to high
|
|
171
175
|
*/
|
|
172
176
|
async pushFanOnChanges(): Promise<void> {
|
|
173
|
-
this.debugLog(
|
|
174
|
-
+ ` disablePushOn: ${this.disablePushOn}
|
|
177
|
+
this.debugLog(
|
|
178
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushFanOnChanges Active: ${this.Active},` + ` disablePushOn: ${this.disablePushOn}`,
|
|
179
|
+
);
|
|
175
180
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
176
181
|
const commandType: string = await this.commandType();
|
|
177
182
|
const command: string = await this.commandOn();
|
|
178
183
|
const bodyChange = JSON.stringify({
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
184
|
+
command: command,
|
|
185
|
+
parameter: 'default',
|
|
186
|
+
commandType: commandType,
|
|
182
187
|
});
|
|
183
188
|
await this.pushChanges(bodyChange);
|
|
184
189
|
}
|
|
185
190
|
}
|
|
186
191
|
|
|
187
192
|
async pushFanOffChanges(): Promise<void> {
|
|
188
|
-
this.debugLog(
|
|
189
|
-
|
|
193
|
+
this.debugLog(
|
|
194
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges Active: ${this.Active},` +
|
|
195
|
+
` disablePushOff: ${this.disablePushOff}`,
|
|
196
|
+
);
|
|
190
197
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
191
198
|
const commandType: string = await this.commandType();
|
|
192
199
|
const command: string = await this.commandOff();
|
|
193
200
|
const bodyChange = JSON.stringify({
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
201
|
+
command: command,
|
|
202
|
+
parameter: 'default',
|
|
203
|
+
commandType: commandType,
|
|
197
204
|
});
|
|
198
205
|
await this.pushChanges(bodyChange);
|
|
199
206
|
}
|
|
@@ -201,27 +208,27 @@ export class Fan {
|
|
|
201
208
|
|
|
202
209
|
async pushFanSpeedUpChanges(): Promise<void> {
|
|
203
210
|
const bodyChange = JSON.stringify({
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
211
|
+
command: 'highSpeed',
|
|
212
|
+
parameter: 'default',
|
|
213
|
+
commandType: 'command',
|
|
207
214
|
});
|
|
208
215
|
await this.pushChanges(bodyChange);
|
|
209
216
|
}
|
|
210
217
|
|
|
211
218
|
async pushFanSpeedDownChanges(): Promise<void> {
|
|
212
219
|
const bodyChange = JSON.stringify({
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
220
|
+
command: 'lowSpeed',
|
|
221
|
+
parameter: 'default',
|
|
222
|
+
commandType: 'command',
|
|
216
223
|
});
|
|
217
224
|
await this.pushChanges(bodyChange);
|
|
218
225
|
}
|
|
219
226
|
|
|
220
227
|
async pushFanSwingChanges(): Promise<void> {
|
|
221
228
|
const bodyChange = JSON.stringify({
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
229
|
+
command: 'swing',
|
|
230
|
+
parameter: 'default',
|
|
231
|
+
commandType: 'command',
|
|
225
232
|
});
|
|
226
233
|
await this.pushChanges(bodyChange);
|
|
227
234
|
}
|
|
@@ -229,7 +236,7 @@ export class Fan {
|
|
|
229
236
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
230
237
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
231
238
|
if (this.device.connectionType === 'OpenAPI') {
|
|
232
|
-
this.
|
|
239
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
233
240
|
try {
|
|
234
241
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
235
242
|
body: bodyChange,
|
|
@@ -243,13 +250,16 @@ export class Fan {
|
|
|
243
250
|
this.updateHomeKitCharacteristics();
|
|
244
251
|
} catch (e: any) {
|
|
245
252
|
this.apiError(e);
|
|
246
|
-
this.errorLog(
|
|
247
|
-
|
|
253
|
+
this.errorLog(
|
|
254
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
|
|
255
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
248
256
|
);
|
|
249
257
|
}
|
|
250
258
|
} else {
|
|
251
|
-
this.warnLog(
|
|
252
|
-
|
|
259
|
+
this.warnLog(
|
|
260
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` +
|
|
261
|
+
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
262
|
+
);
|
|
253
263
|
}
|
|
254
264
|
}
|
|
255
265
|
|
|
@@ -277,7 +287,7 @@ export class Fan {
|
|
|
277
287
|
}
|
|
278
288
|
}
|
|
279
289
|
|
|
280
|
-
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig
|
|
290
|
+
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
281
291
|
if (device.disablePushOn === undefined) {
|
|
282
292
|
this.disablePushOn = false;
|
|
283
293
|
} else {
|
|
@@ -285,7 +295,7 @@ export class Fan {
|
|
|
285
295
|
}
|
|
286
296
|
}
|
|
287
297
|
|
|
288
|
-
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig
|
|
298
|
+
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
289
299
|
if (device.disablePushOff === undefined) {
|
|
290
300
|
this.disablePushOff = false;
|
|
291
301
|
} else {
|
|
@@ -338,8 +348,10 @@ export class Fan {
|
|
|
338
348
|
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
339
349
|
break;
|
|
340
350
|
case 171:
|
|
341
|
-
this.errorLog(
|
|
342
|
-
|
|
351
|
+
this.errorLog(
|
|
352
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
353
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
354
|
+
);
|
|
343
355
|
break;
|
|
344
356
|
case 190:
|
|
345
357
|
this.errorLog(
|
|
@@ -354,8 +366,10 @@ export class Fan {
|
|
|
354
366
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
355
367
|
break;
|
|
356
368
|
default:
|
|
357
|
-
this.infoLog(
|
|
358
|
-
|
|
369
|
+
this.infoLog(
|
|
370
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
371
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
372
|
+
);
|
|
359
373
|
}
|
|
360
374
|
}
|
|
361
375
|
|
|
@@ -367,8 +381,9 @@ export class Fan {
|
|
|
367
381
|
|
|
368
382
|
FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
|
|
369
383
|
let FirmwareRevision: string;
|
|
370
|
-
this.debugLog(
|
|
371
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
384
|
+
this.debugLog(
|
|
385
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
386
|
+
);
|
|
372
387
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
373
388
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
374
389
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -389,7 +404,6 @@ export class Fan {
|
|
|
389
404
|
}
|
|
390
405
|
}
|
|
391
406
|
|
|
392
|
-
|
|
393
407
|
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
394
408
|
let config = {};
|
|
395
409
|
if (device.irfan) {
|
|
@@ -420,7 +434,7 @@ export class Fan {
|
|
|
420
434
|
config['disablePushOff'] = device.disablePushOff;
|
|
421
435
|
}
|
|
422
436
|
if (Object.entries(config).length !== 0) {
|
|
423
|
-
this.
|
|
437
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
424
438
|
}
|
|
425
439
|
}
|
|
426
440
|
|
package/src/irdevice/light.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
1
2
|
import { request } from 'undici';
|
|
2
3
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import { irDevicesConfig, irdevice
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
4
|
+
import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -20,13 +20,17 @@ export class Light {
|
|
|
20
20
|
disablePushOff?: boolean;
|
|
21
21
|
deviceLogging!: string;
|
|
22
22
|
|
|
23
|
-
constructor(
|
|
23
|
+
constructor(
|
|
24
|
+
private readonly platform: SwitchBotPlatform,
|
|
25
|
+
private accessory: PlatformAccessory,
|
|
26
|
+
public device: irdevice & irDevicesConfig,
|
|
27
|
+
) {
|
|
24
28
|
// default placeholders
|
|
25
29
|
this.logs(device);
|
|
26
|
-
this.config(device);
|
|
27
30
|
this.context();
|
|
28
31
|
this.disablePushOnChanges({ device });
|
|
29
32
|
this.disablePushOffChanges({ device });
|
|
33
|
+
this.config(device);
|
|
30
34
|
|
|
31
35
|
// set accessory information
|
|
32
36
|
accessory
|
|
@@ -84,30 +88,32 @@ export class Light {
|
|
|
84
88
|
* Light - "command" "channelSub" "default" = previous channel
|
|
85
89
|
*/
|
|
86
90
|
async pushLightOnChanges(): Promise<void> {
|
|
87
|
-
this.debugLog(
|
|
88
|
-
+ ` disablePushOn: ${this.disablePushOn}
|
|
91
|
+
this.debugLog(
|
|
92
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushLightOnChanges On: ${this.On},` + ` disablePushOn: ${this.disablePushOn}`,
|
|
93
|
+
);
|
|
89
94
|
if (this.On && !this.disablePushOn) {
|
|
90
95
|
const commandType: string = await this.commandType();
|
|
91
96
|
const command: string = await this.commandOn();
|
|
92
97
|
const bodyChange = JSON.stringify({
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
command: command,
|
|
99
|
+
parameter: 'default',
|
|
100
|
+
commandType: commandType,
|
|
96
101
|
});
|
|
97
102
|
await this.pushChanges(bodyChange);
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
105
|
|
|
101
106
|
async pushLightOffChanges(): Promise<void> {
|
|
102
|
-
this.debugLog(
|
|
103
|
-
+ ` disablePushOff: ${this.disablePushOff}
|
|
107
|
+
this.debugLog(
|
|
108
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges On: ${this.On},` + ` disablePushOff: ${this.disablePushOff}`,
|
|
109
|
+
);
|
|
104
110
|
if (!this.On && !this.disablePushOff) {
|
|
105
111
|
const commandType: string = await this.commandType();
|
|
106
112
|
const command: string = await this.commandOff();
|
|
107
113
|
const bodyChange = JSON.stringify({
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
command: command,
|
|
115
|
+
parameter: 'default',
|
|
116
|
+
commandType: commandType,
|
|
111
117
|
});
|
|
112
118
|
await this.pushChanges(bodyChange);
|
|
113
119
|
}
|
|
@@ -115,18 +121,18 @@ export class Light {
|
|
|
115
121
|
|
|
116
122
|
async pushLightBrightnessUpChanges(): Promise<void> {
|
|
117
123
|
const bodyChange = JSON.stringify({
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
command: 'brightnessUp',
|
|
125
|
+
parameter: 'default',
|
|
126
|
+
commandType: 'command',
|
|
121
127
|
});
|
|
122
128
|
await this.pushChanges(bodyChange);
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
async pushLightBrightnessDownChanges(): Promise<void> {
|
|
126
132
|
const bodyChange = JSON.stringify({
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
133
|
+
command: 'brightnessDown',
|
|
134
|
+
parameter: 'default',
|
|
135
|
+
commandType: 'command',
|
|
130
136
|
});
|
|
131
137
|
await this.pushChanges(bodyChange);
|
|
132
138
|
}
|
|
@@ -134,7 +140,7 @@ export class Light {
|
|
|
134
140
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
135
141
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
136
142
|
if (this.device.connectionType === 'OpenAPI') {
|
|
137
|
-
this.
|
|
143
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
138
144
|
try {
|
|
139
145
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
140
146
|
body: bodyChange,
|
|
@@ -149,13 +155,16 @@ export class Light {
|
|
|
149
155
|
this.updateHomeKitCharacteristics();
|
|
150
156
|
} catch (e: any) {
|
|
151
157
|
this.apiError(e);
|
|
152
|
-
this.errorLog(
|
|
153
|
-
|
|
158
|
+
this.errorLog(
|
|
159
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
|
|
160
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
154
161
|
);
|
|
155
162
|
}
|
|
156
163
|
} else {
|
|
157
|
-
this.warnLog(
|
|
158
|
-
|
|
164
|
+
this.warnLog(
|
|
165
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` +
|
|
166
|
+
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
167
|
+
);
|
|
159
168
|
}
|
|
160
169
|
}
|
|
161
170
|
|
|
@@ -169,7 +178,7 @@ export class Light {
|
|
|
169
178
|
}
|
|
170
179
|
}
|
|
171
180
|
|
|
172
|
-
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig
|
|
181
|
+
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
173
182
|
if (device.disablePushOn === undefined) {
|
|
174
183
|
this.disablePushOn = false;
|
|
175
184
|
} else {
|
|
@@ -177,7 +186,7 @@ export class Light {
|
|
|
177
186
|
}
|
|
178
187
|
}
|
|
179
188
|
|
|
180
|
-
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig
|
|
189
|
+
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
181
190
|
if (device.disablePushOff === undefined) {
|
|
182
191
|
this.disablePushOff = false;
|
|
183
192
|
} else {
|
|
@@ -230,8 +239,10 @@ export class Light {
|
|
|
230
239
|
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
231
240
|
break;
|
|
232
241
|
case 171:
|
|
233
|
-
this.errorLog(
|
|
234
|
-
|
|
242
|
+
this.errorLog(
|
|
243
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
244
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
245
|
+
);
|
|
235
246
|
break;
|
|
236
247
|
case 190:
|
|
237
248
|
this.errorLog(
|
|
@@ -246,8 +257,10 @@ export class Light {
|
|
|
246
257
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
247
258
|
break;
|
|
248
259
|
default:
|
|
249
|
-
this.infoLog(
|
|
250
|
-
|
|
260
|
+
this.infoLog(
|
|
261
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
262
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
263
|
+
);
|
|
251
264
|
}
|
|
252
265
|
}
|
|
253
266
|
|
|
@@ -257,8 +270,9 @@ export class Light {
|
|
|
257
270
|
|
|
258
271
|
FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
|
|
259
272
|
let FirmwareRevision: string;
|
|
260
|
-
this.debugLog(
|
|
261
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
273
|
+
this.debugLog(
|
|
274
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
275
|
+
);
|
|
262
276
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
263
277
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
264
278
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -309,7 +323,7 @@ export class Light {
|
|
|
309
323
|
config['disablePushOff'] = device.disablePushOff;
|
|
310
324
|
}
|
|
311
325
|
if (Object.entries(config).length !== 0) {
|
|
312
|
-
this.
|
|
326
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
313
327
|
}
|
|
314
328
|
}
|
|
315
329
|
|