homebridge-midea-platform 1.2.0-beta.7 → 1.2.1

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 (168) hide show
  1. package/CHANGELOG.md +7 -2
  2. package/README.md +2 -2
  3. package/config.schema.json +1 -1
  4. package/dist/accessory/AccessoryFactory.d.ts +14 -15
  5. package/dist/accessory/AccessoryFactory.js +34 -40
  6. package/dist/accessory/AccessoryFactory.js.map +1 -1
  7. package/dist/accessory/AirConditionerAccessory.d.ts +98 -99
  8. package/dist/accessory/AirConditionerAccessory.js +666 -662
  9. package/dist/accessory/AirConditionerAccessory.js.map +1 -1
  10. package/dist/accessory/BaseAccessory.d.ts +11 -12
  11. package/dist/accessory/BaseAccessory.js +21 -21
  12. package/dist/accessory/BaseAccessory.js.map +1 -1
  13. package/dist/accessory/DehumidifierAccessory.d.ts +45 -46
  14. package/dist/accessory/DehumidifierAccessory.js +343 -344
  15. package/dist/accessory/DehumidifierAccessory.js.map +1 -1
  16. package/dist/accessory/DishwasherAccessory.d.ts +30 -31
  17. package/dist/accessory/DishwasherAccessory.js +59 -63
  18. package/dist/accessory/DishwasherAccessory.js.map +1 -1
  19. package/dist/accessory/ElectricWaterHeaterAccessory.d.ts +44 -45
  20. package/dist/accessory/ElectricWaterHeaterAccessory.js +172 -176
  21. package/dist/accessory/ElectricWaterHeaterAccessory.js.map +1 -1
  22. package/dist/accessory/FanAccessory.d.ts +39 -40
  23. package/dist/accessory/FanAccessory.js +120 -123
  24. package/dist/accessory/FanAccessory.js.map +1 -1
  25. package/dist/accessory/FrontLoadWasherAccessory.d.ts +30 -31
  26. package/dist/accessory/FrontLoadWasherAccessory.js +63 -66
  27. package/dist/accessory/FrontLoadWasherAccessory.js.map +1 -1
  28. package/dist/accessory/GasWaterHeaterAccessory.d.ts +51 -52
  29. package/dist/accessory/GasWaterHeaterAccessory.js +217 -216
  30. package/dist/accessory/GasWaterHeaterAccessory.js.map +1 -1
  31. package/dist/accessory/{HeatPumpWifiControllerAccessory.d.ts → HeatPumpWiFiControllerAccessory.d.ts} +34 -35
  32. package/dist/accessory/{HeatPumpWifiControllerAccessory.js → HeatPumpWiFiControllerAccessory.js} +55 -36
  33. package/dist/accessory/HeatPumpWiFiControllerAccessory.js.map +1 -0
  34. package/dist/core/MideaCloud.d.ts +34 -36
  35. package/dist/core/MideaCloud.js +349 -350
  36. package/dist/core/MideaCloud.js.map +1 -1
  37. package/dist/core/MideaConstants.d.ts +51 -52
  38. package/dist/core/MideaConstants.js +56 -59
  39. package/dist/core/MideaConstants.js.map +1 -1
  40. package/dist/core/MideaDevice.d.ts +75 -78
  41. package/dist/core/MideaDevice.js +430 -420
  42. package/dist/core/MideaDevice.js.map +1 -1
  43. package/dist/core/MideaDiscover.d.ts +34 -36
  44. package/dist/core/MideaDiscover.js +208 -212
  45. package/dist/core/MideaDiscover.js.map +1 -1
  46. package/dist/core/MideaMessage.d.ts +75 -76
  47. package/dist/core/MideaMessage.js +185 -184
  48. package/dist/core/MideaMessage.js.map +1 -1
  49. package/dist/core/MideaPacketBuilder.d.ts +9 -11
  50. package/dist/core/MideaPacketBuilder.js +60 -60
  51. package/dist/core/MideaPacketBuilder.js.map +1 -1
  52. package/dist/core/MideaSecurity.d.ts +62 -64
  53. package/dist/core/MideaSecurity.js +241 -251
  54. package/dist/core/MideaSecurity.js.map +1 -1
  55. package/dist/core/MideaUtils.d.ts +31 -33
  56. package/dist/core/MideaUtils.js +178 -181
  57. package/dist/core/MideaUtils.js.map +1 -1
  58. package/dist/devices/DeviceFactory.d.ts +14 -15
  59. package/dist/devices/DeviceFactory.js +34 -40
  60. package/dist/devices/DeviceFactory.js.map +1 -1
  61. package/dist/devices/a1/MideaA1Device.d.ts +75 -77
  62. package/dist/devices/a1/MideaA1Device.js +142 -145
  63. package/dist/devices/a1/MideaA1Device.js.map +1 -1
  64. package/dist/devices/a1/MideaA1Message.d.ts +39 -41
  65. package/dist/devices/a1/MideaA1Message.js +219 -198
  66. package/dist/devices/a1/MideaA1Message.js.map +1 -1
  67. package/dist/devices/ac/MideaACDevice.d.ts +105 -107
  68. package/dist/devices/ac/MideaACDevice.js +417 -400
  69. package/dist/devices/ac/MideaACDevice.js.map +1 -1
  70. package/dist/devices/ac/MideaACMessage.d.ts +97 -96
  71. package/dist/devices/ac/MideaACMessage.js +724 -621
  72. package/dist/devices/ac/MideaACMessage.js.map +1 -1
  73. package/dist/devices/c3/MideaC3Device.d.ts +73 -75
  74. package/dist/devices/c3/MideaC3Device.js +249 -255
  75. package/dist/devices/c3/MideaC3Device.js.map +1 -1
  76. package/dist/devices/c3/MideaC3Message.d.ts +81 -80
  77. package/dist/devices/c3/MideaC3Message.js +190 -152
  78. package/dist/devices/c3/MideaC3Message.js.map +1 -1
  79. package/dist/devices/db/MideaDBDevice.d.ts +28 -30
  80. package/dist/devices/db/MideaDBDevice.js +94 -100
  81. package/dist/devices/db/MideaDBDevice.js.map +1 -1
  82. package/dist/devices/db/MideaDBMessage.d.ts +31 -33
  83. package/dist/devices/db/MideaDBMessage.js +101 -101
  84. package/dist/devices/db/MideaDBMessage.js.map +1 -1
  85. package/dist/devices/e1/MideaE1Device.d.ts +55 -57
  86. package/dist/devices/e1/MideaE1Device.js +122 -128
  87. package/dist/devices/e1/MideaE1Device.js.map +1 -1
  88. package/dist/devices/e1/MideaE1Message.d.ts +27 -29
  89. package/dist/devices/e1/MideaE1Message.js +128 -107
  90. package/dist/devices/e1/MideaE1Message.js.map +1 -1
  91. package/dist/devices/e2/MideaE2Device.d.ts +43 -45
  92. package/dist/devices/e2/MideaE2Device.js +124 -129
  93. package/dist/devices/e2/MideaE2Device.js.map +1 -1
  94. package/dist/devices/e2/MideaE2Message.d.ts +34 -34
  95. package/dist/devices/e2/MideaE2Message.js +143 -132
  96. package/dist/devices/e2/MideaE2Message.js.map +1 -1
  97. package/dist/devices/e3/MideaE3Device.d.ts +42 -44
  98. package/dist/devices/e3/MideaE3Device.js +132 -137
  99. package/dist/devices/e3/MideaE3Device.js.map +1 -1
  100. package/dist/devices/e3/MideaE3Message.d.ts +51 -52
  101. package/dist/devices/e3/MideaE3Message.js +144 -136
  102. package/dist/devices/e3/MideaE3Message.js.map +1 -1
  103. package/dist/devices/fa/MideaFADevice.d.ts +35 -37
  104. package/dist/devices/fa/MideaFADevice.js +102 -106
  105. package/dist/devices/fa/MideaFADevice.js.map +1 -1
  106. package/dist/devices/fa/MideaFAMessage.d.ts +38 -39
  107. package/dist/devices/fa/MideaFAMessage.js +108 -98
  108. package/dist/devices/fa/MideaFAMessage.js.map +1 -1
  109. package/dist/index.d.ts +6 -7
  110. package/dist/index.js +8 -6
  111. package/dist/index.js.map +1 -1
  112. package/dist/platform.d.ts +61 -61
  113. package/dist/platform.js +232 -212
  114. package/dist/platform.js.map +1 -1
  115. package/dist/platformUtils.d.ts +116 -117
  116. package/dist/platformUtils.js +107 -110
  117. package/dist/platformUtils.js.map +1 -1
  118. package/dist/settings.d.ts +8 -9
  119. package/dist/settings.js +8 -11
  120. package/dist/settings.js.map +1 -1
  121. package/docs/download_lua.md +9 -0
  122. package/eslint.config.js +43 -0
  123. package/homebridge-ui/public/js/bootstrap.min.js +1179 -1
  124. package/homebridge-ui/{server.js → server.cjs} +30 -30
  125. package/package.json +21 -31
  126. package/.eslintignore +0 -3
  127. package/.husky/pre-commit +0 -5
  128. package/.prettierrc +0 -19
  129. package/dist/accessory/AccessoryFactory.d.ts.map +0 -1
  130. package/dist/accessory/AirConditionerAccessory.d.ts.map +0 -1
  131. package/dist/accessory/BaseAccessory.d.ts.map +0 -1
  132. package/dist/accessory/DehumidifierAccessory.d.ts.map +0 -1
  133. package/dist/accessory/DishwasherAccessory.d.ts.map +0 -1
  134. package/dist/accessory/ElectricWaterHeaterAccessory.d.ts.map +0 -1
  135. package/dist/accessory/FanAccessory.d.ts.map +0 -1
  136. package/dist/accessory/FrontLoadWasherAccessory.d.ts.map +0 -1
  137. package/dist/accessory/GasWaterHeaterAccessory.d.ts.map +0 -1
  138. package/dist/accessory/HeatPumpWifiControllerAccessory.d.ts.map +0 -1
  139. package/dist/accessory/HeatPumpWifiControllerAccessory.js.map +0 -1
  140. package/dist/core/MideaCloud.d.ts.map +0 -1
  141. package/dist/core/MideaConstants.d.ts.map +0 -1
  142. package/dist/core/MideaDevice.d.ts.map +0 -1
  143. package/dist/core/MideaDiscover.d.ts.map +0 -1
  144. package/dist/core/MideaMessage.d.ts.map +0 -1
  145. package/dist/core/MideaPacketBuilder.d.ts.map +0 -1
  146. package/dist/core/MideaSecurity.d.ts.map +0 -1
  147. package/dist/core/MideaUtils.d.ts.map +0 -1
  148. package/dist/devices/DeviceFactory.d.ts.map +0 -1
  149. package/dist/devices/a1/MideaA1Device.d.ts.map +0 -1
  150. package/dist/devices/a1/MideaA1Message.d.ts.map +0 -1
  151. package/dist/devices/ac/MideaACDevice.d.ts.map +0 -1
  152. package/dist/devices/ac/MideaACMessage.d.ts.map +0 -1
  153. package/dist/devices/c3/MideaC3Device.d.ts.map +0 -1
  154. package/dist/devices/c3/MideaC3Message.d.ts.map +0 -1
  155. package/dist/devices/db/MideaDBDevice.d.ts.map +0 -1
  156. package/dist/devices/db/MideaDBMessage.d.ts.map +0 -1
  157. package/dist/devices/e1/MideaE1Device.d.ts.map +0 -1
  158. package/dist/devices/e1/MideaE1Message.d.ts.map +0 -1
  159. package/dist/devices/e2/MideaE2Device.d.ts.map +0 -1
  160. package/dist/devices/e2/MideaE2Message.d.ts.map +0 -1
  161. package/dist/devices/e3/MideaE3Device.d.ts.map +0 -1
  162. package/dist/devices/e3/MideaE3Message.d.ts.map +0 -1
  163. package/dist/devices/fa/MideaFADevice.d.ts.map +0 -1
  164. package/dist/devices/fa/MideaFAMessage.d.ts.map +0 -1
  165. package/dist/index.d.ts.map +0 -1
  166. package/dist/platform.d.ts.map +0 -1
  167. package/dist/platformUtils.d.ts.map +0 -1
  168. package/dist/settings.d.ts.map +0 -1
@@ -1,347 +1,346 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
7
- const platformUtils_1 = require("../platformUtils");
8
- class DehumidifierAccessory extends BaseAccessory_1.default {
9
- /*********************************************************************
10
- * Constructor registers all the service types with Homebridge, registers
11
- * a callback function with the MideaDevice class, and requests device status.
12
- */
13
- constructor(platform, accessory, device, configDev) {
14
- var _a, _b, _c, _d, _e, _f, _g;
15
- super(platform, accessory, device, configDev);
16
- this.device = device;
17
- this.configDev = configDev;
18
- // Increment this every time we make a change to accessory that requires
19
- // previously cached Homebridge service to be deleted/replaced.
20
- this.serviceVersion = 1;
21
- this.platform.log.debug(`[${device.name}] Dehumidifier serviceVersion: ${this.serviceVersion}, currentVersion: ${this.accessory.context.serviceVersion}`);
22
- const service = this.accessory.getService(this.platform.Service.HumidifierDehumidifier);
23
- if (service && this.accessory.context.serviceVersion !== this.serviceVersion) {
1
+ import BaseAccessory from './BaseAccessory.js';
2
+ import { WaterTankSensor } from '../platformUtils.js';
3
+ export default class DehumidifierAccessory extends BaseAccessory {
4
+ device;
5
+ configDev;
6
+ service;
7
+ temperatureService;
8
+ fanService;
9
+ humiditySensorService;
10
+ pumpService;
11
+ waterTankService;
12
+ // Increment this every time we make a change to accessory that requires
13
+ // previously cached Homebridge service to be deleted/replaced.
14
+ serviceVersion = 1;
15
+ /*********************************************************************
16
+ * Constructor registers all the service types with Homebridge, registers
17
+ * a callback function with the MideaDevice class, and requests device status.
18
+ */
19
+ constructor(platform, accessory, device, configDev) {
20
+ super(platform, accessory, device, configDev);
21
+ this.device = device;
22
+ this.configDev = configDev;
23
+ this.platform.log.debug(`[${device.name}] Dehumidifier serviceVersion: ${this.serviceVersion}, currentVersion: ${this.accessory.context.serviceVersion}`);
24
+ const service = this.accessory.getService(this.platform.Service.HumidifierDehumidifier);
25
+ if (service && this.accessory.context.serviceVersion !== this.serviceVersion) {
24
26
  this.platform.log.info(`[${this.device.name}] New dehumidifier service version.\
25
- Upgrade from v${this.accessory.context.serviceVersion} to v${this.serviceVersion}.`);
26
- this.accessory.removeService(service);
27
- this.service = this.accessory.addService(this.platform.Service.HumidifierDehumidifier);
28
- this.accessory.context.serviceVersion = this.serviceVersion;
29
- }
30
- else if (service) {
31
- this.platform.log.debug(`[${this.device.name}] Existing dehumidifier service version.`);
32
- this.service = service;
33
- }
34
- else {
35
- this.platform.log.debug(`[${this.device.name}] Creating new dehumidifier service.`);
36
- this.service = this.accessory.addService(this.platform.Service.HumidifierDehumidifier);
37
- this.accessory.context.serviceVersion = this.serviceVersion;
38
- }
39
- this.service.setCharacteristic(this.platform.Characteristic.Name, this.device.name);
40
- this.service.getCharacteristic(this.platform.Characteristic.Active).onGet(this.getActive.bind(this)).onSet(this.setActive.bind(this));
41
- this.service
42
- .getCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState)
43
- .onGet(this.getCurrentHumidifierDehumidifierState.bind(this));
44
- // need to set as dehumidifier before setting validValues as defult of 0 will
45
- // throw error when we state that only valid value is dehumidifier (2).
46
- this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.platform.Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER);
47
- this.service
48
- .getCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState)
49
- .onGet(this.getTargetHumidifierDehumidifierState.bind(this))
50
- .onSet(this.setTargetHumidifierDehumidifierState.bind(this))
51
- .setProps({
52
- validValues: [this.platform.Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER],
53
- });
54
- this.service
55
- .getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity)
56
- .onGet(this.getCurrentRelativeHumidity.bind(this))
57
- .setProps({
58
- minValue: 0,
59
- maxValue: 100,
60
- minStep: 1,
61
- });
62
- this.service
63
- .getCharacteristic(this.platform.Characteristic.RelativeHumidityDehumidifierThreshold)
64
- .onGet(this.getRelativeHumidityDehumidifierThreshold.bind(this))
65
- .onSet(this.setRelativeHumidityDehumidifierThreshold.bind(this))
66
- .setProps({
67
- minValue: 0,
68
- maxValue: 100,
69
- minStep: 5,
70
- });
71
- this.service
72
- .getCharacteristic(this.platform.Characteristic.RotationSpeed)
73
- .onGet(this.getRotationSpeed.bind(this))
74
- .onSet(this.setRotationSpeed.bind(this));
75
- this.service.getCharacteristic(this.platform.Characteristic.WaterLevel).onGet(this.getWaterLevel.bind(this));
76
- // Temperature sensor
77
- this.temperatureService = this.accessory.getServiceById(this.platform.Service.TemperatureSensor, 'Temperature');
78
- if (this.configDev.A1_options.temperatureSensor) {
79
- (_a = this.temperatureService) !== null && _a !== void 0 ? _a : (this.temperatureService = this.accessory.addService(this.platform.Service.TemperatureSensor, 'Temperature', 'Temperature'));
80
- this.temperatureService.getCharacteristic(this.platform.Characteristic.CurrentTemperature).onGet(this.getTemperature.bind(this));
81
- }
82
- else if (this.temperatureService) {
83
- this.accessory.removeService(this.temperatureService);
84
- }
85
- // Fan
86
- this.fanService = this.accessory.getServiceById(this.platform.Service.Fanv2, 'Fan');
87
- if (this.configDev.A1_options.fanAccessory) {
88
- (_b = this.fanService) !== null && _b !== void 0 ? _b : (this.fanService = this.accessory.addService(this.platform.Service.Fanv2, 'Fan', 'Fan'));
89
- this.fanService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Fan`);
90
- this.fanService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Fan`);
91
- this.fanService
92
- .getCharacteristic(this.platform.Characteristic.Active)
93
- .onGet(this.getActive.bind(this))
94
- .onSet(this.setActive.bind(this));
95
- this.fanService
96
- .getCharacteristic(this.platform.Characteristic.RotationSpeed)
97
- .onGet(this.getRotationSpeed.bind(this))
98
- .onSet(this.setRotationSpeed.bind(this));
99
- }
100
- else if (this.fanService) {
101
- this.accessory.removeService(this.fanService);
102
- }
103
- // Humidity sensor
104
- this.humiditySensorService = this.accessory.getServiceById(this.platform.Service.HumiditySensor, 'Humidity');
105
- if (this.configDev.A1_options.humiditySensor) {
106
- (_c = this.humiditySensorService) !== null && _c !== void 0 ? _c : (this.humiditySensorService = this.accessory.addService(this.platform.Service.HumiditySensor, 'Humidity', 'Humidity'));
107
- this.humiditySensorService
108
- .getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity)
109
- .onGet(this.getCurrentRelativeHumidity.bind(this));
110
- }
111
- else if (this.humiditySensorService) {
112
- this.accessory.removeService(this.humiditySensorService);
113
- }
114
- // Pump switch
115
- this.pumpService = this.accessory.getServiceById(this.platform.Service.Switch, 'Pump');
116
- if (this.configDev.A1_options.pumpSwitch) {
117
- (_d = this.pumpService) !== null && _d !== void 0 ? _d : (this.pumpService = this.accessory.addService(this.platform.Service.Switch, 'Pump', 'Pump'));
118
- this.pumpService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Pump`);
119
- this.pumpService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Pump`);
120
- this.pumpService.getCharacteristic(this.platform.Characteristic.On).onGet(this.getPump.bind(this)).onSet(this.setPump.bind(this));
121
- }
122
- else if (this.pumpService) {
123
- this.accessory.removeService(this.pumpService);
124
- }
125
- this.waterTankService =
126
- (_e = this.accessory.getServiceById(this.platform.Service.ContactSensor, 'WaterTankContact')) !== null && _e !== void 0 ? _e : this.accessory.getServiceById(this.platform.Service.LeakSensor, 'WaterTankLeak');
127
- if (this.configDev.A1_options.waterTankSensor !== platformUtils_1.WaterTankSensor.NONE) {
128
- if (this.configDev.A1_options.waterTankSensor === platformUtils_1.WaterTankSensor.CONTACT_SENSOR) {
129
- (_f = this.waterTankService) !== null && _f !== void 0 ? _f : (this.waterTankService = this.accessory.addService(this.platform.Service.ContactSensor, `${this.device.name} Water Tank Sensor`, 'WaterTankContact'));
130
- this.waterTankService.getCharacteristic(this.platform.Characteristic.ContactSensorState).onGet(this.getWaterTankFull.bind(this));
131
- }
132
- else {
133
- (_g = this.waterTankService) !== null && _g !== void 0 ? _g : (this.waterTankService = this.accessory.addService(this.platform.Service.LeakSensor, `${this.device.name} Water Tank Sensor`, 'WaterTankLeak'));
134
- this.waterTankService.getCharacteristic(this.platform.Characteristic.LeakDetected).onGet(this.getWaterTankFull.bind(this));
135
- }
136
- this.waterTankService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Water Tank Sensor`);
137
- this.waterTankService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Water Tank Sensor`);
138
- }
139
- else if (this.waterTankService) {
140
- this.accessory.removeService(this.waterTankService);
141
- }
142
- }
143
- /*********************************************************************
144
- * Callback function called by MideaDevice whenever there is a change to
145
- * any attribute value.
146
- */
147
- async updateCharacteristics(attributes) {
148
- var _a, _b, _c, _d, _e, _f, _g;
149
- for (const [k, v] of Object.entries(attributes)) {
150
- this.platform.log.debug(`[${this.device.name}] Set attribute ${k} to: ${v}`);
151
- let updateState = false;
152
- switch (k.toLowerCase()) {
153
- case 'power':
154
- updateState = true;
155
- break;
156
- case 'target_humidity':
157
- this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityDehumidifierThreshold, v);
158
- updateState = true;
159
- break;
160
- case 'fan_speed':
161
- this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, v);
162
- (_a = this.fanService) === null || _a === void 0 ? void 0 : _a.updateCharacteristic(this.platform.Characteristic.RotationSpeed, v);
163
- updateState = true;
164
- break;
165
- case 'current_humidity':
166
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, v);
167
- (_b = this.humiditySensorService) === null || _b === void 0 ? void 0 : _b.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, v);
168
- updateState = true;
169
- break;
170
- case 'mode':
171
- updateState = true;
172
- break;
173
- case 'current_temperature':
174
- (_c = this.temperatureService) === null || _c === void 0 ? void 0 : _c.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, v);
175
- break;
176
- case 'tank_level':
177
- this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, v);
178
- break;
179
- case 'pump':
180
- (_d = this.pumpService) === null || _d === void 0 ? void 0 : _d.updateCharacteristic(this.platform.Characteristic.On, v);
181
- break;
182
- case 'tank_full':
183
- if (this.configDev.A1_options.waterTankSensor === platformUtils_1.WaterTankSensor.LEAK_SENSOR) {
184
- (_e = this.waterTankService) === null || _e === void 0 ? void 0 : _e.updateCharacteristic(this.platform.Characteristic.LeakDetected, v);
185
- }
186
- else if (this.configDev.A1_options.waterTankSensor === platformUtils_1.WaterTankSensor.CONTACT_SENSOR) {
187
- (_f = this.waterTankService) === null || _f === void 0 ? void 0 : _f.updateCharacteristic(this.platform.Characteristic.ContactSensorState, v);
188
- }
189
- break;
190
- case 'water_level_set':
191
- // No HomeKit characteristic
192
- break;
193
- case 'swing':
194
- // No HomeKit characteristic
195
- break;
196
- case 'child_lock':
197
- // No HomeKit characteristic
198
- break;
199
- default:
200
- this.platform.log.debug(`[${this.device.name}] Attempt to set unsupported attribute ${k} to ${v}`);
201
- }
202
- if (updateState) {
203
- this.service.updateCharacteristic(this.platform.Characteristic.Active, this.getActive());
204
- this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.platform.Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER);
205
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.currentHumidifierDehumidifierState());
206
- (_g = this.fanService) === null || _g === void 0 ? void 0 : _g.updateCharacteristic(this.platform.Characteristic.Active, this.getActive());
207
- }
208
- }
209
- }
210
- /*********************************************************************
211
- * Callback functions for each Homebridge/HomeKit service
212
- *
213
- */
214
- getActive() {
215
- this.platform.log.debug(`[${this.device.name}] GET Active, value: ${this.device.attributes.POWER}`);
216
- return this.device.attributes.POWER ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE;
217
- }
218
- async setActive(value) {
219
- this.platform.log.debug(`[${this.device.name}] SET Active to: ${value}`);
220
- await this.device.set_attribute({ POWER: !!value });
221
- }
222
- // Handle requests to get the current value of the "HumidifierDehumidifierState" characteristic
223
- getCurrentHumidifierDehumidifierState() {
224
- this.platform.log.debug(`[${this.device.name}] GET CurrentHumidifierDehumidifierState, value: ${this.device.attributes.POWER},${this.device.attributes.MODE}`);
225
- return this.currentHumidifierDehumidifierState();
226
- }
227
- currentHumidifierDehumidifierState() {
228
- if (!this.device.attributes.POWER) {
229
- // Powered off, must be inactive
230
- return this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
231
- }
232
- else {
233
- // Powered on, check mode
234
- if (this.device.attributes.MODE >= 2) {
235
- // Dehumidifying
236
- return this.platform.Characteristic.CurrentHumidifierDehumidifierState.DEHUMIDIFYING;
237
- }
238
- else if (this.device.attributes.MODE === 1) {
239
- // Whether deumidifying depends on whether we have reached target. This is not
240
- // always accurate, but is best we can do to signal whether actively dehumidifing or not.
241
- if (this.device.attributes.CURRENT_HUMIDITY < this.device.attributes.TARGET_HUMIDITY) {
242
- return this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
243
- }
244
- else {
245
- return this.platform.Characteristic.CurrentHumidifierDehumidifierState.DEHUMIDIFYING;
246
- }
247
- }
248
- return this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
249
- }
250
- }
251
- // Handle requests to get the target value of the "HumidifierDehumidifierState" characteristic
252
- getTargetHumidifierDehumidifierState() {
253
- this.platform.log.debug(
254
- // eslint-disable-next-line max-len
255
- `[${this.device.name}] GET TargetHumidifierDehumidifierState, value: ${this.platform.Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER}`);
256
- // Always return that we are a dehumidifier, other states not supported.
257
- return this.platform.Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER;
258
- }
259
- // Handle requests to set the target value of the "HumidifierDehumidifierState" characteristic
260
- async setTargetHumidifierDehumidifierState(value) {
261
- this.platform.log.debug(`[${this.device.name}] SET TargetHumidifierDehumidifierState to: ${value}`);
262
- if (value !== this.platform.Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER) {
263
- throw new Error(`Device ${this.device.name} (${this.device.id}) can only be a Dehumidifier, illegal value: ${value}`);
264
- }
265
- }
266
- // Handle requests to get the current value of the "RelativeHumidity" characteristic
267
- getCurrentRelativeHumidity() {
27
+ Upgrade from v${this.accessory.context.serviceVersion} to v${this.serviceVersion}.`);
28
+ this.accessory.removeService(service);
29
+ this.service = this.accessory.addService(this.platform.Service.HumidifierDehumidifier);
30
+ this.accessory.context.serviceVersion = this.serviceVersion;
31
+ }
32
+ else if (service) {
33
+ this.platform.log.debug(`[${this.device.name}] Existing dehumidifier service version.`);
34
+ this.service = service;
35
+ }
36
+ else {
37
+ this.platform.log.debug(`[${this.device.name}] Creating new dehumidifier service.`);
38
+ this.service = this.accessory.addService(this.platform.Service.HumidifierDehumidifier);
39
+ this.accessory.context.serviceVersion = this.serviceVersion;
40
+ }
41
+ this.service.setCharacteristic(this.platform.Characteristic.Name, this.device.name);
42
+ this.service.getCharacteristic(this.platform.Characteristic.Active).onGet(this.getActive.bind(this)).onSet(this.setActive.bind(this));
43
+ this.service
44
+ .getCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState)
45
+ .onGet(this.getCurrentHumidifierDehumidifierState.bind(this));
46
+ // need to set as dehumidifier before setting validValues as defult of 0 will
47
+ // throw error when we state that only valid value is dehumidifier (2).
48
+ this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.platform.Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER);
49
+ this.service
50
+ .getCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState)
51
+ .onGet(this.getTargetHumidifierDehumidifierState.bind(this))
52
+ .onSet(this.setTargetHumidifierDehumidifierState.bind(this))
53
+ .setProps({
54
+ validValues: [this.platform.Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER],
55
+ });
56
+ this.service
57
+ .getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity)
58
+ .onGet(this.getCurrentRelativeHumidity.bind(this))
59
+ .setProps({
60
+ minValue: 0,
61
+ maxValue: 100,
62
+ minStep: 1,
63
+ });
64
+ this.service
65
+ .getCharacteristic(this.platform.Characteristic.RelativeHumidityDehumidifierThreshold)
66
+ .onGet(this.getRelativeHumidityDehumidifierThreshold.bind(this))
67
+ .onSet(this.setRelativeHumidityDehumidifierThreshold.bind(this))
68
+ .setProps({
69
+ minValue: 0, // need this to be 0..100 so that Apple Home User Inteface humidity percent matched
70
+ maxValue: 100, // what we set to the himdifier. If we have this as 35..85 then Apple Home UI will not match.
71
+ minStep: 5,
72
+ });
73
+ this.service
74
+ .getCharacteristic(this.platform.Characteristic.RotationSpeed)
75
+ .onGet(this.getRotationSpeed.bind(this))
76
+ .onSet(this.setRotationSpeed.bind(this));
77
+ this.service.getCharacteristic(this.platform.Characteristic.WaterLevel).onGet(this.getWaterLevel.bind(this));
78
+ // Temperature sensor
79
+ this.temperatureService = this.accessory.getServiceById(this.platform.Service.TemperatureSensor, 'Temperature');
80
+ if (this.configDev.A1_options.temperatureSensor) {
81
+ this.temperatureService ??= this.accessory.addService(this.platform.Service.TemperatureSensor, 'Temperature', 'Temperature');
82
+ this.temperatureService.getCharacteristic(this.platform.Characteristic.CurrentTemperature).onGet(this.getTemperature.bind(this));
83
+ }
84
+ else if (this.temperatureService) {
85
+ this.accessory.removeService(this.temperatureService);
86
+ }
87
+ // Fan
88
+ this.fanService = this.accessory.getServiceById(this.platform.Service.Fanv2, 'Fan');
89
+ if (this.configDev.A1_options.fanAccessory) {
90
+ this.fanService ??= this.accessory.addService(this.platform.Service.Fanv2, 'Fan', 'Fan');
91
+ this.fanService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Fan`);
92
+ this.fanService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Fan`);
93
+ this.fanService
94
+ .getCharacteristic(this.platform.Characteristic.Active)
95
+ .onGet(this.getActive.bind(this))
96
+ .onSet(this.setActive.bind(this));
97
+ this.fanService
98
+ .getCharacteristic(this.platform.Characteristic.RotationSpeed)
99
+ .onGet(this.getRotationSpeed.bind(this))
100
+ .onSet(this.setRotationSpeed.bind(this));
101
+ }
102
+ else if (this.fanService) {
103
+ this.accessory.removeService(this.fanService);
104
+ }
105
+ // Humidity sensor
106
+ this.humiditySensorService = this.accessory.getServiceById(this.platform.Service.HumiditySensor, 'Humidity');
107
+ if (this.configDev.A1_options.humiditySensor) {
108
+ this.humiditySensorService ??= this.accessory.addService(this.platform.Service.HumiditySensor, 'Humidity', 'Humidity');
109
+ this.humiditySensorService
110
+ .getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity)
111
+ .onGet(this.getCurrentRelativeHumidity.bind(this));
112
+ }
113
+ else if (this.humiditySensorService) {
114
+ this.accessory.removeService(this.humiditySensorService);
115
+ }
116
+ // Pump switch
117
+ this.pumpService = this.accessory.getServiceById(this.platform.Service.Switch, 'Pump');
118
+ if (this.configDev.A1_options.pumpSwitch) {
119
+ this.pumpService ??= this.accessory.addService(this.platform.Service.Switch, 'Pump', 'Pump');
120
+ this.pumpService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Pump`);
121
+ this.pumpService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Pump`);
122
+ this.pumpService.getCharacteristic(this.platform.Characteristic.On).onGet(this.getPump.bind(this)).onSet(this.setPump.bind(this));
123
+ }
124
+ else if (this.pumpService) {
125
+ this.accessory.removeService(this.pumpService);
126
+ }
127
+ this.waterTankService =
128
+ this.accessory.getServiceById(this.platform.Service.ContactSensor, 'WaterTankContact') ??
129
+ this.accessory.getServiceById(this.platform.Service.LeakSensor, 'WaterTankLeak');
130
+ if (this.configDev.A1_options.waterTankSensor !== WaterTankSensor.NONE) {
131
+ if (this.configDev.A1_options.waterTankSensor === WaterTankSensor.CONTACT_SENSOR) {
132
+ this.waterTankService ??= this.accessory.addService(this.platform.Service.ContactSensor, `${this.device.name} Water Tank Sensor`, 'WaterTankContact');
133
+ this.waterTankService.getCharacteristic(this.platform.Characteristic.ContactSensorState).onGet(this.getWaterTankFull.bind(this));
134
+ }
135
+ else {
136
+ this.waterTankService ??= this.accessory.addService(this.platform.Service.LeakSensor, `${this.device.name} Water Tank Sensor`, 'WaterTankLeak');
137
+ this.waterTankService.getCharacteristic(this.platform.Characteristic.LeakDetected).onGet(this.getWaterTankFull.bind(this));
138
+ }
139
+ this.waterTankService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Water Tank Sensor`);
140
+ this.waterTankService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Water Tank Sensor`);
141
+ }
142
+ else if (this.waterTankService) {
143
+ this.accessory.removeService(this.waterTankService);
144
+ }
145
+ }
146
+ /*********************************************************************
147
+ * Callback function called by MideaDevice whenever there is a change to
148
+ * any attribute value.
149
+ */
150
+ async updateCharacteristics(attributes) {
151
+ for (const [k, v] of Object.entries(attributes)) {
152
+ this.platform.log.debug(`[${this.device.name}] Set attribute ${k} to: ${v}`);
153
+ let updateState = false;
154
+ switch (k.toLowerCase()) {
155
+ case 'power':
156
+ updateState = true;
157
+ break;
158
+ case 'target_humidity':
159
+ this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityDehumidifierThreshold, v);
160
+ updateState = true;
161
+ break;
162
+ case 'fan_speed':
163
+ this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, v);
164
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, v);
165
+ updateState = true;
166
+ break;
167
+ case 'current_humidity':
168
+ this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, v);
169
+ this.humiditySensorService?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, v);
170
+ updateState = true;
171
+ break;
172
+ case 'mode':
173
+ updateState = true;
174
+ break;
175
+ case 'current_temperature':
176
+ this.temperatureService?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, v);
177
+ break;
178
+ case 'tank_level':
179
+ this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, v);
180
+ break;
181
+ case 'pump':
182
+ this.pumpService?.updateCharacteristic(this.platform.Characteristic.On, v);
183
+ break;
184
+ case 'tank_full':
185
+ if (this.configDev.A1_options.waterTankSensor === WaterTankSensor.LEAK_SENSOR) {
186
+ this.waterTankService?.updateCharacteristic(this.platform.Characteristic.LeakDetected, v);
187
+ }
188
+ else if (this.configDev.A1_options.waterTankSensor === WaterTankSensor.CONTACT_SENSOR) {
189
+ this.waterTankService?.updateCharacteristic(this.platform.Characteristic.ContactSensorState, v);
190
+ }
191
+ break;
192
+ case 'water_level_set':
193
+ // No HomeKit characteristic
194
+ break;
195
+ case 'swing':
196
+ // No HomeKit characteristic
197
+ break;
198
+ case 'child_lock':
199
+ // No HomeKit characteristic
200
+ break;
201
+ default:
202
+ this.platform.log.debug(`[${this.device.name}] Attempt to set unsupported attribute ${k} to ${v}`);
203
+ }
204
+ if (updateState) {
205
+ this.service.updateCharacteristic(this.platform.Characteristic.Active, this.getActive());
206
+ this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.platform.Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER);
207
+ this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.currentHumidifierDehumidifierState());
208
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.getActive());
209
+ }
210
+ }
211
+ }
212
+ /*********************************************************************
213
+ * Callback functions for each Homebridge/HomeKit service
214
+ *
215
+ */
216
+ getActive() {
217
+ this.platform.log.debug(`[${this.device.name}] GET Active, value: ${this.device.attributes.POWER}`);
218
+ return this.device.attributes.POWER ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE;
219
+ }
220
+ async setActive(value) {
221
+ this.platform.log.debug(`[${this.device.name}] SET Active to: ${value}`);
222
+ await this.device.set_attribute({ POWER: !!value });
223
+ }
224
+ // Handle requests to get the current value of the "HumidifierDehumidifierState" characteristic
225
+ getCurrentHumidifierDehumidifierState() {
226
+ this.platform.log.debug(`[${this.device.name}] GET CurrentHumidifierDehumidifierState, value: ${this.device.attributes.POWER},${this.device.attributes.MODE}`);
227
+ return this.currentHumidifierDehumidifierState();
228
+ }
229
+ currentHumidifierDehumidifierState() {
230
+ if (!this.device.attributes.POWER) {
231
+ // Powered off, must be inactive
232
+ return this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
233
+ }
234
+ else {
235
+ // Powered on, check mode
236
+ if (this.device.attributes.MODE >= 2) {
237
+ // Dehumidifying
238
+ return this.platform.Characteristic.CurrentHumidifierDehumidifierState.DEHUMIDIFYING;
239
+ }
240
+ else if (this.device.attributes.MODE === 1) {
241
+ // Whether deumidifying depends on whether we have reached target. This is not
242
+ // always accurate, but is best we can do to signal whether actively dehumidifing or not.
243
+ if (this.device.attributes.CURRENT_HUMIDITY < this.device.attributes.TARGET_HUMIDITY) {
244
+ return this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
245
+ }
246
+ else {
247
+ return this.platform.Characteristic.CurrentHumidifierDehumidifierState.DEHUMIDIFYING;
248
+ }
249
+ }
250
+ return this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
251
+ }
252
+ }
253
+ // Handle requests to get the target value of the "HumidifierDehumidifierState" characteristic
254
+ getTargetHumidifierDehumidifierState() {
255
+ this.platform.log.debug(`[${this.device.name}] GET TargetHumidifierDehumidifierState, value: ${this.platform.Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER}`);
256
+ // Always return that we are a dehumidifier, other states not supported.
257
+ return this.platform.Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER;
258
+ }
259
+ // Handle requests to set the target value of the "HumidifierDehumidifierState" characteristic
260
+ async setTargetHumidifierDehumidifierState(value) {
261
+ this.platform.log.debug(`[${this.device.name}] SET TargetHumidifierDehumidifierState to: ${value}`);
262
+ if (value !== this.platform.Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER) {
263
+ throw new Error(`Device ${this.device.name} (${this.device.id}) can only be a Dehumidifier, illegal value: ${value}`);
264
+ }
265
+ }
266
+ // Handle requests to get the current value of the "RelativeHumidity" characteristic
267
+ getCurrentRelativeHumidity() {
268
268
  this.platform.log.debug(`[${this.device.name}] GET CurrentRelativeHumidity, value: ${this.device.attributes.CURRENT_HUMIDITY},\
269
- custom offset: ${this.configDev.A1_options.humidityOffset}`);
270
- // Adding custom offset to the humidity value
271
- return this.device.attributes.CURRENT_HUMIDITY + this.configDev.A1_options.humidityOffset;
272
- }
273
- // Handle requests to get the Relative value of the "HumidityDehumidifierThreshold" characteristic
274
- getRelativeHumidityDehumidifierThreshold() {
275
- this.platform.log.debug(`[${this.device.name}] GET RelativeHumidityDehumidifierThreshold, value: ${this.device.attributes.TARGET_HUMIDITY}`);
276
- return this.device.attributes.TARGET_HUMIDITY;
277
- }
278
- // Handle requests to set the Relative value of the "HumidityDehumidifierThreshold" characteristic
279
- async setRelativeHumidityDehumidifierThreshold(value) {
280
- let RequestedHumidity = value;
281
- // valid humidity has to be between min and max values
282
- RequestedHumidity =
283
- RequestedHumidity < this.device.MIN_HUMIDITY
284
- ? this.device.MIN_HUMIDITY
285
- : RequestedHumidity > this.device.MAX_HUMIDITY
286
- ? this.device.MAX_HUMIDITY
287
- : RequestedHumidity;
288
- this.platform.log.debug(`[${this.device.name}] SET RelativeHumidityDehumidifierThreshold to: ${RequestedHumidity} (${value})`);
289
- await this.device.set_attribute({ TARGET_HUMIDITY: RequestedHumidity });
290
- // Update HomeKit in case we adjusted the value outside of min and max values
291
- if (RequestedHumidity !== value) {
292
- // We had to adjust the requested value to within permitted range... Update homekit to actual value set.
293
- // Calling updateCharacteristic within set handler seems to fail, new value is not accepted. Workaround is
294
- // to request the update after short delay (say 50ms) to allow homebridge/homekit to complete the set handler.
295
- setTimeout(() => {
296
- this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityDehumidifierThreshold, RequestedHumidity);
297
- }, 50);
298
- }
299
- }
300
- // Handle requests to get the current value of the "RotationSpeed" characteristic
301
- getRotationSpeed() {
302
- this.platform.log.debug(`[${this.device.name}] GET RotationSpeed, value: ${this.device.attributes.FAN_SPEED}`);
303
- return this.device.attributes.FAN_SPEED;
304
- }
305
- // Handle requests to set the "RotationSpeed" characteristic
306
- async setRotationSpeed(value) {
307
- let speed = value;
308
- speed = speed <= 40 ? 40 : speed > 40 && speed <= 60 ? 60 : 80;
309
- this.platform.log.debug(`[${this.device.name}] SET RotationSpeed to: ${speed} (${value})`);
310
- await this.device.set_attribute({ FAN_SPEED: speed });
311
- if (speed !== value) {
312
- // We had to adjust the requested value to within permitted range... Update homekit to actual value set.
313
- // Calling updateCharacteristic within set handler seems to fail, new value is not accepted. Workaround is
314
- // to request the update after short delay (say 50ms) to allow homebridge/homekit to complete the set handler.
315
- setTimeout(() => {
316
- this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, speed);
317
- }, 50);
318
- }
319
- }
320
- // Handle requests to get the current value of the "WaterLevel" characteristic
321
- getWaterLevel() {
322
- this.platform.log.debug(`[${this.device.name}] GET WaterLevel, value: ${this.device.attributes.TANK_LEVEL}`);
323
- return this.device.attributes.TANK_LEVEL;
324
- }
325
- // Handle requests to get the current value of the "Pump" characteristic
326
- getTemperature() {
327
- this.platform.log.debug(`[${this.device.name}] GET Temperature, value: ${this.device.attributes.CURRENT_TEMPERATURE}`);
328
- return this.device.attributes.CURRENT_TEMPERATURE;
329
- }
330
- // Handle requests to get the current value of the "Pump" characteristic
331
- getPump() {
332
- this.platform.log.debug(`[${this.device.name}] GET Pump, value: ${this.device.attributes.PUMP}`);
333
- return this.device.attributes.POWER === true && this.device.attributes.PUMP;
334
- }
335
- // Handle requests to set the "Pump" characteristic
336
- async setPump(value) {
337
- this.platform.log.debug(`[${this.device.name}] SET Pump to: ${value}`);
338
- await this.device.set_attribute({ PUMP: !!value });
339
- }
340
- // Handle requests to get the current value of the "WaterTankFull" characteristic
341
- getWaterTankFull() {
342
- this.platform.log.debug(`[${this.device.name}] GET WaterTankFull, value: ${this.device.attributes.TANK_FULL}`);
343
- return this.device.attributes.TANK_FULL;
344
- }
345
- }
346
- exports.default = DehumidifierAccessory;
269
+ custom offset: ${this.configDev.A1_options.humidityOffset}`);
270
+ // Adding custom offset to the humidity value
271
+ return this.device.attributes.CURRENT_HUMIDITY + this.configDev.A1_options.humidityOffset;
272
+ }
273
+ // Handle requests to get the Relative value of the "HumidityDehumidifierThreshold" characteristic
274
+ getRelativeHumidityDehumidifierThreshold() {
275
+ this.platform.log.debug(`[${this.device.name}] GET RelativeHumidityDehumidifierThreshold, value: ${this.device.attributes.TARGET_HUMIDITY}`);
276
+ return this.device.attributes.TARGET_HUMIDITY;
277
+ }
278
+ // Handle requests to set the Relative value of the "HumidityDehumidifierThreshold" characteristic
279
+ async setRelativeHumidityDehumidifierThreshold(value) {
280
+ let RequestedHumidity = value;
281
+ // valid humidity has to be between min and max values
282
+ RequestedHumidity =
283
+ RequestedHumidity < this.device.MIN_HUMIDITY
284
+ ? this.device.MIN_HUMIDITY
285
+ : RequestedHumidity > this.device.MAX_HUMIDITY
286
+ ? this.device.MAX_HUMIDITY
287
+ : RequestedHumidity;
288
+ this.platform.log.debug(`[${this.device.name}] SET RelativeHumidityDehumidifierThreshold to: ${RequestedHumidity} (${value})`);
289
+ await this.device.set_attribute({ TARGET_HUMIDITY: RequestedHumidity });
290
+ // Update HomeKit in case we adjusted the value outside of min and max values
291
+ if (RequestedHumidity !== value) {
292
+ // We had to adjust the requested value to within permitted range... Update homekit to actual value set.
293
+ // Calling updateCharacteristic within set handler seems to fail, new value is not accepted. Workaround is
294
+ // to request the update after short delay (say 50ms) to allow homebridge/homekit to complete the set handler.
295
+ setTimeout(() => {
296
+ this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityDehumidifierThreshold, RequestedHumidity);
297
+ }, 50);
298
+ }
299
+ }
300
+ // Handle requests to get the current value of the "RotationSpeed" characteristic
301
+ getRotationSpeed() {
302
+ this.platform.log.debug(`[${this.device.name}] GET RotationSpeed, value: ${this.device.attributes.FAN_SPEED}`);
303
+ return this.device.attributes.FAN_SPEED;
304
+ }
305
+ // Handle requests to set the "RotationSpeed" characteristic
306
+ async setRotationSpeed(value) {
307
+ let speed = value;
308
+ speed = speed <= 40 ? 40 : speed > 40 && speed <= 60 ? 60 : 80;
309
+ this.platform.log.debug(`[${this.device.name}] SET RotationSpeed to: ${speed} (${value})`);
310
+ await this.device.set_attribute({ FAN_SPEED: speed });
311
+ if (speed !== value) {
312
+ // We had to adjust the requested value to within permitted range... Update homekit to actual value set.
313
+ // Calling updateCharacteristic within set handler seems to fail, new value is not accepted. Workaround is
314
+ // to request the update after short delay (say 50ms) to allow homebridge/homekit to complete the set handler.
315
+ setTimeout(() => {
316
+ this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, speed);
317
+ }, 50);
318
+ }
319
+ }
320
+ // Handle requests to get the current value of the "WaterLevel" characteristic
321
+ getWaterLevel() {
322
+ this.platform.log.debug(`[${this.device.name}] GET WaterLevel, value: ${this.device.attributes.TANK_LEVEL}`);
323
+ return this.device.attributes.TANK_LEVEL;
324
+ }
325
+ // Handle requests to get the current value of the "Pump" characteristic
326
+ getTemperature() {
327
+ this.platform.log.debug(`[${this.device.name}] GET Temperature, value: ${this.device.attributes.CURRENT_TEMPERATURE}`);
328
+ return this.device.attributes.CURRENT_TEMPERATURE;
329
+ }
330
+ // Handle requests to get the current value of the "Pump" characteristic
331
+ getPump() {
332
+ this.platform.log.debug(`[${this.device.name}] GET Pump, value: ${this.device.attributes.PUMP}`);
333
+ return this.device.attributes.POWER === true && this.device.attributes.PUMP;
334
+ }
335
+ // Handle requests to set the "Pump" characteristic
336
+ async setPump(value) {
337
+ this.platform.log.debug(`[${this.device.name}] SET Pump to: ${value}`);
338
+ await this.device.set_attribute({ PUMP: !!value });
339
+ }
340
+ // Handle requests to get the current value of the "WaterTankFull" characteristic
341
+ getWaterTankFull() {
342
+ this.platform.log.debug(`[${this.device.name}] GET WaterTankFull, value: ${this.device.attributes.TANK_FULL}`);
343
+ return this.device.attributes.TANK_FULL;
344
+ }
345
+ }
347
346
  //# sourceMappingURL=DehumidifierAccessory.js.map