@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
package/src/irdevice/fan.ts
CHANGED
|
@@ -1,162 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* fan.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
|
|
12
|
-
public readonly api: API;
|
|
13
|
-
public readonly log: Logging;
|
|
14
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
15
|
-
protected readonly hap: HAP;
|
|
16
|
+
export class IRFan extends irdeviceBase {
|
|
16
17
|
// Services
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
RotationDirection!: CharacteristicValue;
|
|
26
|
-
|
|
27
|
-
// Config
|
|
28
|
-
minStep?: number;
|
|
29
|
-
minValue?: number;
|
|
30
|
-
maxValue?: number;
|
|
31
|
-
deviceLogging!: string;
|
|
32
|
-
disablePushOn?: boolean;
|
|
33
|
-
disablePushOff?: boolean;
|
|
18
|
+
private Fan: {
|
|
19
|
+
Name: CharacteristicValue;
|
|
20
|
+
Service: Service;
|
|
21
|
+
Active: CharacteristicValue;
|
|
22
|
+
SwingMode: CharacteristicValue;
|
|
23
|
+
RotationSpeed: CharacteristicValue;
|
|
24
|
+
RotationDirection: CharacteristicValue;
|
|
25
|
+
};
|
|
34
26
|
|
|
35
27
|
constructor(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
readonly platform: SwitchBotPlatform,
|
|
29
|
+
accessory: PlatformAccessory,
|
|
30
|
+
device: irdevice & irDevicesConfig,
|
|
39
31
|
) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
accessory
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
.setCharacteristic(this.hap.Characteristic.
|
|
56
|
-
.
|
|
57
|
-
.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const fanService = `${accessory.displayName} Fan`;
|
|
62
|
-
(this.fanService = accessory.getService(this.hap.Service.Fanv2)
|
|
63
|
-
|| accessory.addService(this.hap.Service.Fanv2)), fanService;
|
|
64
|
-
|
|
65
|
-
this.fanService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
66
|
-
if (!this.fanService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
67
|
-
this.fanService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// handle on / off events using the Active characteristic
|
|
71
|
-
this.fanService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
32
|
+
super(platform, accessory, device);
|
|
33
|
+
|
|
34
|
+
// Initialize Switch Service
|
|
35
|
+
accessory.context.Fan = accessory.context.Fan ?? {};
|
|
36
|
+
this.Fan = {
|
|
37
|
+
Name: accessory.context.Fan.Name ?? `${accessory.displayName} Fan`,
|
|
38
|
+
Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
|
|
39
|
+
Active: accessory.context.Active ?? this.hap.Characteristic.Active.INACTIVE,
|
|
40
|
+
SwingMode: accessory.context.SwingMode ?? this.hap.Characteristic.SwingMode.SWING_DISABLED,
|
|
41
|
+
RotationSpeed: accessory.context.RotationSpeed ?? 0,
|
|
42
|
+
RotationDirection: accessory.context.RotationDirection ?? this.hap.Characteristic.RotationDirection.CLOCKWISE,
|
|
43
|
+
};
|
|
44
|
+
accessory.context.Fan = this.Fan as object;
|
|
45
|
+
|
|
46
|
+
this.Fan.Service
|
|
47
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
|
|
48
|
+
.getCharacteristic(this.hap.Characteristic.Active)
|
|
49
|
+
.onGet(() => {
|
|
50
|
+
return this.Fan.Active;
|
|
51
|
+
})
|
|
52
|
+
.onSet(this.ActiveSet.bind(this));
|
|
72
53
|
|
|
73
54
|
if (device.irfan?.rotation_speed) {
|
|
74
|
-
if (device.irfan?.set_minStep) {
|
|
75
|
-
this.minStep = device.irfan?.set_minStep;
|
|
76
|
-
} else {
|
|
77
|
-
this.minStep = 1;
|
|
78
|
-
}
|
|
79
|
-
if (device.irfan?.set_min) {
|
|
80
|
-
this.minValue = device.irfan?.set_min;
|
|
81
|
-
} else {
|
|
82
|
-
this.minValue = 1;
|
|
83
|
-
}
|
|
84
|
-
if (device.irfan?.set_max) {
|
|
85
|
-
this.maxValue = device.irfan?.set_max;
|
|
86
|
-
} else {
|
|
87
|
-
this.maxValue = 100;
|
|
88
|
-
}
|
|
89
55
|
// handle Rotation Speed events using the RotationSpeed characteristic
|
|
90
|
-
this.
|
|
56
|
+
this.Fan.Service
|
|
91
57
|
.getCharacteristic(this.hap.Characteristic.RotationSpeed)
|
|
92
58
|
.setProps({
|
|
93
|
-
minStep:
|
|
94
|
-
minValue:
|
|
95
|
-
maxValue:
|
|
59
|
+
minStep: device.irfan?.set_minStep ?? 1,
|
|
60
|
+
minValue: device.irfan?.set_min ?? 1,
|
|
61
|
+
maxValue: device.irfan?.set_max ?? 100,
|
|
62
|
+
})
|
|
63
|
+
.onGet(() => {
|
|
64
|
+
return this.Fan.RotationSpeed;
|
|
96
65
|
})
|
|
97
66
|
.onSet(this.RotationSpeedSet.bind(this));
|
|
98
|
-
} else if (this.
|
|
99
|
-
const characteristic = this.
|
|
100
|
-
this.
|
|
67
|
+
} else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
|
|
68
|
+
const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.RotationSpeed);
|
|
69
|
+
this.Fan.Service.removeCharacteristic(characteristic);
|
|
101
70
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`);
|
|
102
71
|
} else {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed Characteristic was not removed/added, ` +
|
|
106
|
-
`Clear Cache on ${this.accessory.displayName} to remove Chracteristic`,
|
|
107
|
-
);
|
|
72
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed Characteristic was not removed/added, `
|
|
73
|
+
+ `Clear Cache on ${this.accessory.displayName} to remove Chracteristic`);
|
|
108
74
|
}
|
|
109
75
|
|
|
110
76
|
if (device.irfan?.swing_mode) {
|
|
111
77
|
// handle Osolcation events using the SwingMode characteristic
|
|
112
|
-
this.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
78
|
+
this.Fan.Service
|
|
79
|
+
.getCharacteristic(this.hap.Characteristic.SwingMode)
|
|
80
|
+
.onGet(() => {
|
|
81
|
+
return this.Fan.SwingMode;
|
|
82
|
+
})
|
|
83
|
+
.onSet(this.SwingModeSet.bind(this));
|
|
84
|
+
} else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
|
|
85
|
+
const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.SwingMode);
|
|
86
|
+
this.Fan.Service.removeCharacteristic(characteristic);
|
|
116
87
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Swing Mode Characteristic was removed.`);
|
|
117
88
|
} else {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Swing Mode Characteristic was not removed/added, ` +
|
|
121
|
-
`Clear Cache on ${this.accessory.displayName} To Remove Chracteristic`,
|
|
122
|
-
);
|
|
89
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Swing Mode Characteristic was not removed/added, `
|
|
90
|
+
+ `Clear Cache on ${this.accessory.displayName} To Remove Chracteristic`);
|
|
123
91
|
}
|
|
124
92
|
}
|
|
125
93
|
|
|
126
94
|
async SwingModeSet(value: CharacteristicValue): Promise<void> {
|
|
127
95
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} SwingMode: ${value}`);
|
|
128
|
-
if (value > this.SwingMode) {
|
|
129
|
-
this.SwingMode = 1;
|
|
96
|
+
if (value > this.Fan.SwingMode) {
|
|
97
|
+
this.Fan.SwingMode = 1;
|
|
130
98
|
await this.pushFanOnChanges();
|
|
131
99
|
await this.pushFanSwingChanges();
|
|
132
100
|
} else {
|
|
133
|
-
this.SwingMode = 0;
|
|
101
|
+
this.Fan.SwingMode = 0;
|
|
134
102
|
await this.pushFanOnChanges();
|
|
135
103
|
await this.pushFanSwingChanges();
|
|
136
104
|
}
|
|
137
|
-
this.SwingMode = value;
|
|
138
|
-
this.accessory.context.SwingMode = this.SwingMode;
|
|
105
|
+
this.Fan.SwingMode = value;
|
|
106
|
+
this.accessory.context.SwingMode = this.Fan.SwingMode;
|
|
139
107
|
}
|
|
140
108
|
|
|
141
109
|
async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
|
|
142
110
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${value}`);
|
|
143
|
-
if (value > this.RotationSpeed) {
|
|
144
|
-
this.RotationSpeed = 1;
|
|
111
|
+
if (value > this.Fan.RotationSpeed) {
|
|
112
|
+
this.Fan.RotationSpeed = 1;
|
|
145
113
|
this.pushFanSpeedUpChanges();
|
|
146
114
|
this.pushFanOnChanges();
|
|
147
115
|
} else {
|
|
148
|
-
this.RotationSpeed = 0;
|
|
116
|
+
this.Fan.RotationSpeed = 0;
|
|
149
117
|
this.pushFanSpeedDownChanges();
|
|
150
118
|
}
|
|
151
|
-
this.RotationSpeed = value;
|
|
152
|
-
this.accessory.context.RotationSpeed = this.RotationSpeed;
|
|
119
|
+
this.Fan.RotationSpeed = value;
|
|
120
|
+
this.accessory.context.RotationSpeed = this.Fan.RotationSpeed;
|
|
153
121
|
}
|
|
154
122
|
|
|
155
123
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
156
124
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
|
|
157
125
|
|
|
158
|
-
this.Active = value;
|
|
159
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
126
|
+
this.Fan.Active = value;
|
|
127
|
+
if (this.Fan.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
160
128
|
this.pushFanOnChanges();
|
|
161
129
|
} else {
|
|
162
130
|
this.pushFanOffChanges();
|
|
@@ -173,10 +141,9 @@ export class Fan {
|
|
|
173
141
|
* Fan - "command" "highSpeed" "default" = fan speed to high
|
|
174
142
|
*/
|
|
175
143
|
async pushFanOnChanges(): Promise<void> {
|
|
176
|
-
this.debugLog(
|
|
177
|
-
|
|
178
|
-
)
|
|
179
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
144
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushFanOnChanges Active: ${this.Fan.Active},`
|
|
145
|
+
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
146
|
+
if (this.Fan.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
180
147
|
const commandType: string = await this.commandType();
|
|
181
148
|
const command: string = await this.commandOn();
|
|
182
149
|
const bodyChange = JSON.stringify({
|
|
@@ -189,11 +156,9 @@ export class Fan {
|
|
|
189
156
|
}
|
|
190
157
|
|
|
191
158
|
async pushFanOffChanges(): Promise<void> {
|
|
192
|
-
this.debugLog(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
);
|
|
196
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
159
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges Active: ${this.Fan.Active},`
|
|
160
|
+
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
161
|
+
if (this.Fan.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
197
162
|
const commandType: string = await this.commandType();
|
|
198
163
|
const command: string = await this.commandOff();
|
|
199
164
|
const bodyChange = JSON.stringify({
|
|
@@ -237,300 +202,54 @@ export class Fan {
|
|
|
237
202
|
if (this.device.connectionType === 'OpenAPI') {
|
|
238
203
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
239
204
|
try {
|
|
240
|
-
const { body, statusCode } = await
|
|
241
|
-
body: bodyChange,
|
|
242
|
-
method: 'POST',
|
|
243
|
-
headers: this.platform.generateHeaders(),
|
|
244
|
-
});
|
|
245
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
205
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
246
206
|
const deviceStatus: any = await body.json();
|
|
247
|
-
this.
|
|
248
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
207
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
249
208
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
250
|
-
this.
|
|
251
|
-
|
|
252
|
-
this.updateHomeKitCharacteristics();
|
|
209
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
210
|
+
await this.updateHomeKitCharacteristics();
|
|
253
211
|
} else {
|
|
254
|
-
this.statusCode(statusCode);
|
|
255
|
-
this.statusCode(deviceStatus.statusCode);
|
|
212
|
+
await this.statusCode(statusCode);
|
|
213
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
256
214
|
}
|
|
257
215
|
} catch (e: any) {
|
|
258
216
|
this.apiError(e);
|
|
259
|
-
this.errorLog(
|
|
260
|
-
|
|
261
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
262
|
-
);
|
|
217
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
|
|
218
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
263
219
|
}
|
|
264
220
|
} else {
|
|
265
|
-
this.warnLog(
|
|
266
|
-
|
|
267
|
-
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
268
|
-
);
|
|
221
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
222
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
269
223
|
}
|
|
270
224
|
}
|
|
271
225
|
|
|
272
226
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
273
|
-
if (this.Active === undefined) {
|
|
274
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
275
|
-
} else {
|
|
276
|
-
this.accessory.context.Active = this.Active;
|
|
277
|
-
this.fanService?.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
|
|
278
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
279
|
-
}
|
|
280
|
-
if (this.SwingMode === undefined) {
|
|
281
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
|
|
282
|
-
} else {
|
|
283
|
-
this.accessory.context.SwingMode = this.SwingMode;
|
|
284
|
-
this.fanService?.updateCharacteristic(this.hap.Characteristic.SwingMode, this.SwingMode);
|
|
285
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
|
|
286
|
-
}
|
|
287
|
-
if (this.RotationSpeed === undefined) {
|
|
288
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
|
|
289
|
-
} else {
|
|
290
|
-
this.accessory.context.RotationSpeed = this.RotationSpeed;
|
|
291
|
-
this.fanService?.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.RotationSpeed);
|
|
292
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
297
|
-
if (device.disablePushOn === undefined) {
|
|
298
|
-
this.disablePushOn = false;
|
|
227
|
+
if (this.Fan.Active === undefined) {
|
|
228
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Fan.Active}`);
|
|
299
229
|
} else {
|
|
300
|
-
this.
|
|
230
|
+
this.accessory.context.Active = this.Fan.Active;
|
|
231
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Fan.Active);
|
|
232
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Fan.Active}`);
|
|
301
233
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
305
|
-
if (device.disablePushOff === undefined) {
|
|
306
|
-
this.disablePushOff = false;
|
|
234
|
+
if (this.Fan.SwingMode === undefined) {
|
|
235
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} SwingMode: ${this.Fan.SwingMode}`);
|
|
307
236
|
} else {
|
|
308
|
-
this.
|
|
237
|
+
this.accessory.context.SwingMode = this.Fan.SwingMode;
|
|
238
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.SwingMode, this.Fan.SwingMode);
|
|
239
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.Fan.SwingMode}`);
|
|
309
240
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
async commandType(): Promise<string> {
|
|
313
|
-
let commandType: string;
|
|
314
|
-
if (this.device.customize) {
|
|
315
|
-
commandType = 'customize';
|
|
241
|
+
if (this.Fan.RotationSpeed === undefined) {
|
|
242
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.Fan.RotationSpeed}`);
|
|
316
243
|
} else {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
async commandOn(): Promise<string> {
|
|
323
|
-
let command: string;
|
|
324
|
-
if (this.device.customize && this.device.customOn) {
|
|
325
|
-
command = this.device.customOn;
|
|
326
|
-
} else {
|
|
327
|
-
command = 'turnOn';
|
|
328
|
-
}
|
|
329
|
-
return command;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
async commandOff(): Promise<string> {
|
|
333
|
-
let command: string;
|
|
334
|
-
if (this.device.customize && this.device.customOff) {
|
|
335
|
-
command = this.device.customOff;
|
|
336
|
-
} else {
|
|
337
|
-
command = 'turnOff';
|
|
338
|
-
}
|
|
339
|
-
return command;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
343
|
-
switch (statusCode) {
|
|
344
|
-
case 151:
|
|
345
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
346
|
-
break;
|
|
347
|
-
case 152:
|
|
348
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
349
|
-
break;
|
|
350
|
-
case 160:
|
|
351
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
352
|
-
break;
|
|
353
|
-
case 161:
|
|
354
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
355
|
-
break;
|
|
356
|
-
case 171:
|
|
357
|
-
this.errorLog(
|
|
358
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
359
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
360
|
-
);
|
|
361
|
-
break;
|
|
362
|
-
case 190:
|
|
363
|
-
this.errorLog(
|
|
364
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
365
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
366
|
-
);
|
|
367
|
-
break;
|
|
368
|
-
case 100:
|
|
369
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
370
|
-
break;
|
|
371
|
-
case 200:
|
|
372
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
373
|
-
break;
|
|
374
|
-
case 400:
|
|
375
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
376
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
377
|
-
break;
|
|
378
|
-
case 401:
|
|
379
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
380
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
381
|
-
break;
|
|
382
|
-
case 403:
|
|
383
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
384
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
385
|
-
break;
|
|
386
|
-
case 404:
|
|
387
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
388
|
-
+ `statusCode: ${statusCode}`);
|
|
389
|
-
break;
|
|
390
|
-
case 406:
|
|
391
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
392
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
393
|
-
break;
|
|
394
|
-
case 415:
|
|
395
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
396
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
397
|
-
break;
|
|
398
|
-
case 422:
|
|
399
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
|
|
400
|
-
+ `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
401
|
-
break;
|
|
402
|
-
case 429:
|
|
403
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
404
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
405
|
-
break;
|
|
406
|
-
case 500:
|
|
407
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
408
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
409
|
-
break;
|
|
410
|
-
default:
|
|
411
|
-
this.infoLog(
|
|
412
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
413
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
414
|
-
);
|
|
244
|
+
this.accessory.context.RotationSpeed = this.Fan.RotationSpeed;
|
|
245
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.Fan.RotationSpeed);
|
|
246
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.Fan.RotationSpeed}`);
|
|
415
247
|
}
|
|
416
248
|
}
|
|
417
249
|
|
|
418
250
|
async apiError(e: any): Promise<void> {
|
|
419
|
-
this.
|
|
420
|
-
this.
|
|
421
|
-
this.
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
async deviceContext() {
|
|
425
|
-
if (this.Active === undefined) {
|
|
426
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
427
|
-
} else {
|
|
428
|
-
this.Active = this.accessory.context.Active;
|
|
429
|
-
}
|
|
430
|
-
if (this.FirmwareRevision === undefined) {
|
|
431
|
-
this.FirmwareRevision = this.platform.version;
|
|
432
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
437
|
-
let config = {};
|
|
438
|
-
if (device.irfan) {
|
|
439
|
-
config = device.irfan;
|
|
440
|
-
}
|
|
441
|
-
if (device.logging !== undefined) {
|
|
442
|
-
config['logging'] = device.logging;
|
|
443
|
-
}
|
|
444
|
-
if (device.connectionType !== undefined) {
|
|
445
|
-
config['connectionType'] = device.connectionType;
|
|
446
|
-
}
|
|
447
|
-
if (device.external !== undefined) {
|
|
448
|
-
config['external'] = device.external;
|
|
449
|
-
}
|
|
450
|
-
if (device.customOn !== undefined) {
|
|
451
|
-
config['customOn'] = device.customOn;
|
|
452
|
-
}
|
|
453
|
-
if (device.customOff !== undefined) {
|
|
454
|
-
config['customOff'] = device.customOff;
|
|
455
|
-
}
|
|
456
|
-
if (device.customize !== undefined) {
|
|
457
|
-
config['customize'] = device.customize;
|
|
458
|
-
}
|
|
459
|
-
if (device.disablePushOn !== undefined) {
|
|
460
|
-
config['disablePushOn'] = device.disablePushOn;
|
|
461
|
-
}
|
|
462
|
-
if (device.disablePushOff !== undefined) {
|
|
463
|
-
config['disablePushOff'] = device.disablePushOff;
|
|
464
|
-
}
|
|
465
|
-
if (Object.entries(config).length !== 0) {
|
|
466
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
471
|
-
if (this.platform.debugMode) {
|
|
472
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
473
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
474
|
-
} else if (device.logging) {
|
|
475
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
476
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
477
|
-
} else if (this.platform.config.options?.logging) {
|
|
478
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
479
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
480
|
-
} else {
|
|
481
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
482
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* Logging for Device
|
|
488
|
-
*/
|
|
489
|
-
infoLog(...log: any[]): void {
|
|
490
|
-
if (this.enablingDeviceLogging()) {
|
|
491
|
-
this.platform.log.info(String(...log));
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
warnLog(...log: any[]): void {
|
|
496
|
-
if (this.enablingDeviceLogging()) {
|
|
497
|
-
this.platform.log.warn(String(...log));
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
debugWarnLog(...log: any[]): void {
|
|
502
|
-
if (this.enablingDeviceLogging()) {
|
|
503
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
504
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
errorLog(...log: any[]): void {
|
|
510
|
-
if (this.enablingDeviceLogging()) {
|
|
511
|
-
this.platform.log.error(String(...log));
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
debugErrorLog(...log: any[]): void {
|
|
516
|
-
if (this.enablingDeviceLogging()) {
|
|
517
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
518
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
debugLog(...log: any[]): void {
|
|
524
|
-
if (this.enablingDeviceLogging()) {
|
|
525
|
-
if (this.deviceLogging === 'debug') {
|
|
526
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
527
|
-
} else {
|
|
528
|
-
this.platform.log.debug(String(...log));
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
enablingDeviceLogging(): boolean {
|
|
534
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
251
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
252
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
|
|
253
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.SwingMode, e);
|
|
535
254
|
}
|
|
536
255
|
}
|