@switchbot/homebridge-switchbot 3.5.0-beta.56 → 3.5.0-beta.58
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/.vscode/settings.json +4 -1
- package/dist/device/blindtilt.d.ts +4 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +2 -2
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +3 -3
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +1 -1
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +3 -3
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +2 -2
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +3 -3
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +1 -1
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +4 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +8 -2
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +3 -3
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +1 -1
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +4 -4
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +4 -0
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +3 -3
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +1 -1
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +4 -4
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +1 -5
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +3 -3
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +1 -1
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +3 -3
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +1 -5
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +4 -4
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +2 -2
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +3 -3
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +1 -1
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +3 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +1 -5
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +3 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +1 -5
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +3 -3
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +27 -12
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +3 -3
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +1 -1
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +4 -4
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +3 -3
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +3 -3
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +1 -1
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +20 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +3 -3
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +9 -9
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +3 -3
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +3 -3
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +2 -2
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +6 -6
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +37 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +3 -3
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -14
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +67 -88
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +3 -3
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +3 -3
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +3 -3
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +3 -3
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +2 -2
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +3 -3
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +2 -2
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +7 -7
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +20 -23
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +24 -10
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -0
- package/dist/settings.js.map +1 -1
- package/eslint.config.js +89 -78
- package/package.json +3 -3
- package/src/device/blindtilt.ts +9 -7
- package/src/device/bot.ts +17 -15
- package/src/device/ceilinglight.ts +7 -5
- package/src/device/colorbulb.ts +6 -4
- package/src/device/contact.ts +22 -13
- package/src/device/curtain.ts +10 -8
- package/src/device/device.ts +5 -4
- package/src/device/fan.ts +7 -5
- package/src/device/hub.ts +10 -7
- package/src/device/humidifier.ts +9 -7
- package/src/device/iosensor.ts +11 -8
- package/src/device/lightstrip.ts +7 -5
- package/src/device/lock.ts +9 -7
- package/src/device/meter.ts +10 -7
- package/src/device/meterplus.ts +10 -7
- package/src/device/motion.ts +36 -16
- package/src/device/plug.ts +6 -4
- package/src/device/robotvacuumcleaner.ts +9 -7
- package/src/device/waterdetector.ts +7 -5
- package/src/homebridge-ui/public/index.html +20 -14
- package/src/index.ts +3 -2
- package/src/irdevice/airconditioner.ts +15 -13
- package/src/irdevice/airpurifier.ts +7 -5
- package/src/irdevice/camera.ts +7 -5
- package/src/irdevice/fan.ts +43 -30
- package/src/irdevice/irdevice.ts +4 -5
- package/src/irdevice/light.ts +83 -103
- package/src/irdevice/other.ts +15 -13
- package/src/irdevice/tv.ts +9 -7
- package/src/irdevice/vacuumcleaner.ts +7 -5
- package/src/irdevice/waterheater.ts +7 -5
- package/src/platform.ts +59 -66
- package/src/settings.ts +73 -58
package/src/irdevice/light.ts
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* light.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { request } from 'undici';
|
|
6
|
+
import { Devices } from '../settings.js';
|
|
6
7
|
import { irdeviceBase } from './irdevice.js';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
|
|
9
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
10
|
+
import type { irDevicesConfig, irdevice } from '../settings.js';
|
|
11
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Platform Accessory
|
|
@@ -15,20 +17,22 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
|
15
17
|
*/
|
|
16
18
|
export class Light extends irdeviceBase {
|
|
17
19
|
// Services
|
|
18
|
-
private LightBulb
|
|
20
|
+
private LightBulb?: {
|
|
19
21
|
Service: Service;
|
|
20
22
|
On: CharacteristicValue;
|
|
21
23
|
};
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
private ProgrammableSwitchOn?: {
|
|
26
|
+
Service: Service;
|
|
27
|
+
ProgrammableSwitchEvent: CharacteristicValue;
|
|
28
|
+
ProgrammableSwitchOutputState: CharacteristicValue;
|
|
29
|
+
};
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
ProgrammableSwitchOutputStateOff?: CharacteristicValue;
|
|
31
|
+
private ProgrammableSwitchOff?: {
|
|
32
|
+
Service: Service;
|
|
33
|
+
ProgrammableSwitchEvent: CharacteristicValue;
|
|
34
|
+
ProgrammableSwitchOutputState: CharacteristicValue;
|
|
35
|
+
};
|
|
32
36
|
|
|
33
37
|
constructor(
|
|
34
38
|
readonly platform: SwitchBotPlatform,
|
|
@@ -40,7 +44,7 @@ export class Light extends irdeviceBase {
|
|
|
40
44
|
if (!device.irlight?.stateless) {
|
|
41
45
|
// Initialize LightBulb property
|
|
42
46
|
this.LightBulb = {
|
|
43
|
-
Service: accessory.getService(this.hap.Service.Lightbulb)
|
|
47
|
+
Service: accessory.getService(this.hap.Service.Lightbulb)! as Service,
|
|
44
48
|
On: accessory.context.On || false,
|
|
45
49
|
};
|
|
46
50
|
// get the Light service if it exists, otherwise create a new Light service
|
|
@@ -57,47 +61,47 @@ export class Light extends irdeviceBase {
|
|
|
57
61
|
} else {
|
|
58
62
|
|
|
59
63
|
// create a new Stateful Programmable Switch On service
|
|
60
|
-
const
|
|
61
|
-
(this.
|
|
62
|
-
|| accessory.addService(this.hap.Service.StatefulProgrammableSwitch)),
|
|
64
|
+
const ProgrammableSwitchOn = `${accessory.displayName} ${device.remoteType} On`;
|
|
65
|
+
(this.ProgrammableSwitchOn!.Service = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
66
|
+
|| accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), ProgrammableSwitchOn;
|
|
63
67
|
|
|
64
68
|
|
|
65
|
-
this.
|
|
69
|
+
this.ProgrammableSwitchOn?.Service.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} On`);
|
|
66
70
|
|
|
67
|
-
this.
|
|
71
|
+
this.ProgrammableSwitchOn?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
|
|
68
72
|
validValueRanges: [0, 0],
|
|
69
73
|
minValue: 0,
|
|
70
74
|
maxValue: 0,
|
|
71
75
|
validValues: [0],
|
|
72
76
|
})
|
|
73
77
|
.onGet(() => {
|
|
74
|
-
return this.
|
|
78
|
+
return this.ProgrammableSwitchOn!.ProgrammableSwitchEvent;
|
|
75
79
|
});
|
|
76
80
|
|
|
77
|
-
this.
|
|
81
|
+
this.ProgrammableSwitchOn?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
78
82
|
.onSet(this.ProgrammableSwitchOutputStateSetOn.bind(this));
|
|
79
83
|
|
|
80
84
|
|
|
81
85
|
|
|
82
86
|
// create a new Stateful Programmable Switch Off service
|
|
83
|
-
const
|
|
84
|
-
(this.
|
|
85
|
-
|| accessory.addService(this.hap.Service.StatefulProgrammableSwitch)),
|
|
87
|
+
const ProgrammableSwitchOff = `${accessory.displayName} ${device.remoteType} Off`;
|
|
88
|
+
(this.ProgrammableSwitchOff!.Service = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
89
|
+
|| accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), ProgrammableSwitchOff;
|
|
86
90
|
|
|
87
91
|
|
|
88
|
-
this.
|
|
92
|
+
this.ProgrammableSwitchOff?.Service.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Off`);
|
|
89
93
|
|
|
90
|
-
this.
|
|
94
|
+
this.ProgrammableSwitchOff?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
|
|
91
95
|
validValueRanges: [0, 0],
|
|
92
96
|
minValue: 0,
|
|
93
97
|
maxValue: 0,
|
|
94
98
|
validValues: [0],
|
|
95
99
|
})
|
|
96
100
|
.onGet(() => {
|
|
97
|
-
return this.
|
|
101
|
+
return this.ProgrammableSwitchOff!.ProgrammableSwitchEvent;
|
|
98
102
|
});
|
|
99
103
|
|
|
100
|
-
this.
|
|
104
|
+
this.ProgrammableSwitchOff?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
101
105
|
.onSet(this.ProgrammableSwitchOutputStateSetOff.bind(this));
|
|
102
106
|
}
|
|
103
107
|
|
|
@@ -106,11 +110,13 @@ export class Light extends irdeviceBase {
|
|
|
106
110
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
107
111
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
108
112
|
|
|
109
|
-
this.On = value;
|
|
110
|
-
if (this.On) {
|
|
111
|
-
|
|
113
|
+
this.LightBulb!.On = value;
|
|
114
|
+
if (this.LightBulb?.On) {
|
|
115
|
+
const On = true;
|
|
116
|
+
await this.pushLightOnChanges(On);
|
|
112
117
|
} else {
|
|
113
|
-
|
|
118
|
+
const On = false;
|
|
119
|
+
await this.pushLightOffChanges(On);
|
|
114
120
|
}
|
|
115
121
|
/**
|
|
116
122
|
* pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
@@ -121,10 +127,10 @@ export class Light extends irdeviceBase {
|
|
|
121
127
|
async ProgrammableSwitchOutputStateSetOn(value: CharacteristicValue): Promise<void> {
|
|
122
128
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
123
129
|
|
|
124
|
-
this.
|
|
125
|
-
if (this.
|
|
126
|
-
|
|
127
|
-
await this.pushLightOnChanges();
|
|
130
|
+
this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState = value;
|
|
131
|
+
if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === 1) {
|
|
132
|
+
const On = true;
|
|
133
|
+
await this.pushLightOnChanges(On);
|
|
128
134
|
}
|
|
129
135
|
/**
|
|
130
136
|
* pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
@@ -135,10 +141,10 @@ export class Light extends irdeviceBase {
|
|
|
135
141
|
async ProgrammableSwitchOutputStateSetOff(value: CharacteristicValue): Promise<void> {
|
|
136
142
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
137
143
|
|
|
138
|
-
this.
|
|
139
|
-
if (this.
|
|
140
|
-
|
|
141
|
-
await this.pushLightOffChanges();
|
|
144
|
+
this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState = value;
|
|
145
|
+
if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === 1) {
|
|
146
|
+
const On = false;
|
|
147
|
+
await this.pushLightOffChanges(On);
|
|
142
148
|
}
|
|
143
149
|
/**
|
|
144
150
|
* pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
@@ -158,11 +164,9 @@ export class Light extends irdeviceBase {
|
|
|
158
164
|
* Light - "command" "channelAdd" "default" = next channel
|
|
159
165
|
* Light - "command" "channelSub" "default" = previous channel
|
|
160
166
|
*/
|
|
161
|
-
async pushLightOnChanges(): Promise<void> {
|
|
162
|
-
this.debugLog(
|
|
163
|
-
|
|
164
|
-
);
|
|
165
|
-
if (this.On && !this.disablePushOn) {
|
|
167
|
+
async pushLightOnChanges(On: boolean): Promise<void> {
|
|
168
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOnChanges On: ${On}, disablePushOn: ${this.disablePushOn}`);
|
|
169
|
+
if (On === true && this.disablePushOn === false) {
|
|
166
170
|
const commandType: string = await this.commandType();
|
|
167
171
|
const command: string = await this.commandOn();
|
|
168
172
|
const bodyChange = JSON.stringify({
|
|
@@ -170,15 +174,13 @@ export class Light extends irdeviceBase {
|
|
|
170
174
|
parameter: 'default',
|
|
171
175
|
commandType: commandType,
|
|
172
176
|
});
|
|
173
|
-
await this.pushChanges(bodyChange);
|
|
177
|
+
await this.pushChanges(bodyChange, On);
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
|
|
177
|
-
async pushLightOffChanges(): Promise<void> {
|
|
178
|
-
this.debugLog(
|
|
179
|
-
|
|
180
|
-
);
|
|
181
|
-
if (!this.On && !this.disablePushOff) {
|
|
181
|
+
async pushLightOffChanges(On: boolean): Promise<void> {
|
|
182
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges On: ${On}, disablePushOff: ${this.disablePushOff}`);
|
|
183
|
+
if (On === false && this.disablePushOff === false) {
|
|
182
184
|
const commandType: string = await this.commandType();
|
|
183
185
|
const command: string = await this.commandOff();
|
|
184
186
|
const bodyChange = JSON.stringify({
|
|
@@ -186,29 +188,11 @@ export class Light extends irdeviceBase {
|
|
|
186
188
|
parameter: 'default',
|
|
187
189
|
commandType: commandType,
|
|
188
190
|
});
|
|
189
|
-
await this.pushChanges(bodyChange);
|
|
191
|
+
await this.pushChanges(bodyChange, On);
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
|
|
193
|
-
|
|
194
|
-
const bodyChange = JSON.stringify({
|
|
195
|
-
command: 'brightnessUp',
|
|
196
|
-
parameter: 'default',
|
|
197
|
-
commandType: 'command',
|
|
198
|
-
});
|
|
199
|
-
await this.pushChanges(bodyChange);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
async pushLightBrightnessDownChanges(): Promise<void> {
|
|
203
|
-
const bodyChange = JSON.stringify({
|
|
204
|
-
command: 'brightnessDown',
|
|
205
|
-
parameter: 'default',
|
|
206
|
-
commandType: 'command',
|
|
207
|
-
});
|
|
208
|
-
await this.pushChanges(bodyChange);
|
|
209
|
-
}*/
|
|
210
|
-
|
|
211
|
-
async pushChanges(bodyChange: any): Promise<void> {
|
|
195
|
+
async pushChanges(bodyChange: any, On: boolean): Promise<void> {
|
|
212
196
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
213
197
|
if (this.device.connectionType === 'OpenAPI') {
|
|
214
198
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
@@ -227,7 +211,7 @@ export class Light extends irdeviceBase {
|
|
|
227
211
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
228
212
|
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
229
213
|
+ ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
|
|
230
|
-
this.accessory.context.On =
|
|
214
|
+
this.accessory.context.On = On;
|
|
231
215
|
this.updateHomeKitCharacteristics();
|
|
232
216
|
} else {
|
|
233
217
|
this.statusCode(statusCode);
|
|
@@ -235,63 +219,59 @@ export class Light extends irdeviceBase {
|
|
|
235
219
|
}
|
|
236
220
|
} catch (e: any) {
|
|
237
221
|
this.apiError(e);
|
|
238
|
-
this.errorLog(
|
|
239
|
-
|
|
240
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
241
|
-
);
|
|
222
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
|
|
223
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
242
224
|
}
|
|
243
225
|
} else {
|
|
244
|
-
this.warnLog(
|
|
245
|
-
|
|
246
|
-
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
247
|
-
);
|
|
226
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Connection Type: `
|
|
227
|
+
+ `${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
248
228
|
}
|
|
249
229
|
}
|
|
250
230
|
|
|
251
231
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
252
|
-
if (this.device.irlight?.stateless) {
|
|
232
|
+
if (!this.device.irlight?.stateless) {
|
|
253
233
|
// On
|
|
254
|
-
if (this.On === undefined) {
|
|
255
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
234
|
+
if (this.LightBulb?.On === undefined) {
|
|
235
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.LightBulb?.On}`);
|
|
256
236
|
} else {
|
|
257
|
-
this.accessory.context.On = this.On;
|
|
258
|
-
this.LightBulb.
|
|
259
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
237
|
+
this.accessory.context.On = this.LightBulb.On;
|
|
238
|
+
this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
|
|
239
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
|
|
260
240
|
}
|
|
261
241
|
} else {
|
|
262
242
|
// On Stateful Programmable Switch
|
|
263
|
-
if (this.
|
|
243
|
+
if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === undefined) {
|
|
264
244
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
265
|
-
+ ` ProgrammableSwitchOutputStateOn: ${this.
|
|
245
|
+
+ ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState}`);
|
|
266
246
|
} else {
|
|
267
|
-
this.accessory.context.ProgrammableSwitchOutputStateOn = this.
|
|
268
|
-
this.
|
|
269
|
-
this.
|
|
247
|
+
this.accessory.context.ProgrammableSwitchOutputStateOn = this.ProgrammableSwitchOn.ProgrammableSwitchOutputState;
|
|
248
|
+
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
|
|
249
|
+
this.ProgrammableSwitchOn.ProgrammableSwitchOutputState);
|
|
270
250
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
271
|
-
+ ` ProgrammableSwitchOutputStateOn: ${this.
|
|
251
|
+
+ ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn.ProgrammableSwitchOutputState}`);
|
|
272
252
|
}
|
|
273
253
|
// Off Stateful Programmable Switch
|
|
274
|
-
if (this.
|
|
254
|
+
if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === undefined) {
|
|
275
255
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
276
|
-
+ ` ProgrammableSwitchOutputStateOff: ${this.
|
|
256
|
+
+ ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
|
|
277
257
|
} else {
|
|
278
|
-
this.accessory.context.ProgrammableSwitchOutputStateOff = this.
|
|
279
|
-
this.
|
|
280
|
-
this.
|
|
258
|
+
this.accessory.context.ProgrammableSwitchOutputStateOff = this.ProgrammableSwitchOff.ProgrammableSwitchOutputState;
|
|
259
|
+
this.ProgrammableSwitchOff.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
|
|
260
|
+
this.ProgrammableSwitchOff.ProgrammableSwitchOutputState);
|
|
281
261
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
282
|
-
+ ` ProgrammableSwitchOutputStateOff: ${this.
|
|
262
|
+
+ ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
|
|
283
263
|
}
|
|
284
264
|
}
|
|
285
265
|
}
|
|
286
266
|
|
|
287
267
|
async apiError(e: any): Promise<void> {
|
|
288
|
-
if (this.device.irlight?.stateless) {
|
|
289
|
-
this.LightBulb.
|
|
268
|
+
if (!this.device.irlight?.stateless) {
|
|
269
|
+
this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
290
270
|
} else {
|
|
291
|
-
this.
|
|
292
|
-
this.
|
|
293
|
-
this.
|
|
294
|
-
this.
|
|
271
|
+
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
272
|
+
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
273
|
+
this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
274
|
+
this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
295
275
|
}
|
|
296
276
|
}
|
|
297
277
|
}
|
package/src/irdevice/other.ts
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* other.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { request } from 'undici';
|
|
6
|
+
import { Devices } from '../settings.js';
|
|
6
7
|
import { irdeviceBase } from './irdevice.js';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
|
|
9
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
10
|
+
import type { irDevicesConfig, irdevice } from '../settings.js';
|
|
11
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Platform Accessory
|
|
@@ -82,7 +84,7 @@ export class Others extends irdeviceBase {
|
|
|
82
84
|
if (this.otherDeviceType === 'switch') {
|
|
83
85
|
// Initialize Switch property
|
|
84
86
|
this.Switch = {
|
|
85
|
-
Service: accessory.getService(this.hap.Service.Switch)
|
|
87
|
+
Service: accessory.getService(this.hap.Service.Switch) as Service,
|
|
86
88
|
On: accessory.context.On || false,
|
|
87
89
|
};
|
|
88
90
|
this.removeFanService(accessory);
|
|
@@ -106,7 +108,7 @@ export class Others extends irdeviceBase {
|
|
|
106
108
|
} else if (this.otherDeviceType === 'garagedoor') {
|
|
107
109
|
// Initialize Garage Door property
|
|
108
110
|
this.GarageDoor = {
|
|
109
|
-
Service: accessory.getService(this.hap.Service.GarageDoorOpener)
|
|
111
|
+
Service: accessory.getService(this.hap.Service.GarageDoorOpener) as Service,
|
|
110
112
|
On: accessory.context.On || false,
|
|
111
113
|
};
|
|
112
114
|
this.removeFanService(accessory);
|
|
@@ -131,7 +133,7 @@ export class Others extends irdeviceBase {
|
|
|
131
133
|
} else if (this.otherDeviceType === 'door') {
|
|
132
134
|
// Initialize Door property
|
|
133
135
|
this.Door = {
|
|
134
|
-
Service: accessory.getService(this.hap.Service.Door)
|
|
136
|
+
Service: accessory.getService(this.hap.Service.Door) as Service,
|
|
135
137
|
On: accessory.context.On || false,
|
|
136
138
|
};
|
|
137
139
|
this.removeFanService(accessory);
|
|
@@ -164,7 +166,7 @@ export class Others extends irdeviceBase {
|
|
|
164
166
|
} else if (this.otherDeviceType === 'window') {
|
|
165
167
|
// Initialize Window property
|
|
166
168
|
this.Window = {
|
|
167
|
-
Service: accessory.getService(this.hap.Service.Window)
|
|
169
|
+
Service: accessory.getService(this.hap.Service.Window) as Service,
|
|
168
170
|
On: accessory.context.On || false,
|
|
169
171
|
};
|
|
170
172
|
this.removeFanService(accessory);
|
|
@@ -197,7 +199,7 @@ export class Others extends irdeviceBase {
|
|
|
197
199
|
} else if (this.otherDeviceType === 'windowcovering') {
|
|
198
200
|
// Initialize WindowCovering property
|
|
199
201
|
this.WindowCovering = {
|
|
200
|
-
Service: accessory.getService(this.hap.Service.WindowCovering)
|
|
202
|
+
Service: accessory.getService(this.hap.Service.WindowCovering) as Service,
|
|
201
203
|
On: accessory.context.On || false,
|
|
202
204
|
};
|
|
203
205
|
this.removeFanService(accessory);
|
|
@@ -230,7 +232,7 @@ export class Others extends irdeviceBase {
|
|
|
230
232
|
} else if (this.otherDeviceType === 'lock') {
|
|
231
233
|
// Initialize Lock property
|
|
232
234
|
this.Lock = {
|
|
233
|
-
Service: accessory.getService(this.hap.Service.LockMechanism)
|
|
235
|
+
Service: accessory.getService(this.hap.Service.LockMechanism) as Service,
|
|
234
236
|
On: accessory.context.On || false,
|
|
235
237
|
};
|
|
236
238
|
this.removeFanService(accessory);
|
|
@@ -254,7 +256,7 @@ export class Others extends irdeviceBase {
|
|
|
254
256
|
} else if (this.otherDeviceType === 'faucet') {
|
|
255
257
|
// Initialize Faucet property
|
|
256
258
|
this.Faucet = {
|
|
257
|
-
Service: accessory.getService(this.hap.Service.Faucet)
|
|
259
|
+
Service: accessory.getService(this.hap.Service.Faucet) as Service,
|
|
258
260
|
On: accessory.context.On || false,
|
|
259
261
|
};
|
|
260
262
|
this.removeFanService(accessory);
|
|
@@ -278,7 +280,7 @@ export class Others extends irdeviceBase {
|
|
|
278
280
|
} else if (this.otherDeviceType === 'fan') {
|
|
279
281
|
// Initialize Fan property
|
|
280
282
|
this.Fan = {
|
|
281
|
-
Service: accessory.getService(this.hap.Service.Fanv2)
|
|
283
|
+
Service: accessory.getService(this.hap.Service.Fanv2) as Service,
|
|
282
284
|
On: accessory.context.On || false,
|
|
283
285
|
};
|
|
284
286
|
this.removeLockService(accessory);
|
|
@@ -302,7 +304,7 @@ export class Others extends irdeviceBase {
|
|
|
302
304
|
} else if (this.otherDeviceType === 'stateful') {
|
|
303
305
|
// Initialize StatefulProgrammableSwitch property
|
|
304
306
|
this.StatefulProgrammableSwitch = {
|
|
305
|
-
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
307
|
+
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service,
|
|
306
308
|
On: accessory.context.On || false,
|
|
307
309
|
};
|
|
308
310
|
this.removeFanService(accessory);
|
|
@@ -328,7 +330,7 @@ export class Others extends irdeviceBase {
|
|
|
328
330
|
} else {
|
|
329
331
|
// Initialize Outlet property
|
|
330
332
|
this.Outlet = {
|
|
331
|
-
Service: accessory.getService(this.hap.Service.Outlet)
|
|
333
|
+
Service: accessory.getService(this.hap.Service.Outlet) as Service,
|
|
332
334
|
On: accessory.context.On || false,
|
|
333
335
|
};
|
|
334
336
|
this.removeFanService(accessory);
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* tv.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { request } from 'undici';
|
|
6
|
+
import { Devices } from '../settings.js';
|
|
6
7
|
import { irdeviceBase } from './irdevice.js';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
|
|
9
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
10
|
+
import type { irDevicesConfig, irdevice } from '../settings.js';
|
|
11
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Platform Accessory
|
|
@@ -41,7 +43,7 @@ export class TV extends irdeviceBase {
|
|
|
41
43
|
|
|
42
44
|
// Initialize Television property
|
|
43
45
|
this.Television = {
|
|
44
|
-
Service: accessory.getService(this.hap.Service.Television)
|
|
46
|
+
Service: accessory.getService(this.hap.Service.Television) as Service,
|
|
45
47
|
Active: accessory.context.Active || this.hap.Characteristic.Active.INACTIVE,
|
|
46
48
|
ActiveIdentifier: accessory.context.ActiveIdentifier || 1,
|
|
47
49
|
SleepDiscoveryMode: accessory.context.SleepDiscoveryMode || this.hap.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE,
|
|
@@ -50,7 +52,7 @@ export class TV extends irdeviceBase {
|
|
|
50
52
|
|
|
51
53
|
// Initialize TelevisionSpeaker property
|
|
52
54
|
this.TelevisionSpeaker = {
|
|
53
|
-
Service: accessory.getService(this.hap.Service.TelevisionSpeaker)
|
|
55
|
+
Service: accessory.getService(this.hap.Service.TelevisionSpeaker) as Service,
|
|
54
56
|
Active: accessory.context.Active || false,
|
|
55
57
|
VolumeControlType: accessory.context.VolumeControlType || this.hap.Characteristic.VolumeControlType.ABSOLUTE,
|
|
56
58
|
VolumeSelector: accessory.context.VolumeSelector || this.hap.Characteristic.VolumeSelector.INCREMENT,
|
|
@@ -418,7 +420,7 @@ export class TV extends irdeviceBase {
|
|
|
418
420
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Television.Active}`);
|
|
419
421
|
} else {
|
|
420
422
|
this.accessory.context.Active = this.Television.Active;
|
|
421
|
-
this.Television.Service
|
|
423
|
+
this.Television.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Television.Active);
|
|
422
424
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Television.Active}`);
|
|
423
425
|
}
|
|
424
426
|
// ActiveIdentifier
|
|
@@ -426,7 +428,7 @@ export class TV extends irdeviceBase {
|
|
|
426
428
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.Television.ActiveIdentifier}`);
|
|
427
429
|
} else {
|
|
428
430
|
this.accessory.context.ActiveIdentifier = this.Television.ActiveIdentifier;
|
|
429
|
-
this.Television.Service
|
|
431
|
+
this.Television.Service.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, this.Television.ActiveIdentifier);
|
|
430
432
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
431
433
|
+ ` ActiveIdentifier: ${this.Television.ActiveIdentifier}`);
|
|
432
434
|
}
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* vacuumcleaner.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { request } from 'undici';
|
|
6
|
+
import { Devices } from '../settings.js';
|
|
6
7
|
import { irdeviceBase } from './irdevice.js';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
|
|
9
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
10
|
+
import type { irDevicesConfig, irdevice } from '../settings.js';
|
|
11
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Platform Accessory
|
|
@@ -29,7 +31,7 @@ export class VacuumCleaner extends irdeviceBase {
|
|
|
29
31
|
|
|
30
32
|
// Initialize Switch property
|
|
31
33
|
this.Switch = {
|
|
32
|
-
Service: accessory.getService(this.hap.Service.Switch)
|
|
34
|
+
Service: accessory.getService(this.hap.Service.Switch) as Service,
|
|
33
35
|
On: accessory.context.On || false,
|
|
34
36
|
};
|
|
35
37
|
|
|
@@ -133,7 +135,7 @@ export class VacuumCleaner extends irdeviceBase {
|
|
|
133
135
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Switch.On}`);
|
|
134
136
|
} else {
|
|
135
137
|
this.accessory.context.On = this.Switch.On;
|
|
136
|
-
this.Switch.Service
|
|
138
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
|
|
137
139
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch.On}`);
|
|
138
140
|
}
|
|
139
141
|
}
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* waterheater.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { request } from 'undici';
|
|
6
|
+
import { Devices } from '../settings.js';
|
|
6
7
|
import { irdeviceBase } from './irdevice.js';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
|
|
9
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
10
|
+
import type { irDevicesConfig, irdevice } from '../settings.js';
|
|
11
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Platform Accessory
|
|
@@ -29,7 +31,7 @@ export class WaterHeater extends irdeviceBase {
|
|
|
29
31
|
|
|
30
32
|
// Initialize Valve property
|
|
31
33
|
this.Valve = {
|
|
32
|
-
Service: accessory.getService(this.hap.Service.Valve)
|
|
34
|
+
Service: accessory.getService(this.hap.Service.Valve) as Service,
|
|
33
35
|
Active: accessory.context.Active || this.hap.Characteristic.Active.INACTIVE,
|
|
34
36
|
};
|
|
35
37
|
|
|
@@ -138,7 +140,7 @@ export class WaterHeater extends irdeviceBase {
|
|
|
138
140
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Valve.Active}`);
|
|
139
141
|
} else {
|
|
140
142
|
this.accessory.context.Active = this.Valve.Active;
|
|
141
|
-
this.Valve.Service
|
|
143
|
+
this.Valve.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Valve.Active);
|
|
142
144
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Valve.Active}`);
|
|
143
145
|
}
|
|
144
146
|
}
|