@switchbot/homebridge-switchbot 3.7.1-beta.2 → 3.7.1-beta.21

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.
Files changed (199) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +14 -0
  3. package/assets/security-privacy-bluetooth.png +0 -0
  4. package/config.schema.json +74 -2
  5. package/dist/device/blindtilt.d.ts +21 -9
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +167 -96
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot-old.d.ts +132 -0
  10. package/dist/device/bot-old.d.ts.map +1 -0
  11. package/dist/device/bot-old.js +1482 -0
  12. package/dist/device/bot-old.js.map +1 -0
  13. package/dist/device/bot.d.ts +10 -9
  14. package/dist/device/bot.d.ts.map +1 -1
  15. package/dist/device/bot.js +186 -187
  16. package/dist/device/bot.js.map +1 -1
  17. package/dist/device/ceilinglight.d.ts +14 -13
  18. package/dist/device/ceilinglight.d.ts.map +1 -1
  19. package/dist/device/ceilinglight.js +87 -97
  20. package/dist/device/ceilinglight.js.map +1 -1
  21. package/dist/device/colorbulb.d.ts +13 -12
  22. package/dist/device/colorbulb.d.ts.map +1 -1
  23. package/dist/device/colorbulb.js +92 -105
  24. package/dist/device/colorbulb.js.map +1 -1
  25. package/dist/device/contact.d.ts +6 -5
  26. package/dist/device/contact.d.ts.map +1 -1
  27. package/dist/device/contact.js +71 -68
  28. package/dist/device/contact.js.map +1 -1
  29. package/dist/device/curtain.d.ts +17 -5
  30. package/dist/device/curtain.d.ts.map +1 -1
  31. package/dist/device/curtain.js +184 -118
  32. package/dist/device/curtain.js.map +1 -1
  33. package/dist/device/device.d.ts +18 -18
  34. package/dist/device/device.d.ts.map +1 -1
  35. package/dist/device/device.js +33 -36
  36. package/dist/device/device.js.map +1 -1
  37. package/dist/device/fan.d.ts +9 -8
  38. package/dist/device/fan.d.ts.map +1 -1
  39. package/dist/device/fan.js +94 -101
  40. package/dist/device/fan.js.map +1 -1
  41. package/dist/device/hub.d.ts +6 -5
  42. package/dist/device/hub.d.ts.map +1 -1
  43. package/dist/device/hub.js +69 -65
  44. package/dist/device/hub.js.map +1 -1
  45. package/dist/device/humidifier.d.ts +6 -5
  46. package/dist/device/humidifier.d.ts.map +1 -1
  47. package/dist/device/humidifier.js +89 -104
  48. package/dist/device/humidifier.js.map +1 -1
  49. package/dist/device/iosensor.d.ts +6 -5
  50. package/dist/device/iosensor.d.ts.map +1 -1
  51. package/dist/device/iosensor.js +72 -66
  52. package/dist/device/iosensor.js.map +1 -1
  53. package/dist/device/lightstrip.d.ts +7 -6
  54. package/dist/device/lightstrip.d.ts.map +1 -1
  55. package/dist/device/lightstrip.js +85 -99
  56. package/dist/device/lightstrip.js.map +1 -1
  57. package/dist/device/lock.d.ts +10 -9
  58. package/dist/device/lock.d.ts.map +1 -1
  59. package/dist/device/lock.js +89 -79
  60. package/dist/device/lock.js.map +1 -1
  61. package/dist/device/meter.d.ts +6 -5
  62. package/dist/device/meter.d.ts.map +1 -1
  63. package/dist/device/meter.js +72 -65
  64. package/dist/device/meter.js.map +1 -1
  65. package/dist/device/meterplus.d.ts +6 -5
  66. package/dist/device/meterplus.d.ts.map +1 -1
  67. package/dist/device/meterplus.js +72 -64
  68. package/dist/device/meterplus.js.map +1 -1
  69. package/dist/device/motion.d.ts +6 -5
  70. package/dist/device/motion.d.ts.map +1 -1
  71. package/dist/device/motion.js +65 -58
  72. package/dist/device/motion.js.map +1 -1
  73. package/dist/device/plug.d.ts +13 -12
  74. package/dist/device/plug.d.ts.map +1 -1
  75. package/dist/device/plug.js +68 -52
  76. package/dist/device/plug.js.map +1 -1
  77. package/dist/device/robotvacuumcleaner.d.ts +12 -11
  78. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  79. package/dist/device/robotvacuumcleaner.js +93 -82
  80. package/dist/device/robotvacuumcleaner.js.map +1 -1
  81. package/dist/device/waterdetector.d.ts +6 -5
  82. package/dist/device/waterdetector.d.ts.map +1 -1
  83. package/dist/device/waterdetector.js +73 -63
  84. package/dist/device/waterdetector.js.map +1 -1
  85. package/dist/homebridge-ui/server.js +2 -2
  86. package/dist/homebridge-ui/server.js.map +1 -1
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +0 -4
  89. package/dist/index.js.map +1 -1
  90. package/dist/irdevice/airconditioner.d.ts +8 -8
  91. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  92. package/dist/irdevice/airconditioner.js +61 -105
  93. package/dist/irdevice/airconditioner.js.map +1 -1
  94. package/dist/irdevice/airpurifier.d.ts +10 -10
  95. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  96. package/dist/irdevice/airpurifier.js +22 -42
  97. package/dist/irdevice/airpurifier.js.map +1 -1
  98. package/dist/irdevice/camera.d.ts +9 -9
  99. package/dist/irdevice/camera.d.ts.map +1 -1
  100. package/dist/irdevice/camera.js +15 -25
  101. package/dist/irdevice/camera.js.map +1 -1
  102. package/dist/irdevice/fan.d.ts +8 -8
  103. package/dist/irdevice/fan.d.ts.map +1 -1
  104. package/dist/irdevice/fan.js +21 -40
  105. package/dist/irdevice/fan.js.map +1 -1
  106. package/dist/irdevice/irdevice.d.ts +11 -11
  107. package/dist/irdevice/irdevice.d.ts.map +1 -1
  108. package/dist/irdevice/irdevice.js +14 -22
  109. package/dist/irdevice/irdevice.js.map +1 -1
  110. package/dist/irdevice/light.d.ts +9 -9
  111. package/dist/irdevice/light.d.ts.map +1 -1
  112. package/dist/irdevice/light.js +24 -47
  113. package/dist/irdevice/light.js.map +1 -1
  114. package/dist/irdevice/other.d.ts +9 -9
  115. package/dist/irdevice/other.d.ts.map +1 -1
  116. package/dist/irdevice/other.js +40 -83
  117. package/dist/irdevice/other.js.map +1 -1
  118. package/dist/irdevice/tv.d.ts +9 -9
  119. package/dist/irdevice/tv.d.ts.map +1 -1
  120. package/dist/irdevice/tv.js +29 -54
  121. package/dist/irdevice/tv.js.map +1 -1
  122. package/dist/irdevice/vacuumcleaner.d.ts +5 -5
  123. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  124. package/dist/irdevice/vacuumcleaner.js +11 -21
  125. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  126. package/dist/irdevice/waterheater.d.ts +5 -5
  127. package/dist/irdevice/waterheater.d.ts.map +1 -1
  128. package/dist/irdevice/waterheater.js +11 -22
  129. package/dist/irdevice/waterheater.js.map +1 -1
  130. package/dist/platform.d.ts +24 -23
  131. package/dist/platform.d.ts.map +1 -1
  132. package/dist/platform.js +509 -723
  133. package/dist/platform.js.map +1 -1
  134. package/dist/settings.d.ts +5 -2
  135. package/dist/settings.d.ts.map +1 -1
  136. package/dist/settings.js.map +1 -1
  137. package/dist/types/bledevicestatus.d.ts +9 -9
  138. package/dist/types/bledevicestatus.d.ts.map +1 -1
  139. package/dist/types/devicelist.d.ts +6 -6
  140. package/dist/types/devicelist.d.ts.map +1 -1
  141. package/dist/types/deviceresponse.d.ts +4 -4
  142. package/dist/types/deviceresponse.d.ts.map +1 -1
  143. package/dist/types/devicestatus.d.ts +2 -2
  144. package/dist/types/devicestatus.d.ts.map +1 -1
  145. package/dist/types/devicewebhookstatus.d.ts +5 -5
  146. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  147. package/dist/types/irdevicelist.d.ts +4 -4
  148. package/dist/types/irdevicelist.d.ts.map +1 -1
  149. package/dist/types/pushbody.d.ts +2 -2
  150. package/dist/types/pushbody.d.ts.map +1 -1
  151. package/dist/utils.d.ts +4 -4
  152. package/dist/utils.d.ts.map +1 -1
  153. package/dist/utils.js +9 -13
  154. package/dist/utils.js.map +1 -1
  155. package/eslint.config.js +48 -93
  156. package/package.json +64 -57
  157. package/src/device/blindtilt.ts +537 -456
  158. package/src/device/bot-old.ts +1540 -0
  159. package/src/device/bot.ts +732 -725
  160. package/src/device/ceilinglight.ts +359 -368
  161. package/src/device/colorbulb.ts +441 -453
  162. package/src/device/contact.ts +229 -226
  163. package/src/device/curtain.ts +526 -444
  164. package/src/device/device.ts +206 -208
  165. package/src/device/fan.ts +336 -345
  166. package/src/device/hub.ts +213 -214
  167. package/src/device/humidifier.ts +326 -347
  168. package/src/device/iosensor.ts +211 -209
  169. package/src/device/lightstrip.ts +391 -404
  170. package/src/device/lock.ts +292 -282
  171. package/src/device/meter.ts +212 -210
  172. package/src/device/meterplus.ts +212 -209
  173. package/src/device/motion.ts +198 -190
  174. package/src/device/plug.ts +203 -182
  175. package/src/device/robotvacuumcleaner.ts +280 -269
  176. package/src/device/waterdetector.ts +198 -189
  177. package/src/homebridge-ui/server.ts +16 -15
  178. package/src/index.ts +5 -6
  179. package/src/irdevice/airconditioner.ts +277 -326
  180. package/src/irdevice/airpurifier.ts +124 -143
  181. package/src/irdevice/camera.ts +58 -64
  182. package/src/irdevice/fan.ts +106 -123
  183. package/src/irdevice/irdevice.ts +116 -119
  184. package/src/irdevice/light.ts +119 -143
  185. package/src/irdevice/other.ts +417 -461
  186. package/src/irdevice/tv.ts +155 -177
  187. package/src/irdevice/vacuumcleaner.ts +54 -60
  188. package/src/irdevice/waterheater.ts +56 -63
  189. package/src/platform.ts +1491 -1681
  190. package/src/settings.ts +172 -169
  191. package/src/types/bledevicestatus.ts +252 -256
  192. package/src/types/devicelist.ts +79 -79
  193. package/src/types/deviceresponse.ts +12 -13
  194. package/src/types/devicestatus.ts +124 -124
  195. package/src/types/devicewebhookstatus.ts +126 -131
  196. package/src/types/irdevicelist.ts +10 -10
  197. package/src/types/pushbody.ts +5 -5
  198. package/src/utils.ts +64 -65
  199. package/tsconfig.json +10 -9
@@ -2,12 +2,13 @@
2
2
  *
3
3
  * airconditioners.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
- import { irdeviceBase } from './irdevice.js';
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
- import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
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
- .setCharacteristic(this.hap.Characteristic.Name, this.HeaterCooler.Name)
83
- .getCharacteristic(this.hap.Characteristic.Active)
84
- .onGet(() => {
85
- return this.HeaterCooler.Active;
86
- })
87
- .onSet(this.ActiveSet.bind(this));
88
-
89
- this.HeaterCooler.Service
90
- .getCharacteristic(this.hap.Characteristic.CurrentTemperature)
91
- .onGet(async () => {
92
- return await this.CurrentTemperatureGet();
93
- });
94
-
95
- this.HeaterCooler.Service
96
- .getCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState)
97
- .setProps({
98
- validValues: this.ValidValues,
99
- })
100
- .onGet(async () => {
101
- return await this.TargetHeaterCoolerStateGet();
102
- })
103
- .onSet(this.TargetHeaterCoolerStateSet.bind(this));
104
-
105
- this.HeaterCooler.Service
106
- .getCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState)
107
- .onGet(async () => {
108
- return await this.CurrentHeaterCoolerStateGet();
109
- });
110
-
111
- this.HeaterCooler.Service
112
- .getCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature)
113
- .setProps({
114
- minValue: this.set_min_heat,
115
- maxValue: this.set_max_heat,
116
- minStep: 0.5,
117
- })
118
- .onGet(async () => {
119
- return await this.ThresholdTemperatureGet();
120
- })
121
- .onSet(this.ThresholdTemperatureSet.bind(this));
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((accessory) => accessory.UUID === meterUuid);
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((accessory) => accessory.UUID === meterUuid);
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
- .setCharacteristic(this.hap.Characteristic.Name, this.HumiditySensor.Name)
170
- .getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
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 commandType Command command parameter Description
180
- * AirConditioner: "command" "swing" "default" = swing
181
- * AirConditioner: "command" "timer" "default" = timer
182
- * AirConditioner: "command" "lowSpeed" "default" = fan speed to low
183
- * AirConditioner: "command" "middleSpeed" "default" = fan speed to medium
184
- * AirConditioner: "command" "highSpeed" "default" = fan speed to high
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: command,
166
+ command,
194
167
  parameter: 'default',
195
- commandType: 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: command,
180
+ command,
209
181
  parameter: 'default',
210
- commandType: 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
- + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
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.TargetHeaterCoolerState !== this.hap.Characteristic.TargetHeaterCoolerState.COOL) {
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('Get'
396
- + ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
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
- + ` ${this.HeaterCooler.TargetHeaterCoolerState}, ValidValues: ${this.ValidValues}, hide_automode: ${this.hide_automode}`);
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('Set TargetHeaterCoolerState: '
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('Set (AUTO)'
464
- + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
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('Set (COOL)'
472
- + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
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('Set (HEAT)'
480
- + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
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 ? this.hap.Characteristic.Active.INACTIVE
507
- : this.HeaterCooler.Active ?? this.accessory.context.Active;
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
- && this.accessory.context.CurrentTemperature === undefined) ? 24 : this.HeaterCooler.CurrentTemperature
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 ? 24 : this.HeaterCooler.ThresholdTemperature
514
- ?? this.accessory.context.ThresholdTemperature;
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) ? 4
517
- : this.HeaterCooler.RotationSpeed ?? this.accessory.context.RotationSpeed;
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
- && this.accessory.context.CurrentRelativeHumidity === undefined) ? 0 : this.HumiditySensor.CurrentRelativeHumidity
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
- + ` ThresholdTemperatureCached: ${this.accessory.context.ThresholdTemperature}`);
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
  }