@switchbot/homebridge-switchbot 3.5.0-beta.6 → 3.5.0-beta.60

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 (177) hide show
  1. package/.vscode/settings.json +4 -1
  2. package/CHANGELOG.md +4 -1
  3. package/config.schema.json +120 -17
  4. package/dist/device/blindtilt.d.ts +23 -96
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +408 -779
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts +26 -72
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +696 -822
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts +14 -68
  13. package/dist/device/ceilinglight.d.ts.map +1 -1
  14. package/dist/device/ceilinglight.js +237 -606
  15. package/dist/device/ceilinglight.js.map +1 -1
  16. package/dist/device/colorbulb.d.ts +14 -75
  17. package/dist/device/colorbulb.d.ts.map +1 -1
  18. package/dist/device/colorbulb.js +279 -658
  19. package/dist/device/colorbulb.js.map +1 -1
  20. package/dist/device/contact.d.ts +15 -66
  21. package/dist/device/contact.d.ts.map +1 -1
  22. package/dist/device/contact.js +242 -544
  23. package/dist/device/contact.js.map +1 -1
  24. package/dist/device/curtain.d.ts +19 -88
  25. package/dist/device/curtain.d.ts.map +1 -1
  26. package/dist/device/curtain.js +402 -805
  27. package/dist/device/curtain.js.map +1 -1
  28. package/dist/device/device.d.ts +59 -0
  29. package/dist/device/device.d.ts.map +1 -0
  30. package/dist/device/device.js +684 -0
  31. package/dist/device/device.js.map +1 -0
  32. package/dist/device/fan.d.ts +51 -0
  33. package/dist/device/fan.d.ts.map +1 -0
  34. package/dist/device/fan.js +535 -0
  35. package/dist/device/fan.js.map +1 -0
  36. package/dist/device/hub.d.ts +16 -60
  37. package/dist/device/hub.d.ts.map +1 -1
  38. package/dist/device/hub.js +246 -613
  39. package/dist/device/hub.js.map +1 -1
  40. package/dist/device/humidifier.d.ts +11 -66
  41. package/dist/device/humidifier.d.ts.map +1 -1
  42. package/dist/device/humidifier.js +232 -593
  43. package/dist/device/humidifier.js.map +1 -1
  44. package/dist/device/iosensor.d.ts +11 -64
  45. package/dist/device/iosensor.d.ts.map +1 -1
  46. package/dist/device/iosensor.js +185 -600
  47. package/dist/device/iosensor.js.map +1 -1
  48. package/dist/device/lightstrip.d.ts +11 -69
  49. package/dist/device/lightstrip.d.ts.map +1 -1
  50. package/dist/device/lightstrip.js +277 -586
  51. package/dist/device/lightstrip.js.map +1 -1
  52. package/dist/device/lock.d.ts +16 -63
  53. package/dist/device/lock.d.ts.map +1 -1
  54. package/dist/device/lock.js +241 -560
  55. package/dist/device/lock.js.map +1 -1
  56. package/dist/device/meter.d.ts +14 -64
  57. package/dist/device/meter.d.ts.map +1 -1
  58. package/dist/device/meter.js +181 -593
  59. package/dist/device/meter.js.map +1 -1
  60. package/dist/device/meterplus.d.ts +14 -65
  61. package/dist/device/meterplus.d.ts.map +1 -1
  62. package/dist/device/meterplus.js +170 -593
  63. package/dist/device/meterplus.js.map +1 -1
  64. package/dist/device/motion.d.ts +13 -69
  65. package/dist/device/motion.d.ts.map +1 -1
  66. package/dist/device/motion.js +178 -531
  67. package/dist/device/motion.js.map +1 -1
  68. package/dist/device/plug.d.ts +9 -57
  69. package/dist/device/plug.d.ts.map +1 -1
  70. package/dist/device/plug.js +92 -458
  71. package/dist/device/plug.js.map +1 -1
  72. package/dist/device/robotvacuumcleaner.d.ts +12 -63
  73. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  74. package/dist/device/robotvacuumcleaner.js +197 -521
  75. package/dist/device/robotvacuumcleaner.js.map +1 -1
  76. package/dist/device/waterdetector.d.ts +10 -65
  77. package/dist/device/waterdetector.d.ts.map +1 -1
  78. package/dist/device/waterdetector.js +139 -495
  79. package/dist/device/waterdetector.js.map +1 -1
  80. package/dist/homebridge-ui/public/index.html +22 -16
  81. package/dist/homebridge-ui/server.js +1 -1
  82. package/dist/homebridge-ui/server.js.map +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +2 -2
  86. package/dist/index.js.map +1 -1
  87. package/dist/irdevice/airconditioner.d.ts +9 -49
  88. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  89. package/dist/irdevice/airconditioner.js +309 -419
  90. package/dist/irdevice/airconditioner.js.map +1 -1
  91. package/dist/irdevice/airpurifier.d.ts +8 -39
  92. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  93. package/dist/irdevice/airpurifier.js +72 -304
  94. package/dist/irdevice/airpurifier.js.map +1 -1
  95. package/dist/irdevice/camera.d.ts +7 -36
  96. package/dist/irdevice/camera.d.ts.map +1 -1
  97. package/dist/irdevice/camera.js +34 -278
  98. package/dist/irdevice/camera.js.map +1 -1
  99. package/dist/irdevice/fan.d.ts +10 -43
  100. package/dist/irdevice/fan.d.ts.map +1 -1
  101. package/dist/irdevice/fan.js +100 -338
  102. package/dist/irdevice/fan.js.map +1 -1
  103. package/dist/irdevice/irdevice.d.ts +40 -0
  104. package/dist/irdevice/irdevice.d.ts.map +1 -0
  105. package/dist/irdevice/irdevice.js +330 -0
  106. package/dist/irdevice/irdevice.js.map +1 -0
  107. package/dist/irdevice/light.d.ts +12 -45
  108. package/dist/irdevice/light.d.ts.map +1 -1
  109. package/dist/irdevice/light.js +87 -357
  110. package/dist/irdevice/light.js.map +1 -1
  111. package/dist/irdevice/other.d.ts +19 -48
  112. package/dist/irdevice/other.d.ts.map +1 -1
  113. package/dist/irdevice/other.js +352 -546
  114. package/dist/irdevice/other.js.map +1 -1
  115. package/dist/irdevice/tv.d.ts +8 -40
  116. package/dist/irdevice/tv.d.ts.map +1 -1
  117. package/dist/irdevice/tv.js +82 -321
  118. package/dist/irdevice/tv.js.map +1 -1
  119. package/dist/irdevice/vacuumcleaner.d.ts +7 -36
  120. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  121. package/dist/irdevice/vacuumcleaner.js +41 -284
  122. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  123. package/dist/irdevice/waterheater.d.ts +7 -36
  124. package/dist/irdevice/waterheater.d.ts.map +1 -1
  125. package/dist/irdevice/waterheater.js +42 -287
  126. package/dist/irdevice/waterheater.js.map +1 -1
  127. package/dist/platform.d.ts +19 -6
  128. package/dist/platform.d.ts.map +1 -1
  129. package/dist/platform.js +310 -169
  130. package/dist/platform.js.map +1 -1
  131. package/dist/settings.d.ts +62 -19
  132. package/dist/settings.d.ts.map +1 -1
  133. package/dist/settings.js +16 -552
  134. package/dist/settings.js.map +1 -1
  135. package/dist/utils.d.ts +77 -0
  136. package/dist/utils.d.ts.map +1 -1
  137. package/dist/utils.js +638 -1
  138. package/dist/utils.js.map +1 -1
  139. package/eslint.config.js +96 -0
  140. package/package.json +19 -15
  141. package/src/custom.d.ts +2 -1
  142. package/src/device/blindtilt.ts +442 -814
  143. package/src/device/bot.ts +754 -915
  144. package/src/device/ceilinglight.ts +255 -633
  145. package/src/device/colorbulb.ts +294 -685
  146. package/src/device/contact.ts +277 -571
  147. package/src/device/curtain.ts +431 -835
  148. package/src/device/device.ts +709 -0
  149. package/src/device/fan.ts +591 -0
  150. package/src/device/hub.ts +286 -644
  151. package/src/device/humidifier.ts +266 -646
  152. package/src/device/iosensor.ts +220 -625
  153. package/src/device/lightstrip.ts +305 -620
  154. package/src/device/lock.ts +280 -600
  155. package/src/device/meter.ts +216 -617
  156. package/src/device/meterplus.ts +205 -619
  157. package/src/device/motion.ts +206 -556
  158. package/src/device/plug.ts +107 -490
  159. package/src/device/robotvacuumcleaner.ts +223 -550
  160. package/src/device/waterdetector.ts +160 -519
  161. package/src/homebridge-ui/public/index.html +22 -16
  162. package/src/homebridge-ui/server.ts +1 -1
  163. package/src/index.ts +4 -3
  164. package/src/irdevice/airconditioner.ts +333 -447
  165. package/src/irdevice/airpurifier.ts +92 -322
  166. package/src/irdevice/camera.ts +45 -294
  167. package/src/irdevice/fan.ts +115 -353
  168. package/src/irdevice/irdevice.ts +346 -0
  169. package/src/irdevice/light.ts +110 -385
  170. package/src/irdevice/other.ts +399 -616
  171. package/src/irdevice/tv.ts +103 -340
  172. package/src/irdevice/vacuumcleaner.ts +52 -306
  173. package/src/irdevice/waterheater.ts +53 -311
  174. package/src/platform.ts +355 -216
  175. package/src/settings.ts +116 -611
  176. package/src/utils.ts +642 -1
  177. package/src/device/waterdetector.json +0 -11
@@ -1,119 +1,72 @@
1
1
  import { request } from 'undici';
2
- import { sleep } from '../utils.js';
2
+ import { deviceBase } from './device.js';
3
3
  import { interval, Subject } from 'rxjs';
4
- import { SwitchBotPlatform } from '../platform.js';
4
+ import { Devices } from '../settings.js';
5
+ import { convertUnits } from '../utils.js';
5
6
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
- import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
7
- import { device, devicesConfig, serviceData, deviceStatus, Devices, SwitchBotPlatformConfig } from '../settings.js';
7
+
8
+ import type { SwitchBotPlatform } from '../platform.js';
9
+ import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
10
+ import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
8
11
 
9
12
  /**
10
13
  * Platform Accessory
11
14
  * An instance of this class is created for each accessory your platform registers
12
15
  * Each accessory may expose multiple services of different service types.
13
16
  */
14
- export class Humidifier {
15
- public readonly api: API;
16
- public readonly log: Logging;
17
- public readonly config!: SwitchBotPlatformConfig;
18
- protected readonly hap: HAP;
17
+ export class Humidifier extends deviceBase {
19
18
  // Services
20
- humidifierService: Service;
21
- temperatureservice?: Service;
22
-
23
- // Characteristic Values
24
- Active!: CharacteristicValue;
25
- WaterLevel!: CharacteristicValue;
26
- FirmwareRevision!: CharacteristicValue;
27
- CurrentTemperature!: CharacteristicValue;
28
- CurrentRelativeHumidity!: CharacteristicValue;
29
- TargetHumidifierDehumidifierState!: CharacteristicValue;
30
- CurrentHumidifierDehumidifierState!: CharacteristicValue;
31
- RelativeHumidityHumidifierThreshold!: CharacteristicValue;
32
-
33
- // OpenAPI
34
- OpenAPI_Active: deviceStatus['power'];
35
- OpenAPI_WaterLevel: deviceStatus['lackWater'];
36
- OpenAPI_FirmwareRevision: deviceStatus['version'];
37
- OpenAPI_CurrentTemperature: deviceStatus['temperature'];
38
- OpenAPI_CurrentRelativeHumidity: deviceStatus['humidity'];
39
- OpenAPI_CurrentHumidifierDehumidifierState: deviceStatus['auto'];
40
- OpenAPI_RelativeHumidityHumidifierThreshold: deviceStatus['nebulizationEfficiency'];
41
-
42
- // BLE Others
43
- connected?: boolean;
44
- onState!: serviceData['onState'];
45
- autoMode!: serviceData['autoMode'];
46
- percentage!: serviceData['percentage'];
47
-
48
- // Config
49
- set_minStep?: number;
50
- scanDuration!: number;
51
- deviceLogging!: string;
52
- deviceRefreshRate!: number;
19
+ private HumidifierDehumidifier: {
20
+ Name: CharacteristicValue;
21
+ Service: Service;
22
+ Active: CharacteristicValue;
23
+ WaterLevel: CharacteristicValue;
24
+ CurrentRelativeHumidity: CharacteristicValue;
25
+ TargetHumidifierDehumidifierState: CharacteristicValue;
26
+ CurrentHumidifierDehumidifierState: CharacteristicValue;
27
+ RelativeHumidityHumidifierThreshold: CharacteristicValue;
28
+ };
29
+
30
+ private TemperatureSensor?: {
31
+ Name: CharacteristicValue;
32
+ Service: Service;
33
+ CurrentTemperature: CharacteristicValue;
34
+ };
53
35
 
54
36
  // Updates
55
37
  humidifierUpdateInProgress!: boolean;
56
38
  doHumidifierUpdate!: Subject<void>;
57
39
 
58
- // Connection
59
- private readonly OpenAPI: boolean;
60
- private readonly BLE: boolean;
61
-
62
40
  constructor(
63
- private readonly platform: SwitchBotPlatform,
64
- private accessory: PlatformAccessory,
65
- public device: device & devicesConfig,
41
+ readonly platform: SwitchBotPlatform,
42
+ accessory: PlatformAccessory,
43
+ device: device & devicesConfig,
66
44
  ) {
67
- this.api = this.platform.api;
68
- this.log = this.platform.log;
69
- this.config = this.platform.config;
70
- this.hap = this.api.hap;
71
- // Connection
72
- this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
73
- this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
74
- // default placeholders
75
- this.deviceLogs(device);
76
- this.scan(device);
77
- this.refreshRate(device);
78
- this.deviceContext();
79
- this.deviceConfig(device);
80
-
45
+ super(platform, accessory, device);
81
46
  // this is subject we use to track when we need to POST changes to the SwitchBot API
82
47
  this.doHumidifierUpdate = new Subject();
83
48
  this.humidifierUpdateInProgress = false;
84
49
 
85
- // Retrieve initial values and updateHomekit
86
- this.refreshStatus();
87
-
88
- // set accessory information
89
- accessory
90
- .getService(this.hap.Service.AccessoryInformation)!
91
- .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
92
- .setCharacteristic(this.hap.Characteristic.Model, 'W0801800')
93
- .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
94
- .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
95
-
96
- // get the service if it exists, otherwise create a new service
97
- // you can create multiple services for each accessory
98
- const humidifierService = `${accessory.displayName} Humidifier`;
99
- (this.humidifierService = accessory.getService(this.hap.Service.HumidifierDehumidifier)
100
- || accessory.addService(this.hap.Service.HumidifierDehumidifier)), humidifierService;
101
-
102
- this.humidifierService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
103
- if (!this.humidifierService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
104
- this.humidifierService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
105
- }
106
-
107
- // each service must implement at-minimum the "required characteristics" for the given service type
108
- // see https://developers.homebridge.io/#/service/HumidifierDehumidifier
109
-
110
- // create handlers for required characteristics
111
- this.humidifierService.setCharacteristic(
112
- this.hap.Characteristic.CurrentHumidifierDehumidifierState,
113
- this.CurrentHumidifierDehumidifierState,
114
- );
115
-
116
- this.humidifierService
50
+ // Initialize the HumidifierDehumidifier Service
51
+ this.HumidifierDehumidifier = {
52
+ Name: accessory.context.HumidifierDehumidifierName ?? accessory.displayName,
53
+ Service: accessory.getService(this.hap.Service.HumidifierDehumidifier)
54
+ ?? accessory.addService(this.hap.Service.HumidifierDehumidifier) as Service,
55
+ Active: accessory.context.Active ?? this.hap.Characteristic.Active.ACTIVE,
56
+ WaterLevel: accessory.context.WaterLevel ?? 100,
57
+ CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity ?? 50,
58
+ TargetHumidifierDehumidifierState: accessory.context.TargetHumidifierDehumidifierState
59
+ ?? this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER,
60
+ CurrentHumidifierDehumidifierState: accessory.context.CurrentHumidifierDehumidifierState
61
+ ?? this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE,
62
+ RelativeHumidityHumidifierThreshold: accessory.context.RelativeHumidityHumidifierThreshold ?? 50,
63
+ };
64
+
65
+ // Initialize the HumidifierDehumidifier Characteristics
66
+ this.HumidifierDehumidifier.Service
67
+ .setCharacteristic(this.hap.Characteristic.Name, this.HumidifierDehumidifier.Name)
68
+ .setCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
69
+ this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState)
117
70
  .getCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState)
118
71
  .setProps({
119
72
  validValueRanges: [0, 1],
@@ -121,36 +74,47 @@ export class Humidifier {
121
74
  maxValue: 1,
122
75
  validValues: [0, 1],
123
76
  })
77
+ .onGet(() => {
78
+ return this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
79
+ })
124
80
  .onSet(this.TargetHumidifierDehumidifierStateSet.bind(this));
125
81
 
126
- this.humidifierService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
82
+ this.HumidifierDehumidifier.Service
83
+ .getCharacteristic(this.hap.Characteristic.Active)
84
+ .onGet(() => {
85
+ return this.HumidifierDehumidifier.Active;
86
+ })
87
+ .onSet(this.ActiveSet.bind(this));
127
88
 
128
- this.humidifierService
89
+ this.HumidifierDehumidifier.Service
129
90
  .getCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold)
130
91
  .setProps({
131
92
  validValueRanges: [0, 100],
132
93
  minValue: 0,
133
94
  maxValue: 100,
134
- minStep: this.minStep(),
95
+ minStep: this.minStep(device),
96
+ })
97
+ .onGet(() => {
98
+ return this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
135
99
  })
136
100
  .onSet(this.RelativeHumidityHumidifierThresholdSet.bind(this));
101
+ accessory.context.HumidifierDehumidifierName = this.HumidifierDehumidifier.Name;
137
102
 
138
- // Temperature Sensor Service
139
- if (device.humidifier?.hide_temperature || this.BLE) {
103
+ // Initialize the Temperature Sensor Service
104
+ if (device.humidifier?.hide_temperature) {
140
105
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
141
- this.temperatureservice = this.accessory.getService(this.hap.Service.TemperatureSensor);
142
- accessory.removeService(this.temperatureservice!);
143
- } else if (!this.temperatureservice && !this.BLE) {
144
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
145
- const temperatureservice = `${accessory.displayName} Temperature Sensor`;
146
- (this.temperatureservice = this.accessory.getService(this.hap.Service.TemperatureSensor)
147
- || this.accessory.addService(this.hap.Service.TemperatureSensor)), temperatureservice;
106
+ this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service;
107
+ accessory.removeService(this.TemperatureSensor!.Service);
108
+ } else {
109
+ this.TemperatureSensor = {
110
+ Name: accessory.context.TemperatureSensorName ?? `${accessory.displayName} Temperature Sensor`,
111
+ Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? this.accessory.addService(this.hap.Service.TemperatureSensor) as Service,
112
+ CurrentTemperature: accessory.context.CurrentTemperature || 30,
113
+ };
148
114
 
149
- this.temperatureservice.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
150
- if (!this.temperatureservice.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
151
- this.temperatureservice.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
152
- }
153
- this.temperatureservice
115
+ // Initialize the Temperature Sensor Characteristics
116
+ this.TemperatureSensor.Service
117
+ .setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name)
154
118
  .getCharacteristic(this.hap.Characteristic.CurrentTemperature)
155
119
  .setProps({
156
120
  validValueRanges: [-273.15, 100],
@@ -159,12 +123,14 @@ export class Humidifier {
159
123
  minStep: 0.1,
160
124
  })
161
125
  .onGet(() => {
162
- return this.CurrentTemperature;
126
+ return this.TemperatureSensor!.CurrentTemperature;
163
127
  });
164
- } else {
165
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
128
+ accessory.context.TemperatureSensorName = this.TemperatureSensor.Name;
166
129
  }
167
130
 
131
+ // Retrieve initial values and updateHomekit
132
+ this.refreshStatus();
133
+
168
134
  // Retrieve initial values and updateHomekit
169
135
  this.updateHomeKitCharacteristics();
170
136
 
@@ -176,22 +142,23 @@ export class Humidifier {
176
142
  });
177
143
 
178
144
  //regisiter webhook event handler
179
- if (this.device.webhook) {
180
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
145
+ if (device.webhook) {
146
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
181
147
  this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
182
148
  try {
183
149
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
184
- if (context.scale === 'CELSIUS') {
185
- const { temperature, humidity } = context;
186
- const { CurrentTemperature, CurrentRelativeHumidity } = this;
187
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
188
- '(temperature, humidity) = ' +
189
- `Webhook:(${temperature}, ${humidity}), ` +
190
- `current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
191
- this.CurrentRelativeHumidity = humidity;
192
- this.CurrentTemperature = temperature;
193
- this.updateHomeKitCharacteristics();
150
+ const { temperature, humidity } = context;
151
+ const { CurrentRelativeHumidity } = this.HumidifierDehumidifier;
152
+ const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
153
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
154
+ '(temperature, humidity) = ' +
155
+ `Webhook:(${convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo)}, ${humidity}), ` +
156
+ `current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
157
+ this.HumidifierDehumidifier.CurrentRelativeHumidity = humidity;
158
+ if (!this.device.humidifier?.hide_temperature) {
159
+ this.TemperatureSensor!.CurrentTemperature = convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo);
194
160
  }
161
+ this.updateHomeKitCharacteristics();
195
162
  } catch (e: any) {
196
163
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
197
164
  + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
@@ -222,105 +189,95 @@ export class Humidifier {
222
189
  });
223
190
  }
224
191
 
225
- /**
226
- * Parse the device status from the SwitchBot api
227
- */
228
- async parseStatus(): Promise<void> {
229
- if (!this.device.enableCloudService && this.OpenAPI) {
230
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
231
- } else if (this.BLE) {
232
- await this.BLEparseStatus();
233
- } else if (this.OpenAPI && this.platform.config.credentials?.token) {
234
- await this.openAPIparseStatus();
235
- } else {
236
- await this.offlineOff();
237
- this.debugWarnLog(
238
- `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
239
- );
240
- }
241
- }
242
-
243
- async BLEparseStatus(): Promise<void> {
192
+ async BLEparseStatus(serviceData: serviceData): Promise<void> {
244
193
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
194
+ // Target Humidifier Dehumidifier State
195
+ if (serviceData.autoMode) {
196
+ this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
197
+ }
245
198
  // Current Relative Humidity
246
- this.CurrentRelativeHumidity = this.percentage!;
247
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
199
+ this.HumidifierDehumidifier.CurrentRelativeHumidity = serviceData.percentage!;
200
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
201
+ + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
248
202
  // Active
249
- if (this.onState) {
250
- this.Active = this.hap.Characteristic.Active.ACTIVE;
203
+ if (serviceData.onState) {
204
+ this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
251
205
  } else {
252
- this.Active = this.hap.Characteristic.Active.INACTIVE;
206
+ this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
253
207
  }
254
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
208
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
255
209
  }
256
210
 
257
- async openAPIparseStatus(): Promise<void> {
211
+ async openAPIparseStatus(deviceStatus: deviceStatus): Promise<void> {
258
212
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
259
213
  // Current Relative Humidity
260
- this.CurrentRelativeHumidity = this.OpenAPI_CurrentTemperature!;
261
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
214
+ this.HumidifierDehumidifier.CurrentRelativeHumidity = deviceStatus.body.temperature!;
215
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
216
+ + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
262
217
  // Current Temperature
263
218
  if (!this.device.humidifier?.hide_temperature) {
264
- this.CurrentTemperature = this.OpenAPI_CurrentTemperature!;
265
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
219
+ this.TemperatureSensor!.CurrentTemperature = deviceStatus.body.temperature!;
220
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
266
221
  }
267
222
  // Target Humidifier Dehumidifier State
268
- switch (this.OpenAPI_CurrentHumidifierDehumidifierState) {
223
+ switch (deviceStatus.body.auto) {
269
224
  case true:
270
- this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
271
- this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
272
- this.RelativeHumidityHumidifierThreshold = this.CurrentRelativeHumidity;
225
+ this.HumidifierDehumidifier.TargetHumidifierDehumidifierState =
226
+ this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
227
+ this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
228
+ this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.CurrentRelativeHumidity;
273
229
  break;
274
230
  default:
275
- this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
276
- if (this.OpenAPI_RelativeHumidityHumidifierThreshold! > 100) {
277
- this.RelativeHumidityHumidifierThreshold = 100;
231
+ this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
232
+ if (deviceStatus.body.nebulizationEfficiency! > 100) {
233
+ this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = 100;
278
234
  } else {
279
- this.RelativeHumidityHumidifierThreshold = this.OpenAPI_RelativeHumidityHumidifierThreshold!;
235
+ this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency!;
280
236
  }
281
- if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
282
- this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
283
- } else if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
284
- this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
237
+ if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
238
+ this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
239
+ } else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
240
+ this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
285
241
  } else {
286
- this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
242
+ this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
287
243
  }
288
244
  }
289
- this.debugLog(
290
- `${this.device.deviceType}: ${this.accessory.displayName}` + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
291
- );
292
- this.debugLog(
293
- `${this.device.deviceType}: ${this.accessory.displayName}` +
294
- ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
295
- );
296
- this.debugLog(
297
- `${this.device.deviceType}: ${this.accessory.displayName}` + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
298
- );
245
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
246
+ + ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
247
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
248
+ + ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
249
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
250
+ + ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
299
251
  // Active
300
- switch (this.OpenAPI_Active) {
252
+ switch (deviceStatus.body.power) {
301
253
  case 'on':
302
- this.Active = this.hap.Characteristic.Active.ACTIVE;
254
+ this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
303
255
  break;
304
256
  default:
305
- this.Active = this.hap.Characteristic.Active.INACTIVE;
257
+ this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
306
258
  }
307
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
259
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
308
260
  // Water Level
309
- if (this.OpenAPI_WaterLevel) {
310
- this.WaterLevel = 0;
261
+ if (deviceStatus.body.lackWater) {
262
+ this.HumidifierDehumidifier.WaterLevel = 0;
311
263
  } else {
312
- this.WaterLevel = 100;
264
+ this.HumidifierDehumidifier.WaterLevel = 100;
313
265
  }
314
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
266
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
315
267
 
316
- // FirmwareRevision
317
- this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
318
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
268
+ // Firmware Version
269
+ const version = deviceStatus.body.version?.toString();
270
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
271
+ if (deviceStatus.body.version) {
272
+ this.accessory.context.version = version?.replace(/^V|-.*$/g, '');
273
+ this.accessory
274
+ .getService(this.hap.Service.AccessoryInformation)!
275
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.version)
276
+ .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
277
+ .updateValue(this.accessory.context.version);
278
+ }
319
279
  }
320
280
 
321
- /**
322
- * Asks the SwitchBot API for the latest device information
323
- */
324
281
  async refreshStatus(): Promise<void> {
325
282
  if (!this.device.enableCloudService && this.OpenAPI) {
326
283
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
@@ -350,103 +307,43 @@ export class Humidifier {
350
307
  // Start to monitor advertisement packets
351
308
  (async () => {
352
309
  // Start to monitor advertisement packets
353
- await switchbot.startScan({
354
- model: 'e',
355
- id: this.device.bleMac,
356
- });
310
+ await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
357
311
  // Set an event handler
358
312
  switchbot.onadvertisement = (ad: any) => {
359
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
360
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
361
- if (this.device.bleMac === ad.address && ad.serviceData.model === 'e') {
313
+ if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
314
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
315
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
362
316
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
363
- this.autoMode = ad.serviceData.autoMode;
364
- this.onState = ad.serviceData.onState;
365
- this.percentage = ad.serviceData.percentage > 100 ? 100 : ad.serviceData.percentage;
366
317
  } else {
367
318
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
368
319
  }
369
320
  };
370
- // Wait 1 seconds
321
+ // Wait 10 seconds
371
322
  await switchbot.wait(this.scanDuration * 1000);
372
323
  // Stop to monitor
373
324
  await switchbot.stopScan();
374
325
  // Update HomeKit
375
- await this.BLEparseStatus();
326
+ await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
376
327
  await this.updateHomeKitCharacteristics();
377
328
  })();
378
- /*if (switchbot !== false) {
379
- switchbot
380
- .startScan({
381
- model: 'e',
382
- id: this.device.bleMac,
383
- })
384
- .then(async () => {
385
- // Set an event handler
386
- switchbot.onadvertisement = async (ad: ad) => {
387
- this.debugLog(
388
- `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
389
- ` BLE Address Found: ${ad.address}`,
390
- );
391
- this.autoMode = ad.serviceData.autoMode;
392
- this.onState = ad.serviceData.onState;
393
- this.percentage = ad.serviceData.percentage;
394
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
395
- this.debugLog(
396
- `${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
397
- `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
398
- );
399
-
400
- if (ad.serviceData) {
401
- this.connected = true;
402
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
403
- await this.stopScanning(switchbot);
404
- } else {
405
- this.connected = false;
406
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
407
- }
408
- };
409
- // Wait
410
- return await sleep(this.scanDuration * 1000);
411
- })
412
- .then(async () => {
413
- // Stop to monitor
414
- await this.stopScanning(switchbot);
415
- })
416
- .catch(async (e: any) => {
417
- this.apiError(e);
418
- this.errorLog(
419
- `${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
420
- ` Connection, Error Message: ${JSON.stringify(e.message)}`,
421
- );
422
- await this.BLERefreshConnection(switchbot);
423
- });
424
- } else {
329
+ if (switchbot === undefined) {
425
330
  await this.BLERefreshConnection(switchbot);
426
- }*/
331
+ }
427
332
  }
428
333
 
429
334
  async openAPIRefreshStatus(): Promise<void> {
430
335
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
431
336
  try {
432
- const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/status`, {
433
- headers: this.platform.generateHeaders(),
434
- });
337
+ const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries,
338
+ `${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
435
339
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
436
340
  const deviceStatus: any = await body.json();
437
341
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
438
342
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
439
343
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
440
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
344
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
441
345
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
442
- this.OpenAPI_CurrentHumidifierDehumidifierState = deviceStatus.body.auto;
443
- this.OpenAPI_Active = deviceStatus.body.power;
444
- this.OpenAPI_WaterLevel = deviceStatus.body.lackWater;
445
- this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity;
446
- this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature;
447
- this.OpenAPI_RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency;
448
- this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
449
- this.openAPIparseStatus();
346
+ this.openAPIparseStatus(deviceStatus);
450
347
  this.updateHomeKitCharacteristics();
451
348
  } else {
452
349
  this.statusCode(statusCode);
@@ -500,11 +397,13 @@ export class Humidifier {
500
397
  id: this.device.bleMac,
501
398
  })
502
399
  .then(async (device_list: any) => {
503
- this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
504
- return await device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
400
+ this.infoLog(`${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
401
+ return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
505
402
  })
506
403
  .then(() => {
507
404
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
405
+ this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
406
+ + `Active: ${this.HumidifierDehumidifier.Active} sent over BLE, sent successfully`);
508
407
  })
509
408
  .catch(async (e: any) => {
510
409
  this.apiError(e);
@@ -519,13 +418,14 @@ export class Humidifier {
519
418
  async openAPIpushChanges(): Promise<void> {
520
419
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
521
420
  if (
522
- this.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
523
- this.Active === this.hap.Characteristic.Active.ACTIVE
421
+ this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
422
+ this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE
524
423
  ) {
525
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
424
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
425
+ + ` Pushing Manual: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`);
526
426
  const bodyChange = JSON.stringify({
527
427
  command: 'setMode',
528
- parameter: `${this.RelativeHumidityHumidifierThreshold}`,
428
+ parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
529
429
  commandType: 'command',
530
430
  });
531
431
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
@@ -543,6 +443,8 @@ export class Humidifier {
543
443
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
544
444
  this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
545
445
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
446
+ this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
447
+ + `request to SwitchBot API, body: ${JSON.stringify(deviceStatus)} sent successfully`);
546
448
  } else {
547
449
  this.statusCode(statusCode);
548
450
  this.statusCode(deviceStatus.statusCode);
@@ -555,8 +457,9 @@ export class Humidifier {
555
457
  );
556
458
  }
557
459
  } else if (
558
- this.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
559
- this.Active === this.hap.Characteristic.Active.ACTIVE
460
+ this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
461
+ this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
462
+ this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE
560
463
  ) {
561
464
  await this.pushAutoChanges();
562
465
  } else {
@@ -570,8 +473,9 @@ export class Humidifier {
570
473
  async pushAutoChanges(): Promise<void> {
571
474
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
572
475
  if (
573
- this.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
574
- this.Active === this.hap.Characteristic.Active.ACTIVE
476
+ this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
477
+ this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
478
+ this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE
575
479
  ) {
576
480
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
577
481
  const bodyChange = JSON.stringify({
@@ -594,6 +498,8 @@ export class Humidifier {
594
498
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
595
499
  this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
596
500
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
501
+ this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
502
+ + `request to SwitchBot API, body: ${JSON.stringify(deviceStatus)} sent successfully`);
597
503
  } else {
598
504
  this.statusCode(statusCode);
599
505
  this.statusCode(deviceStatus.statusCode);
@@ -606,10 +512,8 @@ export class Humidifier {
606
512
  );
607
513
  }
608
514
  } else {
609
- this.debugLog(
610
- `${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges.` +
611
- `TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}, Active: ${this.Active}`,
612
- );
515
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges. TargetHumidifierDehumidifierState:`
516
+ + ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`);
613
517
  }
614
518
  }
615
519
 
@@ -618,7 +522,7 @@ export class Humidifier {
618
522
  */
619
523
  async pushActiveChanges(): Promise<void> {
620
524
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
621
- if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
525
+ if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
622
526
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
623
527
  const bodyChange = JSON.stringify({
624
528
  command: 'turnOff',
@@ -640,6 +544,8 @@ export class Humidifier {
640
544
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
641
545
  this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
642
546
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
547
+ this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
548
+ + `request to SwitchBot API, body: ${JSON.stringify(deviceStatus)} sent successfully`);
643
549
  } else {
644
550
  this.statusCode(statusCode);
645
551
  this.statusCode(deviceStatus.statusCode);
@@ -652,7 +558,7 @@ export class Humidifier {
652
558
  );
653
559
  }
654
560
  } else {
655
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.Active}`);
561
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.HumidifierDehumidifier.Active}`);
656
562
  }
657
563
  }
658
564
 
@@ -660,13 +566,13 @@ export class Humidifier {
660
566
  * Handle requests to set the "Active" characteristic
661
567
  */
662
568
  async ActiveSet(value: CharacteristicValue): Promise<void> {
663
- if (this.Active === this.accessory.context.Active) {
569
+ if (this.HumidifierDehumidifier.Active === this.accessory.context.Active) {
664
570
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Active: ${value}`);
665
571
  } else {
666
572
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
667
573
  }
668
574
 
669
- this.Active = value;
575
+ this.HumidifierDehumidifier.Active = value;
670
576
  this.doHumidifierUpdate.next();
671
577
  }
672
578
 
@@ -674,13 +580,13 @@ export class Humidifier {
674
580
  * Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
675
581
  */
676
582
  async TargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
677
- if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
583
+ if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
678
584
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
679
585
  } else {
680
586
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
681
587
  }
682
588
 
683
- this.TargetHumidifierDehumidifierState = value;
589
+ this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value;
684
590
  this.doHumidifierUpdate.next();
685
591
  }
686
592
 
@@ -688,16 +594,16 @@ export class Humidifier {
688
594
  * Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
689
595
  */
690
596
  async RelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
691
- if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
597
+ if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
692
598
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
693
599
  } else {
694
600
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
695
601
  }
696
602
 
697
- this.RelativeHumidityHumidifierThreshold = value;
698
- if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
699
- this.Active = this.hap.Characteristic.Active.ACTIVE;
700
- this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
603
+ this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
604
+ if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
605
+ this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
606
+ this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
701
607
  }
702
608
  this.doHumidifierUpdate.next();
703
609
  }
@@ -706,117 +612,76 @@ export class Humidifier {
706
612
  * Updates the status for each of the HomeKit Characteristics
707
613
  */
708
614
  async updateHomeKitCharacteristics(): Promise<void> {
709
- if (this.CurrentRelativeHumidity === undefined) {
710
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
615
+ if (this.HumidifierDehumidifier.CurrentRelativeHumidity === undefined) {
616
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
617
+ + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
711
618
  } else {
712
- this.humidifierService.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
713
- this.debugLog(
714
- `${this.device.deviceType}: ${this.accessory.displayName}` + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
715
- );
716
- this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
619
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity,
620
+ this.HumidifierDehumidifier.CurrentRelativeHumidity);
621
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
622
+ + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
623
+ this.accessory.context.CurrentRelativeHumidity = this.HumidifierDehumidifier.CurrentRelativeHumidity;
717
624
  }
718
625
  if (this.OpenAPI) {
719
- if (this.WaterLevel === undefined) {
720
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
626
+ if (this.HumidifierDehumidifier.WaterLevel === undefined) {
627
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
721
628
  } else {
722
- this.humidifierService.updateCharacteristic(this.hap.Characteristic.WaterLevel, this.WaterLevel);
723
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
724
- this.accessory.context.WaterLevel = this.WaterLevel;
629
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, this.HumidifierDehumidifier.WaterLevel);
630
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
631
+ + ` WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
632
+ this.accessory.context.WaterLevel = this.HumidifierDehumidifier.WaterLevel;
725
633
  }
726
634
  }
727
- if (this.CurrentHumidifierDehumidifierState === undefined) {
728
- this.debugLog(
729
- `${this.device.deviceType}: ${this.accessory.displayName}` +
730
- ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
731
- );
635
+ if (this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState === undefined) {
636
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
637
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
732
638
  } else {
733
- this.humidifierService.updateCharacteristic(
734
- this.hap.Characteristic.CurrentHumidifierDehumidifierState,
735
- this.CurrentHumidifierDehumidifierState,
736
- );
737
- this.debugLog(
738
- `${this.device.deviceType}: ${this.accessory.displayName}` +
739
- ` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
740
- );
741
- this.accessory.context.CurrentHumidifierDehumidifierState = this.CurrentHumidifierDehumidifierState;
742
- }
743
- if (this.TargetHumidifierDehumidifierState === undefined) {
744
- this.debugLog(
745
- `${this.device.deviceType}: ${this.accessory.displayName}` + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
639
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
640
+ this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
641
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic` +
642
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
643
+ this.accessory.context.CurrentHumidifierDehumidifierState = this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState;
644
+ }
645
+ if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === undefined) {
646
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
647
+ + ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`,
746
648
  );
747
649
  } else {
748
- this.humidifierService.updateCharacteristic(
749
- this.hap.Characteristic.TargetHumidifierDehumidifierState,
750
- this.TargetHumidifierDehumidifierState,
751
- );
752
- this.debugLog(
753
- `${this.device.deviceType}: ${this.accessory.displayName}` +
754
- ` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
755
- );
756
- this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
757
- }
758
- if (this.Active === undefined) {
759
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
650
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState,
651
+ this.HumidifierDehumidifier.TargetHumidifierDehumidifierState);
652
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
653
+ + ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
654
+ this.accessory.context.TargetHumidifierDehumidifierState = this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
655
+ }
656
+ if (this.HumidifierDehumidifier.Active === undefined) {
657
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
760
658
  } else {
761
- this.humidifierService.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
762
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
763
- this.accessory.context.Active = this.Active;
659
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HumidifierDehumidifier.Active);
660
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HumidifierDehumidifier.Active}`);
661
+ this.accessory.context.Active = this.HumidifierDehumidifier.Active;
764
662
  }
765
- if (this.RelativeHumidityHumidifierThreshold === undefined) {
766
- this.debugLog(
767
- `${this.device.deviceType}: ${this.accessory.displayName}` +
768
- ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
769
- );
663
+ if (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold === undefined) {
664
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
665
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
770
666
  } else {
771
- this.humidifierService.updateCharacteristic(
772
- this.hap.Characteristic.RelativeHumidityHumidifierThreshold,
773
- this.RelativeHumidityHumidifierThreshold,
774
- );
775
- this.debugLog(
776
- `${this.device.deviceType}: ${this.accessory.displayName}` +
777
- ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
778
- );
779
- this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
667
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold,
668
+ this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
669
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic` +
670
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
671
+ this.accessory.context.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
780
672
  }
781
673
  if (!this.device.humidifier?.hide_temperature && !this.BLE) {
782
- if (this.CurrentTemperature === undefined) {
783
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
674
+ if (this.TemperatureSensor!.CurrentTemperature === undefined) {
675
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
784
676
  } else {
785
- this.temperatureservice?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.CurrentTemperature);
786
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
787
- this.accessory.context.CurrentTemperature = this.CurrentTemperature;
677
+ this.TemperatureSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor!.CurrentTemperature);
678
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
679
+ + ` CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
680
+ this.accessory.context.CurrentTemperature = this.TemperatureSensor!.CurrentTemperature;
788
681
  }
789
682
  }
790
683
  }
791
684
 
792
- async stopScanning(switchbot: any) {
793
- switchbot.stopScan();
794
- if (this.connected) {
795
- await this.BLEparseStatus();
796
- await this.updateHomeKitCharacteristics();
797
- } else {
798
- await this.BLERefreshConnection(switchbot);
799
- }
800
- }
801
-
802
- async getCustomBLEAddress(switchbot: any) {
803
- if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
804
- (async () => {
805
- // Start to monitor advertisement packets
806
- await switchbot.startScan({
807
- model: 'e',
808
- });
809
- // Set an event handler
810
- switchbot.onadvertisement = (ad: any) => {
811
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
812
- };
813
- await sleep(10000);
814
- // Stop to monitor
815
- switchbot.stopScan();
816
- })();
817
- }
818
- }
819
-
820
685
  async BLEPushConnection() {
821
686
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
822
687
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
@@ -833,283 +698,38 @@ export class Humidifier {
833
698
  }
834
699
  }
835
700
 
836
- minStep(): number {
837
- if (this.device.humidifier?.set_minStep) {
838
- this.set_minStep = this.device.humidifier?.set_minStep;
839
- } else {
840
- this.set_minStep = 1;
841
- }
842
- return this.set_minStep;
843
- }
844
-
845
- async scan(device: device & devicesConfig): Promise<void> {
846
- if (device.scanDuration) {
847
- this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
848
- if (this.BLE) {
849
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
850
- }
701
+ minStep(device: device & devicesConfig): number {
702
+ let set_minStep: number;
703
+ if (device.humidifier?.set_minStep) {
704
+ set_minStep = device.humidifier?.set_minStep;
851
705
  } else {
852
- this.scanDuration = this.accessory.context.scanDuration = 1;
853
- if (this.BLE) {
854
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
855
- }
856
- }
857
- }
858
-
859
- async statusCode(statusCode: number): Promise<void> {
860
- switch (statusCode) {
861
- case 151:
862
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
863
- break;
864
- case 152:
865
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
866
- break;
867
- case 160:
868
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
869
- break;
870
- case 161:
871
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
872
- this.offlineOff();
873
- break;
874
- case 171:
875
- this.errorLog(
876
- `${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
877
- `Hub: ${this.device.hubDeviceId}`,
878
- );
879
- this.offlineOff();
880
- break;
881
- case 190:
882
- this.errorLog(
883
- `${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
884
- ` Or command format is invalid, statusCode: ${statusCode}`,
885
- );
886
- break;
887
- case 100:
888
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
889
- break;
890
- case 200:
891
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
892
- break;
893
- case 400:
894
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
895
- + `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
896
- break;
897
- case 401:
898
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
899
- + `but the request has not been authenticated, statusCode: ${statusCode}`);
900
- break;
901
- case 403:
902
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
903
- + `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
904
- break;
905
- case 404:
906
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
907
- + `statusCode: ${statusCode}`);
908
- break;
909
- case 406:
910
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
911
- + `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
912
- break;
913
- case 415:
914
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
915
- + `header that is not supported by the server, statusCode: ${statusCode}`);
916
- break;
917
- case 422:
918
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
919
- + `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
920
- break;
921
- case 429:
922
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
923
- + `requests allowed for a given time window, statusCode: ${statusCode}`);
924
- break;
925
- case 500:
926
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
927
- + `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
928
- break;
929
- default:
930
- this.infoLog(
931
- `${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
932
- `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
933
- );
706
+ set_minStep = 1;
934
707
  }
708
+ return set_minStep;
935
709
  }
936
710
 
937
711
  async offlineOff(): Promise<void> {
938
712
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} offline: ${this.device.offline}`);
939
713
  if (this.device.offline) {
940
- await this.deviceContext();
941
- if (this.CurrentTemperature === undefined) {
942
- this.CurrentTemperature = 0;
943
- }
944
- await this.updateHomeKitCharacteristics();
714
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
715
+ this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE);
716
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState,
717
+ this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER);
718
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
945
719
  }
946
720
  }
947
721
 
948
722
  async apiError(e: any): Promise<void> {
949
- this.humidifierService.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
723
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
950
724
  if (!this.BLE) {
951
- this.humidifierService.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
725
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
952
726
  }
953
- this.humidifierService.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
954
- this.humidifierService.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
955
- this.humidifierService.updateCharacteristic(this.hap.Characteristic.Active, e);
956
- this.humidifierService.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
727
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
728
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
729
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
730
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
957
731
  if (!this.device.humidifier?.hide_temperature && !this.BLE) {
958
- this.temperatureservice?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
959
- }
960
- }
961
-
962
- async deviceContext() {
963
- if (this.Active === undefined) {
964
- this.Active = this.hap.Characteristic.Active.ACTIVE;
965
- } else {
966
- this.Active = this.accessory.context.Active;
967
- }
968
- if (this.CurrentTemperature === undefined) {
969
- this.CurrentTemperature = 30;
970
- } else {
971
- this.CurrentTemperature = this.accessory.context.CurrentTemperature;
972
- }
973
- if (this.CurrentRelativeHumidity === undefined) {
974
- this.CurrentRelativeHumidity = 0;
975
- } else {
976
- this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
977
- }
978
- if (this.TargetHumidifierDehumidifierState === undefined) {
979
- this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
980
- } else if (this.accessory.context.TargetHumidifierDehumidifierState === undefined) {
981
- this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
982
- } else {
983
- this.TargetHumidifierDehumidifierState = this.accessory.context.TargetHumidifierDehumidifierState;
732
+ this.TemperatureSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
984
733
  }
985
- if (this.CurrentHumidifierDehumidifierState === undefined) {
986
- this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
987
- } else if (this.accessory.context.CurrentHumidifierDehumidifierState === undefined) {
988
- this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
989
- } else {
990
- this.CurrentHumidifierDehumidifierState = this.accessory.context.CurrentHumidifierDehumidifierState;
991
- }
992
- if (this.RelativeHumidityHumidifierThreshold === undefined) {
993
- this.RelativeHumidityHumidifierThreshold = 0;
994
- } else {
995
- this.RelativeHumidityHumidifierThreshold = this.accessory.context.RelativeHumidityHumidifierThreshold;
996
- }
997
- if (this.WaterLevel === undefined) {
998
- this.WaterLevel = 0;
999
- } else {
1000
- this.WaterLevel = this.accessory.context.WaterLevel;
1001
- }
1002
- if (this.FirmwareRevision === undefined) {
1003
- this.FirmwareRevision = this.platform.version;
1004
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
1005
- }
1006
- }
1007
-
1008
- async refreshRate(device: device & devicesConfig): Promise<void> {
1009
- if (device.refreshRate) {
1010
- this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
1011
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
1012
- } else if (this.platform.config.options!.refreshRate) {
1013
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
1014
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
1015
- }
1016
- }
1017
-
1018
- async deviceConfig(device: device & devicesConfig): Promise<void> {
1019
- let config = {};
1020
- if (device.humidifier) {
1021
- config = device.humidifier;
1022
- }
1023
- if (device.connectionType !== undefined) {
1024
- config['connectionType'] = device.connectionType;
1025
- }
1026
- if (device.external !== undefined) {
1027
- config['external'] = device.external;
1028
- }
1029
- if (device.logging !== undefined) {
1030
- config['logging'] = device.logging;
1031
- }
1032
- if (device.refreshRate !== undefined) {
1033
- config['refreshRate'] = device.refreshRate;
1034
- }
1035
- if (device.scanDuration !== undefined) {
1036
- config['scanDuration'] = device.scanDuration;
1037
- }
1038
- if (device.offline !== undefined) {
1039
- config['offline'] = device.offline;
1040
- }
1041
- if (device.webhook !== undefined) {
1042
- config['webhook'] = device.webhook;
1043
- }
1044
- if (Object.entries(config).length !== 0) {
1045
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1046
- }
1047
- }
1048
-
1049
- async deviceLogs(device: device & devicesConfig): Promise<void> {
1050
- if (this.platform.debugMode) {
1051
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
1052
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
1053
- } else if (device.logging) {
1054
- this.deviceLogging = this.accessory.context.logging = device.logging;
1055
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
1056
- } else if (this.platform.config.options?.logging) {
1057
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
1058
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
1059
- } else {
1060
- this.deviceLogging = this.accessory.context.logging = 'standard';
1061
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
1062
- }
1063
- }
1064
-
1065
- /**
1066
- * Logging for Device
1067
- */
1068
- async infoLog(...log: any[]): Promise<void> {
1069
- if (this.enablingDeviceLogging()) {
1070
- this.platform.log.info(String(...log));
1071
- }
1072
- }
1073
-
1074
- async warnLog(...log: any[]): Promise<void> {
1075
- if (this.enablingDeviceLogging()) {
1076
- this.platform.log.warn(String(...log));
1077
- }
1078
- }
1079
-
1080
- async debugWarnLog(...log: any[]): Promise<void> {
1081
- if (this.enablingDeviceLogging()) {
1082
- if (this.deviceLogging?.includes('debug')) {
1083
- this.platform.log.warn('[DEBUG]', String(...log));
1084
- }
1085
- }
1086
- }
1087
-
1088
- async errorLog(...log: any[]): Promise<void> {
1089
- if (this.enablingDeviceLogging()) {
1090
- this.platform.log.error(String(...log));
1091
- }
1092
- }
1093
-
1094
- async debugErrorLog(...log: any[]): Promise<void> {
1095
- if (this.enablingDeviceLogging()) {
1096
- if (this.deviceLogging?.includes('debug')) {
1097
- this.platform.log.error('[DEBUG]', String(...log));
1098
- }
1099
- }
1100
- }
1101
-
1102
- async debugLog(...log: any[]): Promise<void> {
1103
- if (this.enablingDeviceLogging()) {
1104
- if (this.deviceLogging === 'debug') {
1105
- this.platform.log.info('[DEBUG]', String(...log));
1106
- } else {
1107
- this.platform.log.debug(String(...log));
1108
- }
1109
- }
1110
- }
1111
-
1112
- enablingDeviceLogging(): boolean {
1113
- return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
1114
734
  }
1115
735
  }