@switchbot/homebridge-switchbot 3.7.1-beta.9 → 3.8.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/CHANGELOG.md +8 -2
- package/README.md +14 -0
- package/assets/security-privacy-bluetooth.png +0 -0
- package/config.schema.json +76 -1
- package/dist/device/blindtilt.d.ts +18 -8
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +108 -70
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -9
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +133 -160
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +38 -73
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +12 -12
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +41 -79
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +5 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +20 -42
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +15 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +127 -81
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +18 -18
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +33 -36
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +8 -8
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +43 -75
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +5 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +18 -39
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +5 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -78
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +5 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +21 -40
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +6 -6
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +34 -73
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +9 -9
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +37 -52
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +21 -39
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +5 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +21 -38
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +5 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +14 -32
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +12 -12
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +16 -25
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -11
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +42 -56
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +5 -5
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +47 -44
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/server.js +2 -2
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -8
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +61 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +10 -10
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +22 -42
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +9 -9
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +15 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -8
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +21 -40
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +11 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +14 -22
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -9
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +24 -47
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +9 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +40 -83
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +9 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +29 -54
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +5 -5
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -21
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +5 -5
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -22
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +20 -19
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +466 -710
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +5 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +9 -9
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts +6 -6
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/deviceresponse.d.ts +4 -4
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +2 -2
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +5 -5
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts +4 -4
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/pushbody.d.ts +2 -2
- package/dist/types/pushbody.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -13
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +48 -93
- package/package.json +61 -54
- package/src/device/blindtilt.ts +509 -460
- package/src/device/bot.ts +696 -718
- package/src/device/ceilinglight.ts +331 -364
- package/src/device/colorbulb.ts +412 -448
- package/src/device/contact.ts +200 -221
- package/src/device/curtain.ts +506 -444
- package/src/device/device.ts +206 -208
- package/src/device/fan.ts +307 -340
- package/src/device/hub.ts +184 -209
- package/src/device/humidifier.ts +297 -342
- package/src/device/iosensor.ts +182 -204
- package/src/device/lightstrip.ts +362 -399
- package/src/device/lock.ts +262 -276
- package/src/device/meter.ts +183 -205
- package/src/device/meterplus.ts +183 -204
- package/src/device/motion.ts +169 -185
- package/src/device/plug.ts +174 -177
- package/src/device/robotvacuumcleaner.ts +256 -269
- package/src/device/waterdetector.ts +185 -185
- package/src/homebridge-ui/server.ts +16 -15
- package/src/index.ts +5 -6
- package/src/irdevice/airconditioner.ts +277 -326
- package/src/irdevice/airpurifier.ts +124 -143
- package/src/irdevice/camera.ts +58 -64
- package/src/irdevice/fan.ts +106 -123
- package/src/irdevice/irdevice.ts +116 -119
- package/src/irdevice/light.ts +119 -143
- package/src/irdevice/other.ts +417 -461
- package/src/irdevice/tv.ts +155 -177
- package/src/irdevice/vacuumcleaner.ts +54 -60
- package/src/irdevice/waterheater.ts +56 -63
- package/src/platform.ts +1462 -1678
- package/src/settings.ts +173 -170
- package/src/types/bledevicestatus.ts +252 -256
- package/src/types/devicelist.ts +79 -79
- package/src/types/deviceresponse.ts +12 -13
- package/src/types/devicestatus.ts +124 -124
- package/src/types/devicewebhookstatus.ts +126 -131
- package/src/types/irdevicelist.ts +10 -10
- package/src/types/pushbody.ts +5 -5
- package/src/utils.ts +64 -65
- package/tsconfig.json +10 -9
- package/.github/npm-version-script.cjs +0 -81
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
*
|
|
3
3
|
* airconditioners.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
6
|
|
|
7
|
-
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
-
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
-
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
|
-
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
|
+
|
|
11
|
+
import { irdeviceBase } from './irdevice.js'
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Platform Accessory
|
|
@@ -17,55 +18,55 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
|
|
|
17
18
|
export class AirConditioner extends irdeviceBase {
|
|
18
19
|
// Services
|
|
19
20
|
private HeaterCooler: {
|
|
20
|
-
Name: CharacteristicValue
|
|
21
|
-
Service: Service
|
|
22
|
-
Active: CharacteristicValue
|
|
23
|
-
CurrentHeaterCoolerState: CharacteristicValue
|
|
24
|
-
TargetHeaterCoolerState: CharacteristicValue
|
|
25
|
-
CurrentTemperature: CharacteristicValue
|
|
26
|
-
ThresholdTemperature: CharacteristicValue
|
|
27
|
-
RotationSpeed: CharacteristicValue
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
meter?: PlatformAccessory
|
|
21
|
+
Name: CharacteristicValue
|
|
22
|
+
Service: Service
|
|
23
|
+
Active: CharacteristicValue
|
|
24
|
+
CurrentHeaterCoolerState: CharacteristicValue
|
|
25
|
+
TargetHeaterCoolerState: CharacteristicValue
|
|
26
|
+
CurrentTemperature: CharacteristicValue
|
|
27
|
+
ThresholdTemperature: CharacteristicValue
|
|
28
|
+
RotationSpeed: CharacteristicValue
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
meter?: PlatformAccessory
|
|
31
32
|
|
|
32
33
|
private HumiditySensor?: {
|
|
33
|
-
Name: CharacteristicValue
|
|
34
|
-
Service: Service
|
|
35
|
-
CurrentRelativeHumidity: CharacteristicValue
|
|
36
|
-
}
|
|
34
|
+
Name: CharacteristicValue
|
|
35
|
+
Service: Service
|
|
36
|
+
CurrentRelativeHumidity: CharacteristicValue
|
|
37
|
+
}
|
|
37
38
|
|
|
38
39
|
// Others
|
|
39
|
-
state!: string
|
|
40
|
-
Busy: any
|
|
41
|
-
Timeout: any = null
|
|
42
|
-
CurrentMode!: number
|
|
43
|
-
ValidValues: number[]
|
|
44
|
-
CurrentFanSpeed!: number
|
|
40
|
+
state!: string
|
|
41
|
+
Busy: any
|
|
42
|
+
Timeout: any = null
|
|
43
|
+
CurrentMode!: number
|
|
44
|
+
ValidValues: number[]
|
|
45
|
+
CurrentFanSpeed!: number
|
|
45
46
|
|
|
46
47
|
// Config
|
|
47
|
-
hide_automode?: boolean
|
|
48
|
-
set_max_heat?: number
|
|
49
|
-
set_min_heat?: number
|
|
50
|
-
set_max_cool?: number
|
|
51
|
-
set_min_cool?: number
|
|
48
|
+
hide_automode?: boolean
|
|
49
|
+
set_max_heat?: number
|
|
50
|
+
set_min_heat?: number
|
|
51
|
+
set_max_cool?: number
|
|
52
|
+
set_min_cool?: number
|
|
52
53
|
|
|
53
54
|
constructor(
|
|
54
55
|
readonly platform: SwitchBotPlatform,
|
|
55
56
|
accessory: PlatformAccessory,
|
|
56
57
|
device: irdevice & irDevicesConfig,
|
|
57
58
|
) {
|
|
58
|
-
super(platform, accessory, device)
|
|
59
|
+
super(platform, accessory, device)
|
|
59
60
|
// Set category
|
|
60
|
-
accessory.category = this.hap.Categories.AIR_CONDITIONER
|
|
61
|
+
accessory.category = this.hap.Categories.AIR_CONDITIONER
|
|
61
62
|
|
|
62
63
|
// default placeholders
|
|
63
|
-
this.getAirConditionerConfigSettings(accessory, device)
|
|
64
|
+
this.getAirConditionerConfigSettings(accessory, device)
|
|
64
65
|
|
|
65
|
-
this.ValidValues = this.hide_automode ? [1, 2] : [0, 1, 2]
|
|
66
|
+
this.ValidValues = this.hide_automode ? [1, 2] : [0, 1, 2]
|
|
66
67
|
|
|
67
68
|
// Initialize HeaterCooler Service
|
|
68
|
-
accessory.context.HeaterCooler = accessory.context.HeaterCooler ?? {}
|
|
69
|
+
accessory.context.HeaterCooler = accessory.context.HeaterCooler ?? {}
|
|
69
70
|
this.HeaterCooler = {
|
|
70
71
|
Name: accessory.displayName,
|
|
71
72
|
Service: accessory.getService(this.hap.Service.HeaterCooler) ?? accessory.addService(this.hap.Service.HeaterCooler) as Service,
|
|
@@ -75,511 +76,461 @@ export class AirConditioner extends irdeviceBase {
|
|
|
75
76
|
CurrentTemperature: accessory.context.CurrentTemperature ?? 24,
|
|
76
77
|
ThresholdTemperature: accessory.context.ThresholdTemperature ?? 24,
|
|
77
78
|
RotationSpeed: accessory.context.RotationSpeed ?? 4,
|
|
78
|
-
}
|
|
79
|
-
accessory.context.HeaterCooler = this.HeaterCooler as object
|
|
80
|
-
|
|
81
|
-
this.HeaterCooler.Service
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.HeaterCooler.Service
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.HeaterCooler.Service
|
|
96
|
-
.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
this.HeaterCooler.Service
|
|
124
|
-
.getCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature)
|
|
125
|
-
.setProps({
|
|
126
|
-
minValue: this.set_min_cool,
|
|
127
|
-
maxValue: this.set_max_cool,
|
|
128
|
-
minStep: 0.5,
|
|
129
|
-
})
|
|
130
|
-
.onGet(async () => {
|
|
131
|
-
return await this.ThresholdTemperatureGet();
|
|
132
|
-
})
|
|
133
|
-
.onSet(this.ThresholdTemperatureSet.bind(this));
|
|
134
|
-
|
|
135
|
-
this.HeaterCooler.Service
|
|
136
|
-
.getCharacteristic(this.hap.Characteristic.RotationSpeed)
|
|
137
|
-
.setProps({
|
|
138
|
-
format: 'int',
|
|
139
|
-
minStep: 1,
|
|
140
|
-
minValue: 1,
|
|
141
|
-
maxValue: 4,
|
|
142
|
-
})
|
|
143
|
-
.onGet(async () => {
|
|
144
|
-
return await this.RotationSpeedGet();
|
|
145
|
-
})
|
|
146
|
-
.onSet(this.RotationSpeedSet.bind(this));
|
|
79
|
+
}
|
|
80
|
+
accessory.context.HeaterCooler = this.HeaterCooler as object
|
|
81
|
+
|
|
82
|
+
this.HeaterCooler.Service.setCharacteristic(this.hap.Characteristic.Name, this.HeaterCooler.Name).getCharacteristic(this.hap.Characteristic.Active).onGet(() => {
|
|
83
|
+
return this.HeaterCooler.Active
|
|
84
|
+
}).onSet(this.ActiveSet.bind(this))
|
|
85
|
+
|
|
86
|
+
this.HeaterCooler.Service.getCharacteristic(this.hap.Characteristic.CurrentTemperature).onGet(async () => {
|
|
87
|
+
return await this.CurrentTemperatureGet()
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
this.HeaterCooler.Service.getCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState).setProps({
|
|
91
|
+
validValues: this.ValidValues,
|
|
92
|
+
}).onGet(async () => {
|
|
93
|
+
return await this.TargetHeaterCoolerStateGet()
|
|
94
|
+
}).onSet(this.TargetHeaterCoolerStateSet.bind(this))
|
|
95
|
+
|
|
96
|
+
this.HeaterCooler.Service.getCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState).onGet(async () => {
|
|
97
|
+
return await this.CurrentHeaterCoolerStateGet()
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
this.HeaterCooler.Service.getCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature).setProps({
|
|
101
|
+
minValue: this.set_min_heat,
|
|
102
|
+
maxValue: this.set_max_heat,
|
|
103
|
+
minStep: 0.5,
|
|
104
|
+
}).onGet(async () => {
|
|
105
|
+
return await this.ThresholdTemperatureGet()
|
|
106
|
+
}).onSet(this.ThresholdTemperatureSet.bind(this))
|
|
107
|
+
|
|
108
|
+
this.HeaterCooler.Service.getCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature).setProps({
|
|
109
|
+
minValue: this.set_min_cool,
|
|
110
|
+
maxValue: this.set_max_cool,
|
|
111
|
+
minStep: 0.5,
|
|
112
|
+
}).onGet(async () => {
|
|
113
|
+
return await this.ThresholdTemperatureGet()
|
|
114
|
+
}).onSet(this.ThresholdTemperatureSet.bind(this))
|
|
115
|
+
|
|
116
|
+
this.HeaterCooler.Service.getCharacteristic(this.hap.Characteristic.RotationSpeed).setProps({
|
|
117
|
+
format: 'int',
|
|
118
|
+
minStep: 1,
|
|
119
|
+
minValue: 1,
|
|
120
|
+
maxValue: 4,
|
|
121
|
+
}).onGet(async () => {
|
|
122
|
+
return await this.RotationSpeedGet()
|
|
123
|
+
}).onSet(this.RotationSpeedSet.bind(this))
|
|
147
124
|
|
|
148
125
|
// Initialize HumiditySensor property
|
|
149
126
|
|
|
150
127
|
if (this.device.irair?.meterType && this.device.irair?.meterId) {
|
|
151
|
-
const meterUuid = this.platform.api.hap.uuid.generate(`${this.device.irair.meterId}-${this.device.irair.meterType}`)
|
|
152
|
-
this.meter = this.platform.accessories.find(
|
|
153
|
-
accessory.context.HumiditySensor = accessory.context.HumiditySensor ?? {}
|
|
128
|
+
const meterUuid = this.platform.api.hap.uuid.generate(`${this.device.irair.meterId}-${this.device.irair.meterType}`)
|
|
129
|
+
this.meter = this.platform.accessories.find(accessory => accessory.UUID === meterUuid)
|
|
130
|
+
accessory.context.HumiditySensor = accessory.context.HumiditySensor ?? {}
|
|
154
131
|
this.HumiditySensor = {
|
|
155
132
|
Name: this.meter!.displayName,
|
|
156
133
|
Service: this.meter!.getService(this.hap.Service.HumiditySensor) ?? this.meter!.addService(this.hap.Service.HumiditySensor) as Service,
|
|
157
134
|
CurrentRelativeHumidity: this.meter!.context.CurrentRelativeHumidity || 0,
|
|
158
|
-
}
|
|
159
|
-
accessory.context.HumiditySensor = this.HumiditySensor as object
|
|
135
|
+
}
|
|
136
|
+
accessory.context.HumiditySensor = this.HumiditySensor as object
|
|
160
137
|
}
|
|
161
138
|
|
|
162
139
|
if (this.device.irair?.meterType && this.device.irair?.meterId) {
|
|
163
|
-
const meterUuid = this.platform.api.hap.uuid.generate(`${this.device.irair.meterId}-${this.device.irair.meterType}`)
|
|
164
|
-
this.meter = this.platform.accessories.find(
|
|
140
|
+
const meterUuid = this.platform.api.hap.uuid.generate(`${this.device.irair.meterId}-${this.device.irair.meterType}`)
|
|
141
|
+
this.meter = this.platform.accessories.find(accessory => accessory.UUID === meterUuid)
|
|
165
142
|
}
|
|
166
143
|
|
|
167
144
|
if (this.meter && this.HumiditySensor) {
|
|
168
|
-
this.HumiditySensor.Service
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
.onGet(async () => {
|
|
172
|
-
return await this.CurrentRelativeHumidityGet();
|
|
173
|
-
});
|
|
145
|
+
this.HumiditySensor.Service.setCharacteristic(this.hap.Characteristic.Name, this.HumiditySensor.Name).getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity).onGet(async () => {
|
|
146
|
+
return await this.CurrentRelativeHumidityGet()
|
|
147
|
+
})
|
|
174
148
|
}
|
|
175
149
|
}
|
|
176
150
|
|
|
177
151
|
/**
|
|
178
152
|
* Pushes the requested changes to the SwitchBot API
|
|
179
|
-
* deviceType
|
|
180
|
-
* AirConditioner: "command" "swing"
|
|
181
|
-
* AirConditioner: "command" "timer"
|
|
182
|
-
* AirConditioner: "command" "lowSpeed"
|
|
183
|
-
* AirConditioner: "command" "middleSpeed"
|
|
184
|
-
* AirConditioner: "command" "highSpeed"
|
|
153
|
+
* deviceType commandType Command command parameter Description
|
|
154
|
+
* AirConditioner: "command" "swing" "default" = swing
|
|
155
|
+
* AirConditioner: "command" "timer" "default" = timer
|
|
156
|
+
* AirConditioner: "command" "lowSpeed" "default" = fan speed to low
|
|
157
|
+
* AirConditioner: "command" "middleSpeed" "default" = fan speed to medium
|
|
158
|
+
* AirConditioner: "command" "highSpeed" "default" = fan speed to high
|
|
185
159
|
*/
|
|
186
160
|
async pushAirConditionerOnChanges(): Promise<void> {
|
|
187
|
-
await this.debugLog(`pushAirConditionerOnChanges Active: ${this.HeaterCooler.Active}
|
|
188
|
-
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
161
|
+
await this.debugLog(`pushAirConditionerOnChanges Active: ${this.HeaterCooler.Active}, disablePushOn: ${this.disablePushOn}`)
|
|
189
162
|
if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
190
|
-
const commandType: string = await this.commandType()
|
|
191
|
-
const command: string = await this.commandOn()
|
|
163
|
+
const commandType: string = await this.commandType()
|
|
164
|
+
const command: string = await this.commandOn()
|
|
192
165
|
const bodyChange = JSON.stringify({
|
|
193
|
-
command
|
|
166
|
+
command,
|
|
194
167
|
parameter: 'default',
|
|
195
|
-
commandType
|
|
196
|
-
})
|
|
197
|
-
await this.pushChanges(bodyChange)
|
|
168
|
+
commandType,
|
|
169
|
+
})
|
|
170
|
+
await this.pushChanges(bodyChange)
|
|
198
171
|
}
|
|
199
172
|
}
|
|
200
173
|
|
|
201
174
|
async pushAirConditionerOffChanges(): Promise<void> {
|
|
202
|
-
await this.debugLog(`pushAirConditionerOffChanges Active: ${this.HeaterCooler.Active}
|
|
203
|
-
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
175
|
+
await this.debugLog(`pushAirConditionerOffChanges Active: ${this.HeaterCooler.Active}, disablePushOff: ${this.disablePushOff}`)
|
|
204
176
|
if (this.HeaterCooler.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
205
|
-
const commandType: string = await this.commandType()
|
|
206
|
-
const command: string = await this.commandOff()
|
|
177
|
+
const commandType: string = await this.commandType()
|
|
178
|
+
const command: string = await this.commandOff()
|
|
207
179
|
const bodyChange = JSON.stringify({
|
|
208
|
-
command
|
|
180
|
+
command,
|
|
209
181
|
parameter: 'default',
|
|
210
|
-
commandType
|
|
211
|
-
})
|
|
212
|
-
await this.pushChanges(bodyChange)
|
|
182
|
+
commandType,
|
|
183
|
+
})
|
|
184
|
+
await this.pushChanges(bodyChange)
|
|
213
185
|
}
|
|
214
186
|
}
|
|
215
187
|
|
|
216
188
|
async pushAirConditionerStatusChanges(): Promise<void> {
|
|
217
|
-
await this.debugLog(`pushAirConditionerStatusChanges Active: ${this.HeaterCooler.Active}
|
|
218
|
-
+ ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
|
|
189
|
+
await this.debugLog(`pushAirConditionerStatusChanges Active: ${this.HeaterCooler.Active}, disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`)
|
|
219
190
|
if (!this.Busy) {
|
|
220
|
-
this.Busy = true
|
|
221
|
-
this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE
|
|
191
|
+
this.Busy = true
|
|
192
|
+
this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE
|
|
222
193
|
}
|
|
223
|
-
clearTimeout(this.Timeout)
|
|
194
|
+
clearTimeout(this.Timeout)
|
|
224
195
|
|
|
225
196
|
// Make a new Timeout set to go off in 1000ms (1 second)
|
|
226
|
-
this.Timeout = setTimeout(this.pushAirConditionerDetailsChanges.bind(this), 1500)
|
|
197
|
+
this.Timeout = setTimeout(this.pushAirConditionerDetailsChanges.bind(this), 1500)
|
|
227
198
|
}
|
|
228
199
|
|
|
229
200
|
async pushAirConditionerDetailsChanges(): Promise<void> {
|
|
230
|
-
await this.debugLog(`pushAirConditionerDetailsChanges Active: ${this.HeaterCooler.Active}
|
|
231
|
-
|
|
232
|
-
//await this.deviceContext();
|
|
201
|
+
await this.debugLog(`pushAirConditionerDetailsChanges Active: ${this.HeaterCooler.Active}, disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`)
|
|
202
|
+
// await this.deviceContext();
|
|
233
203
|
if (this.CurrentMode === undefined) {
|
|
234
|
-
this.CurrentMode = 1
|
|
204
|
+
this.CurrentMode = 1
|
|
235
205
|
}
|
|
236
206
|
if (this.CurrentFanSpeed === undefined) {
|
|
237
|
-
this.CurrentFanSpeed = 1
|
|
207
|
+
this.CurrentFanSpeed = 1
|
|
238
208
|
}
|
|
239
209
|
if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
240
|
-
this.state = 'on'
|
|
210
|
+
this.state = 'on'
|
|
241
211
|
} else {
|
|
242
|
-
this.state = 'off'
|
|
212
|
+
this.state = 'off'
|
|
243
213
|
}
|
|
244
214
|
if (this.CurrentMode === 1) {
|
|
245
215
|
// Remove or make configurable?
|
|
246
|
-
this.HeaterCooler.ThresholdTemperature = 25
|
|
247
|
-
await this.debugLog(`CurrentMode: ${this.CurrentMode}
|
|
248
|
-
+ ` ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
|
|
216
|
+
this.HeaterCooler.ThresholdTemperature = 25
|
|
217
|
+
await this.debugLog(`CurrentMode: ${this.CurrentMode}, ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`)
|
|
249
218
|
}
|
|
250
|
-
const parameter = `${this.HeaterCooler.ThresholdTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}
|
|
219
|
+
const parameter = `${this.HeaterCooler.ThresholdTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`
|
|
251
220
|
|
|
252
|
-
await this.UpdateCurrentHeaterCoolerState()
|
|
221
|
+
await this.UpdateCurrentHeaterCoolerState()
|
|
253
222
|
const bodyChange = JSON.stringify({
|
|
254
223
|
command: 'setAll',
|
|
255
224
|
parameter: `${parameter}`,
|
|
256
225
|
commandType: 'command',
|
|
257
|
-
})
|
|
226
|
+
})
|
|
258
227
|
|
|
259
|
-
await this.pushChanges(bodyChange)
|
|
228
|
+
await this.pushChanges(bodyChange)
|
|
260
229
|
}
|
|
261
230
|
|
|
262
231
|
private async UpdateCurrentHeaterCoolerState() {
|
|
263
232
|
if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
264
|
-
|
|
265
233
|
if (this.HeaterCooler.Active === undefined) {
|
|
266
|
-
this.HeaterCooler.Active = this.hap.Characteristic.Active.INACTIVE
|
|
234
|
+
this.HeaterCooler.Active = this.hap.Characteristic.Active.INACTIVE
|
|
267
235
|
} else {
|
|
268
|
-
this.HeaterCooler.Active = this.HeaterCooler.Active ? this.HeaterCooler.Active : this.accessory.context.Active
|
|
236
|
+
this.HeaterCooler.Active = this.HeaterCooler.Active ? this.HeaterCooler.Active : this.accessory.context.Active
|
|
269
237
|
}
|
|
270
238
|
|
|
271
239
|
if (this.HeaterCooler.CurrentTemperature === undefined && this.accessory.context.CurrentTemperature === undefined) {
|
|
272
|
-
this.HeaterCooler.CurrentTemperature = 24
|
|
240
|
+
this.HeaterCooler.CurrentTemperature = 24
|
|
273
241
|
} else {
|
|
274
|
-
this.HeaterCooler.CurrentTemperature = this.HeaterCooler.CurrentTemperature || this.accessory.context.CurrentTemperature
|
|
242
|
+
this.HeaterCooler.CurrentTemperature = this.HeaterCooler.CurrentTemperature || this.accessory.context.CurrentTemperature
|
|
275
243
|
}
|
|
276
244
|
|
|
277
245
|
if (this.HeaterCooler.ThresholdTemperature === undefined && this.accessory.context.ThresholdTemperature === undefined) {
|
|
278
|
-
this.HeaterCooler.ThresholdTemperature = 24
|
|
246
|
+
this.HeaterCooler.ThresholdTemperature = 24
|
|
279
247
|
} else {
|
|
280
|
-
this.HeaterCooler.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature || this.accessory.context.ThresholdTemperature
|
|
248
|
+
this.HeaterCooler.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature || this.accessory.context.ThresholdTemperature
|
|
281
249
|
}
|
|
282
250
|
|
|
283
251
|
if (this.HeaterCooler.RotationSpeed === undefined && this.accessory.context.RotationSpeed === undefined) {
|
|
284
|
-
this.HeaterCooler.RotationSpeed = 4
|
|
252
|
+
this.HeaterCooler.RotationSpeed = 4
|
|
285
253
|
} else {
|
|
286
|
-
this.HeaterCooler.RotationSpeed = this.HeaterCooler.RotationSpeed || this.accessory.context.RotationSpeed
|
|
254
|
+
this.HeaterCooler.RotationSpeed = this.HeaterCooler.RotationSpeed || this.accessory.context.RotationSpeed
|
|
287
255
|
}
|
|
288
256
|
|
|
289
257
|
if (this.device.irair?.hide_automode) {
|
|
290
|
-
this.hide_automode = this.device.irair?.hide_automode
|
|
291
|
-
this.accessory.context.hide_automode = this.hide_automode
|
|
258
|
+
this.hide_automode = this.device.irair?.hide_automode
|
|
259
|
+
this.accessory.context.hide_automode = this.hide_automode
|
|
292
260
|
} else {
|
|
293
|
-
this.hide_automode = this.device.irair?.hide_automode
|
|
294
|
-
this.accessory.context.hide_automode = this.hide_automode
|
|
261
|
+
this.hide_automode = this.device.irair?.hide_automode
|
|
262
|
+
this.accessory.context.hide_automode = this.hide_automode
|
|
295
263
|
}
|
|
296
264
|
|
|
297
265
|
if (this.device.irair?.set_max_heat) {
|
|
298
|
-
this.set_max_heat = this.device.irair?.set_max_heat
|
|
299
|
-
this.accessory.context.set_max_heat = this.set_max_heat
|
|
266
|
+
this.set_max_heat = this.device.irair?.set_max_heat
|
|
267
|
+
this.accessory.context.set_max_heat = this.set_max_heat
|
|
300
268
|
} else {
|
|
301
|
-
this.set_max_heat = 35
|
|
302
|
-
this.accessory.context.set_max_heat = this.set_max_heat
|
|
269
|
+
this.set_max_heat = 35
|
|
270
|
+
this.accessory.context.set_max_heat = this.set_max_heat
|
|
303
271
|
}
|
|
304
272
|
if (this.device.irair?.set_min_heat) {
|
|
305
|
-
this.set_min_heat = this.device.irair?.set_min_heat
|
|
306
|
-
this.accessory.context.set_min_heat = this.set_min_heat
|
|
273
|
+
this.set_min_heat = this.device.irair?.set_min_heat
|
|
274
|
+
this.accessory.context.set_min_heat = this.set_min_heat
|
|
307
275
|
} else {
|
|
308
|
-
this.set_min_heat = 0
|
|
309
|
-
this.accessory.context.set_min_heat = this.set_min_heat
|
|
276
|
+
this.set_min_heat = 0
|
|
277
|
+
this.accessory.context.set_min_heat = this.set_min_heat
|
|
310
278
|
}
|
|
311
279
|
|
|
312
280
|
if (this.device.irair?.set_max_cool) {
|
|
313
|
-
this.set_max_cool = this.device.irair?.set_max_cool
|
|
314
|
-
this.accessory.context.set_max_cool = this.set_max_cool
|
|
281
|
+
this.set_max_cool = this.device.irair?.set_max_cool
|
|
282
|
+
this.accessory.context.set_max_cool = this.set_max_cool
|
|
315
283
|
} else {
|
|
316
|
-
this.set_max_cool = 35
|
|
317
|
-
this.accessory.context.set_max_cool = this.set_max_cool
|
|
284
|
+
this.set_max_cool = 35
|
|
285
|
+
this.accessory.context.set_max_cool = this.set_max_cool
|
|
318
286
|
}
|
|
319
287
|
if (this.device.irair?.set_min_cool) {
|
|
320
|
-
this.set_min_cool = this.device.irair?.set_min_cool
|
|
321
|
-
this.accessory.context.set_min_cool = this.set_min_cool
|
|
288
|
+
this.set_min_cool = this.device.irair?.set_min_cool
|
|
289
|
+
this.accessory.context.set_min_cool = this.set_min_cool
|
|
322
290
|
} else {
|
|
323
|
-
this.set_min_cool = 0
|
|
324
|
-
this.accessory.context.set_min_cool = this.set_min_cool
|
|
291
|
+
this.set_min_cool = 0
|
|
292
|
+
this.accessory.context.set_min_cool = this.set_min_cool
|
|
325
293
|
}
|
|
326
294
|
|
|
327
295
|
if (this.meter) {
|
|
328
296
|
if (this.HumiditySensor!.CurrentRelativeHumidity === undefined && this.accessory.context.CurrentRelativeHumidity === undefined) {
|
|
329
|
-
this.HumiditySensor!.CurrentRelativeHumidity = 0
|
|
297
|
+
this.HumiditySensor!.CurrentRelativeHumidity = 0
|
|
330
298
|
} else {
|
|
331
|
-
this.HumiditySensor!.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity
|
|
332
|
-
|| this.accessory.context.CurrentRelativeHumidity;
|
|
299
|
+
this.HumiditySensor!.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity ?? this.accessory.context.CurrentRelativeHumidity
|
|
333
300
|
}
|
|
334
301
|
}
|
|
335
|
-
if (this.HeaterCooler.ThresholdTemperature < this.HeaterCooler.CurrentTemperature
|
|
336
|
-
this.HeaterCooler.TargetHeaterCoolerState !== this.hap.Characteristic.TargetHeaterCoolerState.HEAT) {
|
|
337
|
-
this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING
|
|
338
|
-
} else if (this.HeaterCooler.ThresholdTemperature > this.HeaterCooler.CurrentTemperature &&
|
|
339
|
-
this.HeaterCooler.
|
|
340
|
-
this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.HEATING;
|
|
302
|
+
if (this.HeaterCooler.ThresholdTemperature < this.HeaterCooler.CurrentTemperature
|
|
303
|
+
&& this.HeaterCooler.TargetHeaterCoolerState !== this.hap.Characteristic.TargetHeaterCoolerState.HEAT) {
|
|
304
|
+
this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING
|
|
305
|
+
} else if (this.HeaterCooler.ThresholdTemperature > this.HeaterCooler.CurrentTemperature && this.HeaterCooler.TargetHeaterCoolerState !== this.hap.Characteristic.TargetHeaterCoolerState.COOL) {
|
|
306
|
+
this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.HEATING
|
|
341
307
|
} else {
|
|
342
|
-
this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE
|
|
308
|
+
this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE
|
|
343
309
|
}
|
|
344
310
|
} else {
|
|
345
|
-
this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE
|
|
311
|
+
this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE
|
|
346
312
|
}
|
|
347
313
|
}
|
|
348
314
|
|
|
349
315
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
350
|
-
await this.debugLog('pushChanges')
|
|
316
|
+
await this.debugLog('pushChanges')
|
|
351
317
|
if (this.device.connectionType === 'OpenAPI' && !this.disablePushDetail) {
|
|
352
|
-
await this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
318
|
+
await this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
353
319
|
try {
|
|
354
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
355
|
-
const deviceStatus: any = await body.json()
|
|
356
|
-
await this.pushStatusCodes(statusCode, deviceStatus)
|
|
320
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
321
|
+
const deviceStatus: any = await body.json()
|
|
322
|
+
await this.pushStatusCodes(statusCode, deviceStatus)
|
|
357
323
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
358
|
-
await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
|
|
359
|
-
await this.updateHomeKitCharacteristics()
|
|
324
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
|
|
325
|
+
await this.updateHomeKitCharacteristics()
|
|
360
326
|
} else {
|
|
361
|
-
await this.statusCode(statusCode)
|
|
362
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
327
|
+
await this.statusCode(statusCode)
|
|
328
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
363
329
|
}
|
|
364
330
|
} catch (e: any) {
|
|
365
|
-
await this.apiError(e)
|
|
366
|
-
await this.pushChangeError(e)
|
|
331
|
+
await this.apiError(e)
|
|
332
|
+
await this.pushChangeError(e)
|
|
367
333
|
}
|
|
368
334
|
} else {
|
|
369
|
-
await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`)
|
|
370
|
-
await this.debugLog(`Connection Type: ${this.device.connectionType}, disablePushDetails: ${this.disablePushDetail}`)
|
|
371
|
-
await this.updateHomeKitCharacteristics()
|
|
335
|
+
await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`)
|
|
336
|
+
await this.debugLog(`Connection Type: ${this.device.connectionType}, disablePushDetails: ${this.disablePushDetail}`)
|
|
337
|
+
await this.updateHomeKitCharacteristics()
|
|
372
338
|
}
|
|
373
339
|
}
|
|
374
340
|
|
|
375
341
|
async CurrentTemperatureGet(): Promise<CharacteristicValue> {
|
|
376
342
|
if (this.meter?.context?.CurrentTemperature) {
|
|
377
|
-
this.accessory.context.CurrentTemperature = this.meter.context.CurrentTemperature
|
|
378
|
-
await this.debugLog(
|
|
379
|
-
+ `Using CurrentTemperature from ${this.meter.context.deviceType} (${this.meter.context.deviceId})`);
|
|
343
|
+
this.accessory.context.CurrentTemperature = this.meter.context.CurrentTemperature
|
|
344
|
+
await this.debugLog(`Using CurrentTemperature from ${this.meter.context.deviceType} (${this.meter.context.deviceId})`)
|
|
380
345
|
}
|
|
381
346
|
|
|
382
|
-
this.HeaterCooler.CurrentTemperature = this.accessory.context.CurrentTemperature || 24
|
|
383
|
-
await this.debugLog(`Get CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`)
|
|
384
|
-
return this.HeaterCooler.CurrentTemperature
|
|
347
|
+
this.HeaterCooler.CurrentTemperature = this.accessory.context.CurrentTemperature || 24
|
|
348
|
+
await this.debugLog(`Get CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`)
|
|
349
|
+
return this.HeaterCooler.CurrentTemperature
|
|
385
350
|
}
|
|
386
351
|
|
|
387
352
|
async CurrentRelativeHumidityGet(): Promise<CharacteristicValue> {
|
|
388
353
|
if (this.meter?.context?.CurrentRelativeHumidity) {
|
|
389
|
-
this.accessory.context.CurrentRelativeHumidity = this.meter.context.CurrentRelativeHumidity
|
|
390
|
-
await this.debugLog(
|
|
391
|
-
+ `Using CurrentRelativeHumidity from ${this.meter.context.deviceType} (${this.meter.context.deviceId})`);
|
|
354
|
+
this.accessory.context.CurrentRelativeHumidity = this.meter.context.CurrentRelativeHumidity
|
|
355
|
+
await this.debugLog(`Using CurrentRelativeHumidity from ${this.meter.context.deviceType} (${this.meter.context.deviceId})`)
|
|
392
356
|
}
|
|
393
357
|
|
|
394
|
-
this.HumiditySensor!.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity || 0
|
|
395
|
-
await this.debugLog(
|
|
396
|
-
|
|
397
|
-
return this.HumiditySensor!.CurrentRelativeHumidity as CharacteristicValue;
|
|
358
|
+
this.HumiditySensor!.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity || 0
|
|
359
|
+
await this.debugLog(`Get CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`)
|
|
360
|
+
return this.HumiditySensor!.CurrentRelativeHumidity as CharacteristicValue
|
|
398
361
|
}
|
|
399
362
|
|
|
400
363
|
async RotationSpeedGet(): Promise<number> {
|
|
401
364
|
if (!this.CurrentFanSpeed || this.CurrentFanSpeed === 1) {
|
|
402
|
-
this.HeaterCooler.RotationSpeed = 4
|
|
365
|
+
this.HeaterCooler.RotationSpeed = 4
|
|
403
366
|
} else {
|
|
404
|
-
this.HeaterCooler.RotationSpeed = this.CurrentFanSpeed - 1
|
|
367
|
+
this.HeaterCooler.RotationSpeed = this.CurrentFanSpeed - 1
|
|
405
368
|
}
|
|
406
|
-
await this.debugLog(`Get RotationSpeed: ${this.HeaterCooler.RotationSpeed}`)
|
|
407
|
-
return this.HeaterCooler.RotationSpeed
|
|
369
|
+
await this.debugLog(`Get RotationSpeed: ${this.HeaterCooler.RotationSpeed}`)
|
|
370
|
+
return this.HeaterCooler.RotationSpeed
|
|
408
371
|
}
|
|
409
372
|
|
|
410
373
|
async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
|
|
411
374
|
if (value === 4) {
|
|
412
|
-
this.CurrentFanSpeed = 1
|
|
375
|
+
this.CurrentFanSpeed = 1
|
|
413
376
|
} else {
|
|
414
|
-
this.CurrentFanSpeed = Number(value) + 1
|
|
377
|
+
this.CurrentFanSpeed = Number(value) + 1
|
|
415
378
|
}
|
|
416
|
-
this.HeaterCooler.RotationSpeed = value
|
|
417
|
-
await this.debugLog(`Set RotationSpeed: ${this.HeaterCooler.RotationSpeed}, CurrentFanSpeed: ${this.CurrentFanSpeed}`)
|
|
418
|
-
this.pushAirConditionerStatusChanges()
|
|
379
|
+
this.HeaterCooler.RotationSpeed = value
|
|
380
|
+
await this.debugLog(`Set RotationSpeed: ${this.HeaterCooler.RotationSpeed}, CurrentFanSpeed: ${this.CurrentFanSpeed}`)
|
|
381
|
+
this.pushAirConditionerStatusChanges()
|
|
419
382
|
}
|
|
420
383
|
|
|
421
384
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
422
|
-
await this.debugLog(`Set Active: ${value}`)
|
|
385
|
+
await this.debugLog(`Set Active: ${value}`)
|
|
423
386
|
|
|
424
|
-
this.HeaterCooler.Active = value
|
|
387
|
+
this.HeaterCooler.Active = value
|
|
425
388
|
if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
426
|
-
await this.debugLog(`pushAirConditionerOnChanges, Active: ${this.HeaterCooler.Active}`)
|
|
389
|
+
await this.debugLog(`pushAirConditionerOnChanges, Active: ${this.HeaterCooler.Active}`)
|
|
427
390
|
if (this.disablePushOn) {
|
|
428
|
-
this.pushAirConditionerStatusChanges()
|
|
391
|
+
this.pushAirConditionerStatusChanges()
|
|
429
392
|
} else {
|
|
430
|
-
this.pushAirConditionerOnChanges()
|
|
393
|
+
this.pushAirConditionerOnChanges()
|
|
431
394
|
}
|
|
432
395
|
} else {
|
|
433
|
-
await this.debugLog(`pushAirConditionerOffChanges, Active: ${this.HeaterCooler.Active}`)
|
|
434
|
-
this.pushAirConditionerOffChanges()
|
|
396
|
+
await this.debugLog(`pushAirConditionerOffChanges, Active: ${this.HeaterCooler.Active}`)
|
|
397
|
+
this.pushAirConditionerOffChanges()
|
|
435
398
|
}
|
|
436
399
|
}
|
|
437
400
|
|
|
438
401
|
async TargetHeaterCoolerStateGet(): Promise<CharacteristicValue> {
|
|
439
|
-
const targetState = this.HeaterCooler.TargetHeaterCoolerState || this.accessory.context.TargetHeaterCoolerState
|
|
440
|
-
this.HeaterCooler.TargetHeaterCoolerState = this.ValidValues.includes(targetState) ? targetState : this.ValidValues[0]
|
|
441
|
-
await this.debugLog(`Get (${this.getTargetHeaterCoolerStateName()}) TargetHeaterCoolerState
|
|
442
|
-
|
|
443
|
-
return this.HeaterCooler.TargetHeaterCoolerState;
|
|
402
|
+
const targetState = this.HeaterCooler.TargetHeaterCoolerState || this.accessory.context.TargetHeaterCoolerState
|
|
403
|
+
this.HeaterCooler.TargetHeaterCoolerState = this.ValidValues.includes(targetState) ? targetState : this.ValidValues[0]
|
|
404
|
+
await this.debugLog(`Get (${this.getTargetHeaterCoolerStateName()}) TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}, ValidValues: ${this.ValidValues}, hide_automode: ${this.hide_automode}`)
|
|
405
|
+
return this.HeaterCooler.TargetHeaterCoolerState
|
|
444
406
|
}
|
|
445
407
|
|
|
446
408
|
async TargetHeaterCoolerStateSet(value: CharacteristicValue): Promise<void> {
|
|
447
409
|
if (!this.hide_automode && value === this.hap.Characteristic.TargetHeaterCoolerState.AUTO) {
|
|
448
|
-
this.TargetHeaterCoolerStateAUTO()
|
|
410
|
+
this.TargetHeaterCoolerStateAUTO()
|
|
449
411
|
} else if (value === this.hap.Characteristic.TargetHeaterCoolerState.HEAT) {
|
|
450
|
-
this.TargetHeaterCoolerStateHEAT()
|
|
412
|
+
this.TargetHeaterCoolerStateHEAT()
|
|
451
413
|
} else if (value === this.hap.Characteristic.TargetHeaterCoolerState.COOL) {
|
|
452
|
-
this.TargetHeaterCoolerStateCOOL()
|
|
414
|
+
this.TargetHeaterCoolerStateCOOL()
|
|
453
415
|
} else {
|
|
454
|
-
this.errorLog(
|
|
455
|
-
+ `${this.HeaterCooler.TargetHeaterCoolerState}, hide_automode: ${this.hide_automode} `);
|
|
416
|
+
this.errorLog(`Set TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}, hide_automode: ${this.hide_automode} `)
|
|
456
417
|
}
|
|
457
|
-
this.pushAirConditionerStatusChanges()
|
|
418
|
+
this.pushAirConditionerStatusChanges()
|
|
458
419
|
}
|
|
459
420
|
|
|
460
421
|
async TargetHeaterCoolerStateAUTO(): Promise<void> {
|
|
461
|
-
this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.AUTO
|
|
462
|
-
this.CurrentMode = 1
|
|
463
|
-
await this.debugLog(
|
|
464
|
-
|
|
465
|
-
await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`);
|
|
422
|
+
this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.AUTO
|
|
423
|
+
this.CurrentMode = 1
|
|
424
|
+
await this.debugLog(`Set (AUTO) TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`)
|
|
425
|
+
await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`)
|
|
466
426
|
}
|
|
467
427
|
|
|
468
428
|
async TargetHeaterCoolerStateCOOL(): Promise<void> {
|
|
469
|
-
this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.COOL
|
|
470
|
-
this.CurrentMode = 2
|
|
471
|
-
await this.debugLog(
|
|
472
|
-
|
|
473
|
-
await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`);
|
|
429
|
+
this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.COOL
|
|
430
|
+
this.CurrentMode = 2
|
|
431
|
+
await this.debugLog(`Set (COOL) TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`)
|
|
432
|
+
await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`)
|
|
474
433
|
}
|
|
475
434
|
|
|
476
435
|
async TargetHeaterCoolerStateHEAT(): Promise<void> {
|
|
477
|
-
this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.HEAT
|
|
478
|
-
this.CurrentMode = 5
|
|
479
|
-
await this.debugLog(
|
|
480
|
-
|
|
481
|
-
await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`);
|
|
436
|
+
this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.HEAT
|
|
437
|
+
this.CurrentMode = 5
|
|
438
|
+
await this.debugLog(`Set (HEAT) TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`)
|
|
439
|
+
await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`)
|
|
482
440
|
}
|
|
483
441
|
|
|
484
442
|
async CurrentHeaterCoolerStateGet(): Promise<CharacteristicValue> {
|
|
485
|
-
await this.UpdateCurrentHeaterCoolerState()
|
|
486
|
-
await this.debugLog(`Get (${this.getTargetHeaterCoolerStateName()}) CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`)
|
|
443
|
+
await this.UpdateCurrentHeaterCoolerState()
|
|
444
|
+
await this.debugLog(`Get (${this.getTargetHeaterCoolerStateName()}) CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`)
|
|
487
445
|
|
|
488
|
-
return this.HeaterCooler.CurrentHeaterCoolerState
|
|
446
|
+
return this.HeaterCooler.CurrentHeaterCoolerState
|
|
489
447
|
}
|
|
490
448
|
|
|
491
|
-
|
|
492
449
|
private getTargetHeaterCoolerStateName(): string {
|
|
493
450
|
switch (this.HeaterCooler.TargetHeaterCoolerState) {
|
|
494
451
|
case this.hap.Characteristic.TargetHeaterCoolerState.AUTO:
|
|
495
|
-
return 'AUTO'
|
|
452
|
+
return 'AUTO'
|
|
496
453
|
case this.hap.Characteristic.TargetHeaterCoolerState.HEAT:
|
|
497
|
-
return 'HEAT'
|
|
454
|
+
return 'HEAT'
|
|
498
455
|
case this.hap.Characteristic.TargetHeaterCoolerState.COOL:
|
|
499
|
-
return 'COOL'
|
|
456
|
+
return 'COOL'
|
|
500
457
|
default:
|
|
501
|
-
return this.HeaterCooler.TargetHeaterCoolerState.toString()
|
|
458
|
+
return this.HeaterCooler.TargetHeaterCoolerState.toString()
|
|
502
459
|
}
|
|
503
460
|
}
|
|
504
461
|
|
|
505
462
|
async ThresholdTemperatureGet(): Promise<CharacteristicValue> {
|
|
506
|
-
this.HeaterCooler.Active = this.HeaterCooler.Active === undefined
|
|
507
|
-
|
|
463
|
+
this.HeaterCooler.Active = this.HeaterCooler.Active === undefined
|
|
464
|
+
? this.hap.Characteristic.Active.INACTIVE
|
|
465
|
+
: this.HeaterCooler.Active ?? this.accessory.context.Active
|
|
508
466
|
|
|
509
|
-
this.HeaterCooler.CurrentTemperature = (this.HeaterCooler.CurrentTemperature === undefined
|
|
510
|
-
|
|
511
|
-
?? this.accessory.context.CurrentTemperature
|
|
467
|
+
this.HeaterCooler.CurrentTemperature = (this.HeaterCooler.CurrentTemperature === undefined && this.accessory.context.CurrentTemperature === undefined)
|
|
468
|
+
? 24
|
|
469
|
+
: this.HeaterCooler.CurrentTemperature ?? this.accessory.context.CurrentTemperature
|
|
512
470
|
|
|
513
|
-
this.HeaterCooler.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature === undefined
|
|
514
|
-
|
|
471
|
+
this.HeaterCooler.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature === undefined
|
|
472
|
+
? 24
|
|
473
|
+
: this.HeaterCooler.ThresholdTemperature ?? this.accessory.context.ThresholdTemperature
|
|
515
474
|
|
|
516
|
-
this.HeaterCooler.RotationSpeed = (this.HeaterCooler.RotationSpeed === undefined && this.accessory.context.RotationSpeed === undefined)
|
|
517
|
-
|
|
475
|
+
this.HeaterCooler.RotationSpeed = (this.HeaterCooler.RotationSpeed === undefined && this.accessory.context.RotationSpeed === undefined)
|
|
476
|
+
? 4
|
|
477
|
+
: this.HeaterCooler.RotationSpeed ?? this.accessory.context.RotationSpeed
|
|
518
478
|
|
|
519
|
-
await this.getAirConditionerConfigSettings(this.accessory, this.device)
|
|
479
|
+
await this.getAirConditionerConfigSettings(this.accessory, this.device)
|
|
520
480
|
|
|
521
481
|
if (this.meter && this.HumiditySensor?.Service) {
|
|
522
|
-
this.HumiditySensor.CurrentRelativeHumidity = (this.HumiditySensor.CurrentRelativeHumidity === undefined
|
|
523
|
-
|
|
524
|
-
?? this.accessory.context.CurrentRelativeHumidity
|
|
482
|
+
this.HumiditySensor.CurrentRelativeHumidity = (this.HumiditySensor.CurrentRelativeHumidity === undefined && this.accessory.context.CurrentRelativeHumidity === undefined)
|
|
483
|
+
? 0
|
|
484
|
+
: this.HumiditySensor.CurrentRelativeHumidity ?? this.accessory.context.CurrentRelativeHumidity
|
|
525
485
|
}
|
|
526
|
-
await this.debugLog(`Get ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`)
|
|
527
|
-
return this.HeaterCooler.ThresholdTemperature
|
|
486
|
+
await this.debugLog(`Get ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`)
|
|
487
|
+
return this.HeaterCooler.ThresholdTemperature
|
|
528
488
|
}
|
|
529
489
|
|
|
530
490
|
async ThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
531
|
-
this.HeaterCooler.ThresholdTemperature = value
|
|
532
|
-
await this.debugLog(`Set ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}
|
|
533
|
-
|
|
534
|
-
this.pushAirConditionerStatusChanges();
|
|
491
|
+
this.HeaterCooler.ThresholdTemperature = value
|
|
492
|
+
await this.debugLog(`Set ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}, ThresholdTemperatureCached: ${this.accessory.context.ThresholdTemperature}`)
|
|
493
|
+
this.pushAirConditionerStatusChanges()
|
|
535
494
|
}
|
|
536
495
|
|
|
537
496
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
538
|
-
await this.debugLog('updateHomeKitCharacteristics')
|
|
497
|
+
await this.debugLog('updateHomeKitCharacteristics')
|
|
539
498
|
// Active
|
|
540
|
-
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.Active,
|
|
541
|
-
this.HeaterCooler.Active, 'Active');
|
|
499
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.Active, this.HeaterCooler.Active, 'Active')
|
|
542
500
|
// RotationSpeed
|
|
543
|
-
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.RotationSpeed,
|
|
544
|
-
this.HeaterCooler.RotationSpeed, 'RotationSpeed');
|
|
501
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.RotationSpeed, this.HeaterCooler.RotationSpeed, 'RotationSpeed')
|
|
545
502
|
// CurrentTemperature
|
|
546
|
-
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CurrentTemperature,
|
|
547
|
-
this.HeaterCooler.CurrentTemperature, 'CurrentTemperature');
|
|
503
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CurrentTemperature, this.HeaterCooler.CurrentTemperature, 'CurrentTemperature')
|
|
548
504
|
// TargetHeaterCoolerState
|
|
549
|
-
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.TargetHeaterCoolerState,
|
|
550
|
-
this.HeaterCooler.TargetHeaterCoolerState, 'TargetHeaterCoolerState');
|
|
505
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.TargetHeaterCoolerState, this.HeaterCooler.TargetHeaterCoolerState, 'TargetHeaterCoolerState')
|
|
551
506
|
// CurrentHeaterCoolerState
|
|
552
|
-
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CurrentHeaterCoolerState,
|
|
553
|
-
this.HeaterCooler.CurrentHeaterCoolerState, 'CurrentHeaterCoolerState');
|
|
507
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CurrentHeaterCoolerState, this.HeaterCooler.CurrentHeaterCoolerState, 'CurrentHeaterCoolerState')
|
|
554
508
|
// HeatingThresholdTemperature
|
|
555
|
-
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.HeatingThresholdTemperature,
|
|
556
|
-
this.HeaterCooler.ThresholdTemperature, 'ThresholdTemperature');
|
|
509
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.HeatingThresholdTemperature, this.HeaterCooler.ThresholdTemperature, 'ThresholdTemperature')
|
|
557
510
|
// CoolingThresholdTemperature
|
|
558
|
-
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CoolingThresholdTemperature,
|
|
559
|
-
this.HeaterCooler.ThresholdTemperature, 'ThresholdTemperature');
|
|
511
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CoolingThresholdTemperature, this.HeaterCooler.ThresholdTemperature, 'ThresholdTemperature')
|
|
560
512
|
if (this.meter && this.HumiditySensor?.Service) {
|
|
561
513
|
// CurrentRelativeHumidity
|
|
562
|
-
await this.updateCharacteristic(this.HumiditySensor.Service, this.hap.Characteristic.CurrentRelativeHumidity,
|
|
563
|
-
this.HumiditySensor.CurrentRelativeHumidity, 'CurrentRelativeHumidity');
|
|
514
|
+
await this.updateCharacteristic(this.HumiditySensor.Service, this.hap.Characteristic.CurrentRelativeHumidity, this.HumiditySensor.CurrentRelativeHumidity, 'CurrentRelativeHumidity')
|
|
564
515
|
}
|
|
565
516
|
}
|
|
566
517
|
|
|
567
518
|
async apiError(e: any): Promise<void> {
|
|
568
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.Active, e)
|
|
569
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e)
|
|
570
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e)
|
|
571
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e)
|
|
572
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState, e)
|
|
573
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, e)
|
|
574
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature, e)
|
|
575
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature, e)
|
|
519
|
+
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.Active, e)
|
|
520
|
+
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e)
|
|
521
|
+
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e)
|
|
522
|
+
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e)
|
|
523
|
+
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState, e)
|
|
524
|
+
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, e)
|
|
525
|
+
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature, e)
|
|
526
|
+
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature, e)
|
|
576
527
|
}
|
|
577
528
|
|
|
578
529
|
async getAirConditionerConfigSettings(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): Promise<void> {
|
|
579
|
-
accessory.context.hide_automode = this.hide_automode = device.irair?.hide_automode
|
|
580
|
-
accessory.context.set_max_heat = this.set_max_heat = device.irair?.set_max_heat ?? 35
|
|
581
|
-
accessory.context.set_min_heat = this.set_min_heat = device.irair?.set_min_heat ?? 0
|
|
582
|
-
accessory.context.set_max_cool = this.set_max_cool = device.irair?.set_max_cool ?? 35
|
|
583
|
-
accessory.context.set_min_cool = this.set_min_cool = device.irair?.set_min_cool ?? 0
|
|
530
|
+
accessory.context.hide_automode = this.hide_automode = device.irair?.hide_automode
|
|
531
|
+
accessory.context.set_max_heat = this.set_max_heat = device.irair?.set_max_heat ?? 35
|
|
532
|
+
accessory.context.set_min_heat = this.set_min_heat = device.irair?.set_min_heat ?? 0
|
|
533
|
+
accessory.context.set_max_cool = this.set_max_cool = device.irair?.set_max_cool ?? 35
|
|
534
|
+
accessory.context.set_min_cool = this.set_min_cool = device.irair?.set_min_cool ?? 0
|
|
584
535
|
}
|
|
585
536
|
}
|