@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/camera.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
|
10
10
|
*/
|
|
11
11
|
export class Camera {
|
|
12
12
|
// Services
|
|
13
|
-
|
|
13
|
+
switchService!: Service;
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
On!: CharacteristicValue;
|
|
@@ -38,7 +38,7 @@ export class Camera {
|
|
|
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} Camera`;
|
|
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,13 +47,13 @@ export class Camera {
|
|
|
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(`Camera: ${this.accessory.displayName} On: ${value}`);
|
|
58
58
|
this.On = value;
|
|
59
59
|
if (this.On) {
|
|
@@ -63,11 +63,11 @@ export class Camera {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
67
67
|
if (this.On === undefined) {
|
|
68
68
|
this.debugLog(`Camera: ${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(`Camera: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -82,7 +82,7 @@ export class Camera {
|
|
|
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 Camera {
|
|
|
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 Camera {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
async pushChanges(payload: payload): Promise<void> {
|
|
108
108
|
try {
|
|
109
109
|
this.infoLog(
|
|
110
110
|
`Camera: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -132,7 +132,7 @@ export class Camera {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
|
|
136
136
|
switch (push.data.statusCode) {
|
|
137
137
|
case 151:
|
|
138
138
|
this.errorLog(`Camera: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -163,12 +163,12 @@ export class Camera {
|
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
this.
|
|
166
|
+
async apiError(e: any): Promise<void> {
|
|
167
|
+
this.switchService.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
168
168
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
config(device: irdevice & irDevicesConfig) {
|
|
171
|
+
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
172
172
|
let config = {};
|
|
173
173
|
if (device.ircam) {
|
|
174
174
|
config = device.ircam;
|
|
@@ -181,7 +181,7 @@ export class Camera {
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
logs(device: irdevice & irDevicesConfig) {
|
|
184
|
+
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
185
185
|
if (this.platform.debugMode) {
|
|
186
186
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
187
187
|
this.debugLog(`Camera: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -200,25 +200,25 @@ export class Camera {
|
|
|
200
200
|
/**
|
|
201
201
|
* Logging for Device
|
|
202
202
|
*/
|
|
203
|
-
infoLog(...log: any[]) {
|
|
203
|
+
infoLog(...log: any[]): void {
|
|
204
204
|
if (this.enablingDeviceLogging()) {
|
|
205
205
|
this.platform.log.info(String(...log));
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
warnLog(...log: any[]) {
|
|
209
|
+
warnLog(...log: any[]): void {
|
|
210
210
|
if (this.enablingDeviceLogging()) {
|
|
211
211
|
this.platform.log.warn(String(...log));
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
errorLog(...log: any[]) {
|
|
215
|
+
errorLog(...log: any[]): void {
|
|
216
216
|
if (this.enablingDeviceLogging()) {
|
|
217
217
|
this.platform.log.error(String(...log));
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
debugLog(...log: any[]) {
|
|
221
|
+
debugLog(...log: any[]): void {
|
|
222
222
|
if (this.enablingDeviceLogging()) {
|
|
223
223
|
if (this.deviceLogging === 'debug') {
|
|
224
224
|
this.platform.log.info('[DEBUG]', String(...log));
|
package/src/irdevice/fan.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } f
|
|
|
10
10
|
*/
|
|
11
11
|
export class Fan {
|
|
12
12
|
// Services
|
|
13
|
-
|
|
13
|
+
fanService!: Service;
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
Active!: CharacteristicValue;
|
|
@@ -48,7 +48,7 @@ export class Fan {
|
|
|
48
48
|
|
|
49
49
|
// get the Television service if it exists, otherwise create a new Television service
|
|
50
50
|
// you can create multiple services for each accessory
|
|
51
|
-
(this.
|
|
51
|
+
(this.fanService = accessory.getService(this.platform.Service.Fanv2) || accessory.addService(this.platform.Service.Fanv2)),
|
|
52
52
|
`${accessory.displayName} Fan`;
|
|
53
53
|
|
|
54
54
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -57,10 +57,10 @@ export class Fan {
|
|
|
57
57
|
|
|
58
58
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
59
59
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
60
|
-
this.
|
|
60
|
+
this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
61
61
|
|
|
62
62
|
// handle on / off events using the Active characteristic
|
|
63
|
-
this.
|
|
63
|
+
this.fanService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
64
64
|
|
|
65
65
|
if (device.irfan?.rotation_speed) {
|
|
66
66
|
if (device.irfan?.set_minStep) {
|
|
@@ -79,7 +79,7 @@ export class Fan {
|
|
|
79
79
|
this.maxValue = 100;
|
|
80
80
|
}
|
|
81
81
|
// handle Roation Speed events using the RotationSpeed characteristic
|
|
82
|
-
this.
|
|
82
|
+
this.fanService
|
|
83
83
|
.getCharacteristic(this.platform.Characteristic.RotationSpeed)
|
|
84
84
|
.setProps({
|
|
85
85
|
minStep: this.minStep,
|
|
@@ -87,9 +87,9 @@ export class Fan {
|
|
|
87
87
|
maxValue: this.maxValue,
|
|
88
88
|
})
|
|
89
89
|
.onSet(this.RotationSpeedSet.bind(this));
|
|
90
|
-
} else if (this.
|
|
91
|
-
const characteristic = this.
|
|
92
|
-
this.
|
|
90
|
+
} else if (this.fanService.testCharacteristic(this.platform.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
|
|
91
|
+
const characteristic = this.fanService.getCharacteristic(this.platform.Characteristic.RotationSpeed);
|
|
92
|
+
this.fanService.removeCharacteristic(characteristic);
|
|
93
93
|
this.debugLog(`Fan: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`);
|
|
94
94
|
} else {
|
|
95
95
|
// eslint-disable-next-line max-len
|
|
@@ -101,10 +101,10 @@ export class Fan {
|
|
|
101
101
|
|
|
102
102
|
if (device.irfan?.swing_mode) {
|
|
103
103
|
// handle Osolcation events using the SwingMode characteristic
|
|
104
|
-
this.
|
|
105
|
-
} else if (this.
|
|
106
|
-
const characteristic = this.
|
|
107
|
-
this.
|
|
104
|
+
this.fanService.getCharacteristic(this.platform.Characteristic.SwingMode).onSet(this.SwingModeSet.bind(this));
|
|
105
|
+
} else if (this.fanService.testCharacteristic(this.platform.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
|
|
106
|
+
const characteristic = this.fanService.getCharacteristic(this.platform.Characteristic.SwingMode);
|
|
107
|
+
this.fanService.removeCharacteristic(characteristic);
|
|
108
108
|
this.debugLog(`Fan: ${this.accessory.displayName} Swing Mode Characteristic was removed.`);
|
|
109
109
|
} else {
|
|
110
110
|
// eslint-disable-next-line max-len
|
|
@@ -115,42 +115,42 @@ export class Fan {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
async SwingModeSet(value: CharacteristicValue): Promise<void> {
|
|
119
119
|
this.debugLog(`Fan: ${this.accessory.displayName} SwingMode: ${value}`);
|
|
120
120
|
if (value > this.SwingMode) {
|
|
121
121
|
this.SwingMode = 1;
|
|
122
|
-
this.pushFanOnChanges();
|
|
123
|
-
this.pushFanSwingChanges();
|
|
122
|
+
await this.pushFanOnChanges();
|
|
123
|
+
await this.pushFanSwingChanges();
|
|
124
124
|
} else {
|
|
125
125
|
this.SwingMode = 0;
|
|
126
|
-
this.pushFanOnChanges();
|
|
127
|
-
this.pushFanSwingChanges();
|
|
126
|
+
await this.pushFanOnChanges();
|
|
127
|
+
await this.pushFanSwingChanges();
|
|
128
128
|
}
|
|
129
129
|
this.SwingMode = value;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
133
133
|
if (this.Active === undefined) {
|
|
134
134
|
this.debugLog(`Fan: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
135
135
|
} else {
|
|
136
|
-
this.
|
|
136
|
+
this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
137
137
|
this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
138
138
|
}
|
|
139
139
|
if (this.SwingMode === undefined) {
|
|
140
140
|
this.debugLog(`Fan: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
|
|
141
141
|
} else {
|
|
142
|
-
this.
|
|
142
|
+
this.fanService?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
|
|
143
143
|
this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
|
|
144
144
|
}
|
|
145
145
|
if (this.RotationSpeed === undefined) {
|
|
146
146
|
this.debugLog(`Fan: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
|
|
147
147
|
} else {
|
|
148
|
-
this.
|
|
148
|
+
this.fanService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
|
|
149
149
|
this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
|
|
154
154
|
this.debugLog(`Fan: ${this.accessory.displayName} RotationSpeed: ${value}`);
|
|
155
155
|
if (value > this.RotationSpeed) {
|
|
156
156
|
this.RotationSpeed = 1;
|
|
@@ -163,7 +163,7 @@ export class Fan {
|
|
|
163
163
|
this.RotationSpeed = value;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
167
167
|
this.debugLog(`Fan: ${this.accessory.displayName} Active: ${value}`);
|
|
168
168
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
169
169
|
this.pushFanOffChanges();
|
|
@@ -184,7 +184,7 @@ export class Fan {
|
|
|
184
184
|
* Fan: "command" "middleSpeed" "default" = fan speed to medium
|
|
185
185
|
* Fan: "command" "highSpeed" "default" = fan speed to high
|
|
186
186
|
*/
|
|
187
|
-
async pushFanOnChanges() {
|
|
187
|
+
async pushFanOnChanges(): Promise<void> {
|
|
188
188
|
if (this.Active !== 1) {
|
|
189
189
|
const payload = {
|
|
190
190
|
commandType: 'command',
|
|
@@ -195,7 +195,7 @@ export class Fan {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
async pushFanOffChanges() {
|
|
198
|
+
async pushFanOffChanges(): Promise<void> {
|
|
199
199
|
const payload = {
|
|
200
200
|
commandType: 'command',
|
|
201
201
|
parameter: 'default',
|
|
@@ -204,7 +204,7 @@ export class Fan {
|
|
|
204
204
|
await this.pushTVChanges(payload);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
async pushFanSpeedUpChanges() {
|
|
207
|
+
async pushFanSpeedUpChanges(): Promise<void> {
|
|
208
208
|
const payload = {
|
|
209
209
|
commandType: 'command',
|
|
210
210
|
parameter: 'default',
|
|
@@ -213,7 +213,7 @@ export class Fan {
|
|
|
213
213
|
await this.pushTVChanges(payload);
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
async pushFanSpeedDownChanges() {
|
|
216
|
+
async pushFanSpeedDownChanges(): Promise<void> {
|
|
217
217
|
const payload = {
|
|
218
218
|
commandType: 'command',
|
|
219
219
|
parameter: 'default',
|
|
@@ -222,7 +222,7 @@ export class Fan {
|
|
|
222
222
|
await this.pushTVChanges(payload);
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
async pushFanSwingChanges() {
|
|
225
|
+
async pushFanSwingChanges(): Promise<void> {
|
|
226
226
|
const payload = {
|
|
227
227
|
commandType: 'command',
|
|
228
228
|
parameter: 'default',
|
|
@@ -231,7 +231,7 @@ export class Fan {
|
|
|
231
231
|
await this.pushTVChanges(payload);
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
|
|
234
|
+
async pushTVChanges(payload: payload): Promise<void> {
|
|
235
235
|
try {
|
|
236
236
|
this.infoLog(
|
|
237
237
|
`Fan: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -257,7 +257,7 @@ export class Fan {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
|
|
260
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
|
|
261
261
|
switch (push.data.statusCode) {
|
|
262
262
|
case 151:
|
|
263
263
|
this.errorLog(`Fan: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -288,14 +288,14 @@ export class Fan {
|
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
|
|
292
|
-
this.
|
|
293
|
-
this.
|
|
294
|
-
this.
|
|
291
|
+
async apiError(e: any): Promise<void> {
|
|
292
|
+
this.fanService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
293
|
+
this.fanService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
|
|
294
|
+
this.fanService.updateCharacteristic(this.platform.Characteristic.SwingMode, e);
|
|
295
295
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
-
config(device: irdevice & irDevicesConfig) {
|
|
298
|
+
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
299
299
|
let config = {};
|
|
300
300
|
if (device.irfan) {
|
|
301
301
|
config = device.irfan;
|
|
@@ -308,7 +308,7 @@ export class Fan {
|
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
-
logs(device: irdevice & irDevicesConfig) {
|
|
311
|
+
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
312
312
|
if (this.platform.debugMode) {
|
|
313
313
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
314
314
|
this.debugLog(`Fan: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -327,25 +327,25 @@ export class Fan {
|
|
|
327
327
|
/**
|
|
328
328
|
* Logging for Device
|
|
329
329
|
*/
|
|
330
|
-
infoLog(...log: any[]) {
|
|
330
|
+
infoLog(...log: any[]): void {
|
|
331
331
|
if (this.enablingDeviceLogging()) {
|
|
332
332
|
this.platform.log.info(String(...log));
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
-
warnLog(...log: any[]) {
|
|
336
|
+
warnLog(...log: any[]): void {
|
|
337
337
|
if (this.enablingDeviceLogging()) {
|
|
338
338
|
this.platform.log.warn(String(...log));
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
-
errorLog(...log: any[]) {
|
|
342
|
+
errorLog(...log: any[]): void {
|
|
343
343
|
if (this.enablingDeviceLogging()) {
|
|
344
344
|
this.platform.log.error(String(...log));
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
debugLog(...log: any[]) {
|
|
348
|
+
debugLog(...log: any[]): void {
|
|
349
349
|
if (this.enablingDeviceLogging()) {
|
|
350
350
|
if (this.deviceLogging === 'debug') {
|
|
351
351
|
this.platform.log.info('[DEBUG]', String(...log));
|
package/src/irdevice/light.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
|
10
10
|
*/
|
|
11
11
|
export class Light {
|
|
12
12
|
// Services
|
|
13
|
-
|
|
13
|
+
lightBulbService!: Service;
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
On!: CharacteristicValue;
|
|
@@ -38,7 +38,7 @@ export class Light {
|
|
|
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.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
|
|
42
42
|
`${accessory.displayName} Light Bulb`;
|
|
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,10 +47,10 @@ export class Light {
|
|
|
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.lightBulbService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
51
51
|
|
|
52
52
|
// handle on / off events using the On characteristic
|
|
53
|
-
this.
|
|
53
|
+
this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
54
54
|
|
|
55
55
|
// handle Brightness events using the Brightness characteristic
|
|
56
56
|
/* this.service
|
|
@@ -68,21 +68,21 @@ export class Light {
|
|
|
68
68
|
});*/
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
72
72
|
this.debugLog(`Light: ${this.accessory.displayName} On: ${value}`);
|
|
73
73
|
this.On = value;
|
|
74
74
|
if (this.On) {
|
|
75
|
-
this.pushLightOnChanges();
|
|
75
|
+
await this.pushLightOnChanges();
|
|
76
76
|
} else {
|
|
77
|
-
this.pushLightOffChanges();
|
|
77
|
+
await this.pushLightOffChanges();
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
82
82
|
if (this.On === undefined) {
|
|
83
83
|
this.debugLog(`Light: ${this.accessory.displayName} On: ${this.On}`);
|
|
84
84
|
} else {
|
|
85
|
-
this.
|
|
85
|
+
this.lightBulbService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
86
86
|
this.debugLog(`Light: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -97,7 +97,7 @@ export class Light {
|
|
|
97
97
|
* Light: "command" "channelAdd" "default" = next channel
|
|
98
98
|
* Light: "command" "channelSub" "default" = previous channel
|
|
99
99
|
*/
|
|
100
|
-
async pushLightOnChanges() {
|
|
100
|
+
async pushLightOnChanges(): Promise<void> {
|
|
101
101
|
if (this.On) {
|
|
102
102
|
const payload = {
|
|
103
103
|
commandType: 'command',
|
|
@@ -108,7 +108,7 @@ export class Light {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
async pushLightOffChanges() {
|
|
111
|
+
async pushLightOffChanges(): Promise<void> {
|
|
112
112
|
if (!this.On) {
|
|
113
113
|
const payload = {
|
|
114
114
|
commandType: 'command',
|
|
@@ -119,7 +119,7 @@ export class Light {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
async pushLightBrightnessUpChanges() {
|
|
122
|
+
async pushLightBrightnessUpChanges(): Promise<void> {
|
|
123
123
|
const payload = {
|
|
124
124
|
commandType: 'command',
|
|
125
125
|
parameter: 'default',
|
|
@@ -128,7 +128,7 @@ export class Light {
|
|
|
128
128
|
await this.pushChanges(payload);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
async pushLightBrightnessDownChanges() {
|
|
131
|
+
async pushLightBrightnessDownChanges(): Promise<void> {
|
|
132
132
|
const payload = {
|
|
133
133
|
commandType: 'command',
|
|
134
134
|
parameter: 'default',
|
|
@@ -137,7 +137,7 @@ export class Light {
|
|
|
137
137
|
await this.pushChanges(payload);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
async pushChanges(payload: payload): Promise<void> {
|
|
141
141
|
try {
|
|
142
142
|
this.infoLog(
|
|
143
143
|
`Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -165,7 +165,7 @@ export class Light {
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void>{
|
|
169
169
|
switch (push.data.statusCode) {
|
|
170
170
|
case 151:
|
|
171
171
|
this.errorLog(`Light: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -196,12 +196,12 @@ export class Light {
|
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
|
|
200
|
-
this.
|
|
199
|
+
async apiError(e: any): Promise<void> {
|
|
200
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
201
201
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
config(device: irdevice & irDevicesConfig) {
|
|
204
|
+
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
205
205
|
let config = {};
|
|
206
206
|
if (device.irlight) {
|
|
207
207
|
config = device.irlight;
|
|
@@ -214,7 +214,7 @@ export class Light {
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
logs(device: irdevice & irDevicesConfig) {
|
|
217
|
+
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
218
218
|
if (this.platform.debugMode) {
|
|
219
219
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
220
220
|
this.debugLog(`Light: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -233,25 +233,25 @@ export class Light {
|
|
|
233
233
|
/**
|
|
234
234
|
* Logging for Device
|
|
235
235
|
*/
|
|
236
|
-
infoLog(...log: any[]) {
|
|
236
|
+
infoLog(...log: any[]): void {
|
|
237
237
|
if (this.enablingDeviceLogging()) {
|
|
238
238
|
this.platform.log.info(String(...log));
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
warnLog(...log: any[]) {
|
|
242
|
+
warnLog(...log: any[]): void {
|
|
243
243
|
if (this.enablingDeviceLogging()) {
|
|
244
244
|
this.platform.log.warn(String(...log));
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
errorLog(...log: any[]) {
|
|
248
|
+
errorLog(...log: any[]): void {
|
|
249
249
|
if (this.enablingDeviceLogging()) {
|
|
250
250
|
this.platform.log.error(String(...log));
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
debugLog(...log: any[]) {
|
|
254
|
+
debugLog(...log: any[]): void {
|
|
255
255
|
if (this.enablingDeviceLogging()) {
|
|
256
256
|
if (this.deviceLogging === 'debug') {
|
|
257
257
|
this.platform.log.info('[DEBUG]', String(...log));
|