@switchbot/homebridge-switchbot 3.5.0-beta.23 → 3.5.0-beta.24

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