@switchbot/homebridge-switchbot 3.5.0-beta.9 → 3.5.1-beta.0
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/CHANGELOG.md +4 -1
- package/config.schema.json +164 -22
- package/dist/device/blindtilt.d.ts +21 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +457 -866
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +27 -72
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +851 -913
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +15 -69
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +316 -742
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +15 -76
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +380 -833
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -66
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +267 -602
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +18 -89
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +469 -897
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +76 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +846 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +63 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +645 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +19 -58
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +304 -640
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +11 -66
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +300 -710
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +12 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +225 -643
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +12 -70
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +371 -742
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +17 -63
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +309 -642
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +15 -64
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +223 -638
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +15 -65
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +216 -644
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +12 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +209 -588
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +10 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +141 -532
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +13 -63
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +252 -609
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +11 -63
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +179 -521
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +22 -16
- package/dist/homebridge-ui/server.js +1 -1
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +10 -50
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +337 -482
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -39
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +108 -333
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +7 -36
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +47 -299
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -43
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +95 -364
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +46 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +393 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +12 -45
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +121 -376
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +19 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +441 -584
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +94 -353
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +48 -299
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +50 -305
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +22 -8
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +342 -191
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +66 -18
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +95 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +657 -1
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +96 -0
- package/package.json +20 -16
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +488 -937
- package/src/device/bot.ts +907 -1016
- package/src/device/ceilinglight.ts +330 -798
- package/src/device/colorbulb.ts +394 -904
- package/src/device/contact.ts +298 -637
- package/src/device/curtain.ts +496 -954
- package/src/device/device.ts +872 -0
- package/src/device/fan.ts +692 -0
- package/src/device/hub.ts +338 -671
- package/src/device/humidifier.ts +330 -777
- package/src/device/iosensor.ts +258 -671
- package/src/device/lightstrip.ts +394 -809
- package/src/device/lock.ts +345 -700
- package/src/device/meter.ts +256 -666
- package/src/device/meterplus.ts +248 -672
- package/src/device/motion.ts +234 -622
- package/src/device/plug.ts +152 -572
- package/src/device/robotvacuumcleaner.ts +273 -653
- package/src/device/waterdetector.ts +198 -549
- package/src/homebridge-ui/public/index.html +22 -16
- package/src/homebridge-ui/server.ts +1 -1
- package/src/index.ts +4 -3
- package/src/irdevice/airconditioner.ts +368 -540
- package/src/irdevice/airpurifier.ts +134 -369
- package/src/irdevice/camera.ts +60 -324
- package/src/irdevice/fan.ts +111 -392
- package/src/irdevice/irdevice.ts +406 -0
- package/src/irdevice/light.ts +159 -425
- package/src/irdevice/other.ts +509 -661
- package/src/irdevice/tv.ts +123 -388
- package/src/irdevice/vacuumcleaner.ts +61 -324
- package/src/irdevice/waterheater.ts +63 -333
- package/src/platform.ts +395 -259
- package/src/settings.ts +120 -610
- package/src/utils.ts +661 -1
- package/src/device/waterdetector.json +0 -11
|
@@ -1,31 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* airpurifier.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
5
|
+
import { irdeviceBase } from './irdevice.js';
|
|
6
|
+
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
+
import type { irDevicesConfig, irdevice } from '../settings.js';
|
|
9
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* Platform Accessory
|
|
8
13
|
* An instance of this class is created for each accessory your platform registers
|
|
9
14
|
* Each accessory may expose multiple services of different service types.
|
|
10
15
|
*/
|
|
11
|
-
export class AirPurifier {
|
|
12
|
-
public readonly api: API;
|
|
13
|
-
public readonly log: Logging;
|
|
14
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
15
|
-
protected readonly hap: HAP;
|
|
16
|
+
export class AirPurifier extends irdeviceBase {
|
|
16
17
|
// Services
|
|
17
|
-
|
|
18
|
+
private AirPurifier: {
|
|
19
|
+
Name: CharacteristicValue;
|
|
20
|
+
Service: Service;
|
|
21
|
+
Active: CharacteristicValue;
|
|
22
|
+
RotationSpeed: CharacteristicValue;
|
|
23
|
+
CurrentAirPurifierState: CharacteristicValue;
|
|
24
|
+
TargetAirPurifierState: CharacteristicValue;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
private TemperatureSensor: {
|
|
28
|
+
Name: CharacteristicValue;
|
|
29
|
+
Service: Service;
|
|
30
|
+
CurrentTemperature: CharacteristicValue;
|
|
31
|
+
};
|
|
18
32
|
|
|
19
33
|
// Characteristic Values
|
|
20
|
-
Active!: CharacteristicValue;
|
|
21
34
|
APActive!: CharacteristicValue;
|
|
22
35
|
CurrentAPTemp!: CharacteristicValue;
|
|
23
36
|
CurrentAPMode!: CharacteristicValue;
|
|
24
|
-
RotationSpeed!: CharacteristicValue;
|
|
25
|
-
FirmwareRevision!: CharacteristicValue;
|
|
26
37
|
CurrentAPFanSpeed!: CharacteristicValue;
|
|
27
|
-
CurrentTemperature!: CharacteristicValue;
|
|
28
|
-
CurrentAirPurifierState!: CharacteristicValue;
|
|
29
38
|
CurrentHeaterCoolerState!: CharacteristicValue;
|
|
30
39
|
|
|
31
40
|
// Others
|
|
@@ -38,60 +47,68 @@ export class AirPurifier {
|
|
|
38
47
|
CurrentFanSpeed!: number;
|
|
39
48
|
static PURIFYING_AIR: number;
|
|
40
49
|
|
|
41
|
-
// Config
|
|
42
|
-
disablePushOn?: boolean;
|
|
43
|
-
disablePushOff?: boolean;
|
|
44
|
-
deviceLogging!: string;
|
|
45
|
-
|
|
46
50
|
constructor(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
readonly platform: SwitchBotPlatform,
|
|
52
|
+
accessory: PlatformAccessory,
|
|
53
|
+
device: irdevice & irDevicesConfig,
|
|
50
54
|
) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
accessory
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.setCharacteristic(this.hap.Characteristic.
|
|
67
|
-
.
|
|
68
|
-
.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.airPurifierService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
79
|
-
}
|
|
80
|
-
// handle on / off events using the Active characteristic
|
|
81
|
-
this.airPurifierService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
82
|
-
|
|
83
|
-
this.airPurifierService.getCharacteristic(this.hap.Characteristic.CurrentAirPurifierState).onGet(() => {
|
|
84
|
-
return this.CurrentAirPurifierStateGet();
|
|
85
|
-
});
|
|
55
|
+
super(platform, accessory, device);
|
|
56
|
+
|
|
57
|
+
// Initialize AirPurifier Service
|
|
58
|
+
accessory.context.AirPurifier = accessory.context.AirPurifier ?? {};
|
|
59
|
+
this.AirPurifier = {
|
|
60
|
+
Name: accessory.context.AirPurifier.Name ?? `${accessory.displayName} Air Purifier`,
|
|
61
|
+
Service: accessory.getService(this.hap.Service.AirPurifier) ?? accessory.addService(this.hap.Service.AirPurifier) as Service,
|
|
62
|
+
Active: accessory.context.Active ?? this.hap.Characteristic.Active.INACTIVE,
|
|
63
|
+
RotationSpeed: accessory.context.RotationSpeed ?? 0,
|
|
64
|
+
CurrentAirPurifierState: accessory.context.CurrentAirPurifierState ?? this.hap.Characteristic.CurrentAirPurifierState.INACTIVE,
|
|
65
|
+
TargetAirPurifierState: accessory.context.TargetAirPurifierState ?? this.hap.Characteristic.TargetAirPurifierState.AUTO,
|
|
66
|
+
};
|
|
67
|
+
accessory.context.AirPurifier = this.AirPurifier as object;
|
|
68
|
+
|
|
69
|
+
this.AirPurifier.Service
|
|
70
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.AirPurifier.Name)
|
|
71
|
+
.getCharacteristic(this.hap.Characteristic.Active)
|
|
72
|
+
.onGet(() => {
|
|
73
|
+
return this.AirPurifier.Active;
|
|
74
|
+
})
|
|
75
|
+
.onSet(this.ActiveSet.bind(this));
|
|
76
|
+
|
|
77
|
+
this.AirPurifier.Service
|
|
78
|
+
.getCharacteristic(this.hap.Characteristic.CurrentAirPurifierState)
|
|
79
|
+
.onGet(() => {
|
|
80
|
+
return this.CurrentAirPurifierStateGet();
|
|
81
|
+
});
|
|
86
82
|
|
|
87
|
-
this.
|
|
83
|
+
this.AirPurifier.Service
|
|
84
|
+
.getCharacteristic(this.hap.Characteristic.TargetAirPurifierState)
|
|
85
|
+
.onGet(() => {
|
|
86
|
+
return this.AirPurifier.TargetAirPurifierState;
|
|
87
|
+
})
|
|
88
|
+
.onSet(this.TargetAirPurifierStateSet.bind(this));
|
|
89
|
+
|
|
90
|
+
// Initialize TemperatureSensor Service
|
|
91
|
+
accessory.context.TemperatureSensor = accessory.context.TemperatureSensor ?? {};
|
|
92
|
+
this.TemperatureSensor = {
|
|
93
|
+
Name: accessory.context.TemperatureSensor.Name ?? `${accessory.displayName} Temperature Sensor`,
|
|
94
|
+
Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? accessory.addService(this.hap.Service.TemperatureSensor) as Service,
|
|
95
|
+
CurrentTemperature: accessory.context.CurrentTemperature || 24,
|
|
96
|
+
};
|
|
97
|
+
accessory.context.TemperatureSensor = this.TemperatureSensor as object;
|
|
98
|
+
|
|
99
|
+
this.TemperatureSensor.Service
|
|
100
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name)
|
|
101
|
+
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
102
|
+
.onGet(() => {
|
|
103
|
+
return this.TemperatureSensor.CurrentTemperature;
|
|
104
|
+
});
|
|
88
105
|
}
|
|
89
106
|
|
|
90
107
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
91
108
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
92
109
|
|
|
93
|
-
this.Active = value;
|
|
94
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
110
|
+
this.AirPurifier.Active = value;
|
|
111
|
+
if (this.AirPurifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
95
112
|
this.pushAirPurifierOnChanges();
|
|
96
113
|
} else {
|
|
97
114
|
this.pushAirPurifierOffChanges();
|
|
@@ -115,12 +132,12 @@ export class AirPurifier {
|
|
|
115
132
|
}
|
|
116
133
|
|
|
117
134
|
async CurrentAirPurifierStateGet(): Promise<number> {
|
|
118
|
-
if (this.Active === 1) {
|
|
119
|
-
this.CurrentAirPurifierState = this.hap.Characteristic.CurrentAirPurifierState.PURIFYING_AIR;
|
|
135
|
+
if (this.AirPurifier.Active === 1) {
|
|
136
|
+
this.AirPurifier.CurrentAirPurifierState = this.hap.Characteristic.CurrentAirPurifierState.PURIFYING_AIR;
|
|
120
137
|
} else {
|
|
121
|
-
this.CurrentAirPurifierState = this.hap.Characteristic.CurrentAirPurifierState.INACTIVE;
|
|
138
|
+
this.AirPurifier.CurrentAirPurifierState = this.hap.Characteristic.CurrentAirPurifierState.INACTIVE;
|
|
122
139
|
}
|
|
123
|
-
return this.CurrentAirPurifierState;
|
|
140
|
+
return this.AirPurifier.CurrentAirPurifierState;
|
|
124
141
|
}
|
|
125
142
|
|
|
126
143
|
/**
|
|
@@ -135,11 +152,9 @@ export class AirPurifier {
|
|
|
135
152
|
* AirPurifier: "command" "highSpeed" "default" = fan speed to high
|
|
136
153
|
*/
|
|
137
154
|
async pushAirPurifierOnChanges(): Promise<void> {
|
|
138
|
-
this.debugLog(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
);
|
|
142
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
155
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOnChanges Active: ${this.AirPurifier.Active},`
|
|
156
|
+
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
157
|
+
if (this.AirPurifier.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
143
158
|
const commandType: string = await this.commandType();
|
|
144
159
|
const command: string = await this.commandOn();
|
|
145
160
|
const bodyChange = JSON.stringify({
|
|
@@ -152,11 +167,9 @@ export class AirPurifier {
|
|
|
152
167
|
}
|
|
153
168
|
|
|
154
169
|
async pushAirPurifierOffChanges(): Promise<void> {
|
|
155
|
-
this.debugLog(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
);
|
|
159
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOn) {
|
|
170
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOffChanges Active: ${this.AirPurifier.Active},`
|
|
171
|
+
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
172
|
+
if (this.AirPurifier.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOn) {
|
|
160
173
|
const commandType: string = await this.commandType();
|
|
161
174
|
const command: string = await this.commandOff();
|
|
162
175
|
const bodyChange = JSON.stringify({
|
|
@@ -169,10 +182,8 @@ export class AirPurifier {
|
|
|
169
182
|
}
|
|
170
183
|
|
|
171
184
|
async pushAirPurifierStatusChanges(): Promise<void> {
|
|
172
|
-
this.debugLog(
|
|
173
|
-
|
|
174
|
-
` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
|
|
175
|
-
);
|
|
185
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierStatusChanges Active: ${this.AirPurifier.Active},`
|
|
186
|
+
+ ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
|
|
176
187
|
if (!this.Busy) {
|
|
177
188
|
this.Busy = true;
|
|
178
189
|
this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE;
|
|
@@ -184,22 +195,20 @@ export class AirPurifier {
|
|
|
184
195
|
}
|
|
185
196
|
|
|
186
197
|
async pushAirPurifierDetailsChanges(): Promise<void> {
|
|
187
|
-
this.debugLog(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
this.
|
|
192
|
-
this.
|
|
193
|
-
this.CurrentAPFanSpeed = this.CurrentFanSpeed || 1;
|
|
194
|
-
this.APActive = this.Active === 1 ? 'on' : 'off';
|
|
198
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierDetailsChanges Active: ${this.AirPurifier.Active},`
|
|
199
|
+
+ ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
|
|
200
|
+
this.CurrentAPTemp = this.TemperatureSensor!.CurrentTemperature ?? 24;
|
|
201
|
+
this.CurrentAPMode = this.CurrentMode ?? 1;
|
|
202
|
+
this.CurrentAPFanSpeed = this.CurrentFanSpeed ?? 1;
|
|
203
|
+
this.APActive = this.AirPurifier.Active === 1 ? 'on' : 'off';
|
|
195
204
|
const parameter = `${this.CurrentAPTemp},${this.CurrentAPMode},${this.CurrentAPFanSpeed},${this.APActive}`;
|
|
196
205
|
const bodyChange = JSON.stringify({
|
|
197
206
|
command: 'setAll',
|
|
198
207
|
parameter: `${parameter}`,
|
|
199
208
|
commandType: 'command',
|
|
200
209
|
});
|
|
201
|
-
if (this.Active === 1) {
|
|
202
|
-
if ((Number(this.CurrentTemperature) || 24) < (this.LastTemperature || 30)) {
|
|
210
|
+
if (this.AirPurifier.Active === 1) {
|
|
211
|
+
if ((Number(this.TemperatureSensor!.CurrentTemperature) || 24) < (this.LastTemperature || 30)) {
|
|
203
212
|
this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
204
213
|
} else {
|
|
205
214
|
this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.HEATING;
|
|
@@ -215,314 +224,70 @@ export class AirPurifier {
|
|
|
215
224
|
if (this.device.connectionType === 'OpenAPI') {
|
|
216
225
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
217
226
|
try {
|
|
218
|
-
const { body, statusCode } = await
|
|
219
|
-
body: bodyChange,
|
|
220
|
-
method: 'POST',
|
|
221
|
-
headers: this.platform.generateHeaders(),
|
|
222
|
-
});
|
|
223
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
227
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
224
228
|
const deviceStatus: any = await body.json();
|
|
225
|
-
this.
|
|
226
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
229
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
227
230
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
228
|
-
this.
|
|
229
|
-
|
|
230
|
-
this.updateHomeKitCharacteristics();
|
|
231
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
232
|
+
await this.updateHomeKitCharacteristics();
|
|
231
233
|
} else {
|
|
232
|
-
this.statusCode(statusCode);
|
|
233
|
-
this.statusCode(deviceStatus.statusCode);
|
|
234
|
+
await this.statusCode(statusCode);
|
|
235
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
234
236
|
}
|
|
235
237
|
} catch (e: any) {
|
|
236
238
|
this.apiError(e);
|
|
237
|
-
this.errorLog(
|
|
238
|
-
|
|
239
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
240
|
-
);
|
|
239
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
|
|
240
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
241
241
|
}
|
|
242
242
|
} else {
|
|
243
|
-
this.warnLog(
|
|
244
|
-
|
|
245
|
-
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
246
|
-
);
|
|
243
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
244
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
247
245
|
}
|
|
248
246
|
}
|
|
249
247
|
|
|
250
248
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
251
249
|
// Active
|
|
252
|
-
if (this.Active === undefined) {
|
|
253
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
250
|
+
if (this.AirPurifier.Active === undefined) {
|
|
251
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.AirPurifier.Active}`);
|
|
254
252
|
} else {
|
|
255
|
-
this.accessory.context.Active = this.Active;
|
|
256
|
-
this.
|
|
257
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
253
|
+
this.accessory.context.Active = this.AirPurifier.Active;
|
|
254
|
+
this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.AirPurifier.Active);
|
|
255
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.AirPurifier.Active}`);
|
|
258
256
|
}
|
|
259
257
|
// CurrentAirPurifierState
|
|
260
|
-
if (this.CurrentAirPurifierState === undefined) {
|
|
261
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
|
|
258
|
+
if (this.AirPurifier.CurrentAirPurifierState === undefined) {
|
|
259
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentAirPurifierState: ${this.AirPurifier.CurrentAirPurifierState}`);
|
|
262
260
|
} else {
|
|
263
|
-
this.accessory.context.CurrentAirPurifierState = this.CurrentAirPurifierState;
|
|
264
|
-
this.
|
|
265
|
-
this.debugLog(
|
|
266
|
-
|
|
267
|
-
);
|
|
261
|
+
this.accessory.context.CurrentAirPurifierState = this.AirPurifier.CurrentAirPurifierState;
|
|
262
|
+
this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentAirPurifierState, this.AirPurifier.CurrentAirPurifierState);
|
|
263
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
264
|
+
+ ` CurrentAirPurifierState: ${this.AirPurifier.CurrentAirPurifierState}`);
|
|
268
265
|
}
|
|
269
266
|
// CurrentHeaterCoolerState
|
|
270
267
|
if (this.CurrentHeaterCoolerState === undefined) {
|
|
271
268
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
272
269
|
} else {
|
|
273
270
|
this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
|
|
274
|
-
this.
|
|
275
|
-
this.debugLog(
|
|
276
|
-
|
|
277
|
-
` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
283
|
-
if (device.disablePushOn === undefined) {
|
|
284
|
-
this.disablePushOn = false;
|
|
285
|
-
} else {
|
|
286
|
-
this.disablePushOn = device.disablePushOn;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
291
|
-
if (device.disablePushOff === undefined) {
|
|
292
|
-
this.disablePushOff = false;
|
|
293
|
-
} else {
|
|
294
|
-
this.disablePushOff = device.disablePushOff;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
async commandType(): Promise<string> {
|
|
299
|
-
let commandType: string;
|
|
300
|
-
if (this.device.customize) {
|
|
301
|
-
commandType = 'customize';
|
|
302
|
-
} else {
|
|
303
|
-
commandType = 'command';
|
|
304
|
-
}
|
|
305
|
-
return commandType;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
async commandOn(): Promise<string> {
|
|
309
|
-
let command: string;
|
|
310
|
-
if (this.device.customize && this.device.customOn) {
|
|
311
|
-
command = this.device.customOn;
|
|
312
|
-
} else {
|
|
313
|
-
command = 'turnOn';
|
|
271
|
+
this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
|
|
272
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
273
|
+
+ ` CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
314
274
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
async commandOff(): Promise<string> {
|
|
319
|
-
let command: string;
|
|
320
|
-
if (this.device.customize && this.device.customOff) {
|
|
321
|
-
command = this.device.customOff;
|
|
275
|
+
// CurrentTemperature
|
|
276
|
+
if (this.TemperatureSensor.CurrentTemperature === undefined) {
|
|
277
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
322
278
|
} else {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
329
|
-
switch (statusCode) {
|
|
330
|
-
case 151:
|
|
331
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
332
|
-
break;
|
|
333
|
-
case 152:
|
|
334
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
335
|
-
break;
|
|
336
|
-
case 160:
|
|
337
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
338
|
-
break;
|
|
339
|
-
case 161:
|
|
340
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
341
|
-
break;
|
|
342
|
-
case 171:
|
|
343
|
-
this.errorLog(
|
|
344
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
345
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
346
|
-
);
|
|
347
|
-
break;
|
|
348
|
-
case 190:
|
|
349
|
-
this.errorLog(
|
|
350
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
351
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
352
|
-
);
|
|
353
|
-
break;
|
|
354
|
-
case 100:
|
|
355
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
356
|
-
break;
|
|
357
|
-
case 200:
|
|
358
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
359
|
-
break;
|
|
360
|
-
case 400:
|
|
361
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
362
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
363
|
-
break;
|
|
364
|
-
case 401:
|
|
365
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
366
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
367
|
-
break;
|
|
368
|
-
case 403:
|
|
369
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
370
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
371
|
-
break;
|
|
372
|
-
case 404:
|
|
373
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
374
|
-
+ `statusCode: ${statusCode}`);
|
|
375
|
-
break;
|
|
376
|
-
case 406:
|
|
377
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
378
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
379
|
-
break;
|
|
380
|
-
case 415:
|
|
381
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
382
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
383
|
-
break;
|
|
384
|
-
case 422:
|
|
385
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
|
|
386
|
-
+ `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
387
|
-
break;
|
|
388
|
-
case 429:
|
|
389
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
390
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
391
|
-
break;
|
|
392
|
-
case 500:
|
|
393
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
394
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
395
|
-
break;
|
|
396
|
-
default:
|
|
397
|
-
this.infoLog(
|
|
398
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
399
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
400
|
-
);
|
|
279
|
+
this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
|
|
280
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
|
|
281
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
282
|
+
+ ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
401
283
|
}
|
|
402
284
|
}
|
|
403
285
|
|
|
404
286
|
async apiError(e: any): Promise<void> {
|
|
405
|
-
this.
|
|
406
|
-
this.
|
|
407
|
-
this.
|
|
408
|
-
this.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
private deviceContext() {
|
|
412
|
-
if (this.Active === undefined) {
|
|
413
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
414
|
-
} else {
|
|
415
|
-
this.Active = this.accessory.context.Active;
|
|
416
|
-
}
|
|
417
|
-
if (this.CurrentTemperature === undefined) {
|
|
418
|
-
this.CurrentTemperature = 24;
|
|
419
|
-
} else {
|
|
420
|
-
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
421
|
-
}
|
|
422
|
-
if (this.FirmwareRevision === undefined) {
|
|
423
|
-
this.FirmwareRevision = this.platform.version;
|
|
424
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
429
|
-
let config = {};
|
|
430
|
-
if (device.irpur) {
|
|
431
|
-
config = device.irpur;
|
|
432
|
-
}
|
|
433
|
-
if (device.logging !== undefined) {
|
|
434
|
-
config['logging'] = device.logging;
|
|
435
|
-
}
|
|
436
|
-
if (device.connectionType !== undefined) {
|
|
437
|
-
config['connectionType'] = device.connectionType;
|
|
438
|
-
}
|
|
439
|
-
if (device.external !== undefined) {
|
|
440
|
-
config['external'] = device.external;
|
|
441
|
-
}
|
|
442
|
-
if (device.customOn !== undefined) {
|
|
443
|
-
config['customOn'] = device.customOn;
|
|
444
|
-
}
|
|
445
|
-
if (device.customOff !== undefined) {
|
|
446
|
-
config['customOff'] = device.customOff;
|
|
447
|
-
}
|
|
448
|
-
if (device.customize !== undefined) {
|
|
449
|
-
config['customize'] = device.customize;
|
|
450
|
-
}
|
|
451
|
-
if (device.disablePushOn !== undefined) {
|
|
452
|
-
config['disablePushOn'] = device.disablePushOn;
|
|
453
|
-
}
|
|
454
|
-
if (device.disablePushOff !== undefined) {
|
|
455
|
-
config['disablePushOff'] = device.disablePushOff;
|
|
456
|
-
}
|
|
457
|
-
if (Object.entries(config).length !== 0) {
|
|
458
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
463
|
-
if (this.platform.debugMode) {
|
|
464
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
465
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
466
|
-
} else if (device.logging) {
|
|
467
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
468
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
469
|
-
} else if (this.platform.config.options?.logging) {
|
|
470
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
471
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
472
|
-
} else {
|
|
473
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
474
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
/**
|
|
479
|
-
* Logging for Device
|
|
480
|
-
*/
|
|
481
|
-
infoLog(...log: any[]): void {
|
|
482
|
-
if (this.enablingDeviceLogging()) {
|
|
483
|
-
this.platform.log.info(String(...log));
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
warnLog(...log: any[]): void {
|
|
488
|
-
if (this.enablingDeviceLogging()) {
|
|
489
|
-
this.platform.log.warn(String(...log));
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
debugWarnLog(...log: any[]): void {
|
|
494
|
-
if (this.enablingDeviceLogging()) {
|
|
495
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
496
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
errorLog(...log: any[]): void {
|
|
502
|
-
if (this.enablingDeviceLogging()) {
|
|
503
|
-
this.platform.log.error(String(...log));
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
debugErrorLog(...log: any[]): void {
|
|
508
|
-
if (this.enablingDeviceLogging()) {
|
|
509
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
510
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
debugLog(...log: any[]): void {
|
|
516
|
-
if (this.enablingDeviceLogging()) {
|
|
517
|
-
if (this.deviceLogging === 'debug') {
|
|
518
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
519
|
-
} else {
|
|
520
|
-
this.platform.log.debug(String(...log));
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
enablingDeviceLogging(): boolean {
|
|
526
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
287
|
+
this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, e);
|
|
288
|
+
this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentAirPurifierState, e);
|
|
289
|
+
this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.TargetAirPurifierState, e);
|
|
290
|
+
this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
291
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
527
292
|
}
|
|
528
293
|
}
|