homebridge-midea-platform 1.2.0-beta.8 → 1.2.2

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 (167) hide show
  1. package/CHANGELOG.md +5 -2
  2. package/README.md +2 -2
  3. package/dist/accessory/AccessoryFactory.d.ts +14 -15
  4. package/dist/accessory/AccessoryFactory.js +34 -40
  5. package/dist/accessory/AccessoryFactory.js.map +1 -1
  6. package/dist/accessory/AirConditionerAccessory.d.ts +98 -99
  7. package/dist/accessory/AirConditionerAccessory.js +666 -662
  8. package/dist/accessory/AirConditionerAccessory.js.map +1 -1
  9. package/dist/accessory/BaseAccessory.d.ts +11 -12
  10. package/dist/accessory/BaseAccessory.js +21 -21
  11. package/dist/accessory/BaseAccessory.js.map +1 -1
  12. package/dist/accessory/DehumidifierAccessory.d.ts +45 -46
  13. package/dist/accessory/DehumidifierAccessory.js +343 -344
  14. package/dist/accessory/DehumidifierAccessory.js.map +1 -1
  15. package/dist/accessory/DishwasherAccessory.d.ts +30 -31
  16. package/dist/accessory/DishwasherAccessory.js +59 -63
  17. package/dist/accessory/DishwasherAccessory.js.map +1 -1
  18. package/dist/accessory/ElectricWaterHeaterAccessory.d.ts +44 -45
  19. package/dist/accessory/ElectricWaterHeaterAccessory.js +172 -176
  20. package/dist/accessory/ElectricWaterHeaterAccessory.js.map +1 -1
  21. package/dist/accessory/FanAccessory.d.ts +39 -40
  22. package/dist/accessory/FanAccessory.js +120 -123
  23. package/dist/accessory/FanAccessory.js.map +1 -1
  24. package/dist/accessory/FrontLoadWasherAccessory.d.ts +30 -31
  25. package/dist/accessory/FrontLoadWasherAccessory.js +63 -66
  26. package/dist/accessory/FrontLoadWasherAccessory.js.map +1 -1
  27. package/dist/accessory/GasWaterHeaterAccessory.d.ts +51 -52
  28. package/dist/accessory/GasWaterHeaterAccessory.js +217 -216
  29. package/dist/accessory/GasWaterHeaterAccessory.js.map +1 -1
  30. package/dist/accessory/{HeatPumpWifiControllerAccessory.d.ts → HeatPumpWiFiControllerAccessory.d.ts} +34 -35
  31. package/dist/accessory/{HeatPumpWifiControllerAccessory.js → HeatPumpWiFiControllerAccessory.js} +55 -36
  32. package/dist/accessory/HeatPumpWiFiControllerAccessory.js.map +1 -0
  33. package/dist/core/MideaCloud.d.ts +34 -36
  34. package/dist/core/MideaCloud.js +349 -350
  35. package/dist/core/MideaCloud.js.map +1 -1
  36. package/dist/core/MideaConstants.d.ts +51 -52
  37. package/dist/core/MideaConstants.js +56 -59
  38. package/dist/core/MideaConstants.js.map +1 -1
  39. package/dist/core/MideaDevice.d.ts +75 -78
  40. package/dist/core/MideaDevice.js +430 -420
  41. package/dist/core/MideaDevice.js.map +1 -1
  42. package/dist/core/MideaDiscover.d.ts +34 -36
  43. package/dist/core/MideaDiscover.js +208 -212
  44. package/dist/core/MideaDiscover.js.map +1 -1
  45. package/dist/core/MideaMessage.d.ts +75 -76
  46. package/dist/core/MideaMessage.js +185 -184
  47. package/dist/core/MideaMessage.js.map +1 -1
  48. package/dist/core/MideaPacketBuilder.d.ts +9 -11
  49. package/dist/core/MideaPacketBuilder.js +60 -60
  50. package/dist/core/MideaPacketBuilder.js.map +1 -1
  51. package/dist/core/MideaSecurity.d.ts +62 -64
  52. package/dist/core/MideaSecurity.js +241 -251
  53. package/dist/core/MideaSecurity.js.map +1 -1
  54. package/dist/core/MideaUtils.d.ts +31 -33
  55. package/dist/core/MideaUtils.js +178 -181
  56. package/dist/core/MideaUtils.js.map +1 -1
  57. package/dist/devices/DeviceFactory.d.ts +14 -15
  58. package/dist/devices/DeviceFactory.js +34 -40
  59. package/dist/devices/DeviceFactory.js.map +1 -1
  60. package/dist/devices/a1/MideaA1Device.d.ts +75 -77
  61. package/dist/devices/a1/MideaA1Device.js +142 -145
  62. package/dist/devices/a1/MideaA1Device.js.map +1 -1
  63. package/dist/devices/a1/MideaA1Message.d.ts +39 -41
  64. package/dist/devices/a1/MideaA1Message.js +219 -198
  65. package/dist/devices/a1/MideaA1Message.js.map +1 -1
  66. package/dist/devices/ac/MideaACDevice.d.ts +105 -107
  67. package/dist/devices/ac/MideaACDevice.js +417 -400
  68. package/dist/devices/ac/MideaACDevice.js.map +1 -1
  69. package/dist/devices/ac/MideaACMessage.d.ts +97 -96
  70. package/dist/devices/ac/MideaACMessage.js +724 -621
  71. package/dist/devices/ac/MideaACMessage.js.map +1 -1
  72. package/dist/devices/c3/MideaC3Device.d.ts +73 -75
  73. package/dist/devices/c3/MideaC3Device.js +249 -255
  74. package/dist/devices/c3/MideaC3Device.js.map +1 -1
  75. package/dist/devices/c3/MideaC3Message.d.ts +81 -80
  76. package/dist/devices/c3/MideaC3Message.js +190 -152
  77. package/dist/devices/c3/MideaC3Message.js.map +1 -1
  78. package/dist/devices/db/MideaDBDevice.d.ts +28 -30
  79. package/dist/devices/db/MideaDBDevice.js +94 -100
  80. package/dist/devices/db/MideaDBDevice.js.map +1 -1
  81. package/dist/devices/db/MideaDBMessage.d.ts +31 -33
  82. package/dist/devices/db/MideaDBMessage.js +101 -101
  83. package/dist/devices/db/MideaDBMessage.js.map +1 -1
  84. package/dist/devices/e1/MideaE1Device.d.ts +55 -57
  85. package/dist/devices/e1/MideaE1Device.js +122 -128
  86. package/dist/devices/e1/MideaE1Device.js.map +1 -1
  87. package/dist/devices/e1/MideaE1Message.d.ts +27 -29
  88. package/dist/devices/e1/MideaE1Message.js +128 -107
  89. package/dist/devices/e1/MideaE1Message.js.map +1 -1
  90. package/dist/devices/e2/MideaE2Device.d.ts +43 -45
  91. package/dist/devices/e2/MideaE2Device.js +124 -129
  92. package/dist/devices/e2/MideaE2Device.js.map +1 -1
  93. package/dist/devices/e2/MideaE2Message.d.ts +34 -34
  94. package/dist/devices/e2/MideaE2Message.js +143 -132
  95. package/dist/devices/e2/MideaE2Message.js.map +1 -1
  96. package/dist/devices/e3/MideaE3Device.d.ts +42 -44
  97. package/dist/devices/e3/MideaE3Device.js +132 -137
  98. package/dist/devices/e3/MideaE3Device.js.map +1 -1
  99. package/dist/devices/e3/MideaE3Message.d.ts +51 -52
  100. package/dist/devices/e3/MideaE3Message.js +144 -136
  101. package/dist/devices/e3/MideaE3Message.js.map +1 -1
  102. package/dist/devices/fa/MideaFADevice.d.ts +35 -37
  103. package/dist/devices/fa/MideaFADevice.js +102 -106
  104. package/dist/devices/fa/MideaFADevice.js.map +1 -1
  105. package/dist/devices/fa/MideaFAMessage.d.ts +38 -39
  106. package/dist/devices/fa/MideaFAMessage.js +108 -98
  107. package/dist/devices/fa/MideaFAMessage.js.map +1 -1
  108. package/dist/index.d.ts +6 -7
  109. package/dist/index.js +8 -6
  110. package/dist/index.js.map +1 -1
  111. package/dist/platform.d.ts +61 -61
  112. package/dist/platform.js +232 -212
  113. package/dist/platform.js.map +1 -1
  114. package/dist/platformUtils.d.ts +116 -117
  115. package/dist/platformUtils.js +107 -110
  116. package/dist/platformUtils.js.map +1 -1
  117. package/dist/settings.d.ts +8 -9
  118. package/dist/settings.js +8 -11
  119. package/dist/settings.js.map +1 -1
  120. package/docs/download_lua.md +9 -0
  121. package/eslint.config.js +43 -0
  122. package/homebridge-ui/public/js/bootstrap.min.js +1179 -1
  123. package/homebridge-ui/server.js +157 -84
  124. package/package.json +21 -31
  125. package/.eslintignore +0 -3
  126. package/.husky/pre-commit +0 -5
  127. package/.prettierrc +0 -19
  128. package/dist/accessory/AccessoryFactory.d.ts.map +0 -1
  129. package/dist/accessory/AirConditionerAccessory.d.ts.map +0 -1
  130. package/dist/accessory/BaseAccessory.d.ts.map +0 -1
  131. package/dist/accessory/DehumidifierAccessory.d.ts.map +0 -1
  132. package/dist/accessory/DishwasherAccessory.d.ts.map +0 -1
  133. package/dist/accessory/ElectricWaterHeaterAccessory.d.ts.map +0 -1
  134. package/dist/accessory/FanAccessory.d.ts.map +0 -1
  135. package/dist/accessory/FrontLoadWasherAccessory.d.ts.map +0 -1
  136. package/dist/accessory/GasWaterHeaterAccessory.d.ts.map +0 -1
  137. package/dist/accessory/HeatPumpWifiControllerAccessory.d.ts.map +0 -1
  138. package/dist/accessory/HeatPumpWifiControllerAccessory.js.map +0 -1
  139. package/dist/core/MideaCloud.d.ts.map +0 -1
  140. package/dist/core/MideaConstants.d.ts.map +0 -1
  141. package/dist/core/MideaDevice.d.ts.map +0 -1
  142. package/dist/core/MideaDiscover.d.ts.map +0 -1
  143. package/dist/core/MideaMessage.d.ts.map +0 -1
  144. package/dist/core/MideaPacketBuilder.d.ts.map +0 -1
  145. package/dist/core/MideaSecurity.d.ts.map +0 -1
  146. package/dist/core/MideaUtils.d.ts.map +0 -1
  147. package/dist/devices/DeviceFactory.d.ts.map +0 -1
  148. package/dist/devices/a1/MideaA1Device.d.ts.map +0 -1
  149. package/dist/devices/a1/MideaA1Message.d.ts.map +0 -1
  150. package/dist/devices/ac/MideaACDevice.d.ts.map +0 -1
  151. package/dist/devices/ac/MideaACMessage.d.ts.map +0 -1
  152. package/dist/devices/c3/MideaC3Device.d.ts.map +0 -1
  153. package/dist/devices/c3/MideaC3Message.d.ts.map +0 -1
  154. package/dist/devices/db/MideaDBDevice.d.ts.map +0 -1
  155. package/dist/devices/db/MideaDBMessage.d.ts.map +0 -1
  156. package/dist/devices/e1/MideaE1Device.d.ts.map +0 -1
  157. package/dist/devices/e1/MideaE1Message.d.ts.map +0 -1
  158. package/dist/devices/e2/MideaE2Device.d.ts.map +0 -1
  159. package/dist/devices/e2/MideaE2Message.d.ts.map +0 -1
  160. package/dist/devices/e3/MideaE3Device.d.ts.map +0 -1
  161. package/dist/devices/e3/MideaE3Message.d.ts.map +0 -1
  162. package/dist/devices/fa/MideaFADevice.d.ts.map +0 -1
  163. package/dist/devices/fa/MideaFAMessage.d.ts.map +0 -1
  164. package/dist/index.d.ts.map +0 -1
  165. package/dist/platform.d.ts.map +0 -1
  166. package/dist/platformUtils.d.ts.map +0 -1
  167. package/dist/settings.d.ts.map +0 -1
@@ -1,663 +1,667 @@
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 AirConditionerAccessory 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, _h, _j, _k, _l, _m, _o, _p;
15
- super(platform, accessory, device, configDev);
16
- this.device = device;
17
- this.configDev = configDev;
18
- this.service =
19
- this.accessory.getService(this.platform.Service.HeaterCooler) || this.accessory.addService(this.platform.Service.HeaterCooler);
20
- this.service.setCharacteristic(this.platform.Characteristic.Name, this.device.name);
21
- this.service.getCharacteristic(this.platform.Characteristic.Active).onGet(this.getActive.bind(this)).onSet(this.setActive.bind(this));
22
- this.service
23
- .getCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits)
24
- .onGet(this.getTemperatureDisplayUnits.bind(this))
25
- .onSet(this.setTemperatureDisplayUnits.bind(this));
26
- this.service
27
- .getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState)
28
- .onGet(this.getCurrentHeaterCoolerState.bind(this));
29
- this.service
30
- .getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
31
- .onGet(this.getTargetHeaterCoolerState.bind(this))
32
- .onSet(this.setTargetHeaterCoolerState.bind(this))
33
- .setProps({
34
- validValues: this.configDev.AC_options.heatingCapable
35
- ? [
36
- this.platform.Characteristic.TargetHeaterCoolerState.AUTO,
37
- this.platform.Characteristic.TargetHeaterCoolerState.HEAT,
38
- this.platform.Characteristic.TargetHeaterCoolerState.COOL,
39
- ]
40
- : [this.platform.Characteristic.TargetHeaterCoolerState.AUTO, this.platform.Characteristic.TargetHeaterCoolerState.COOL],
41
- });
42
- this.service.getCharacteristic(this.platform.Characteristic.CurrentTemperature).onGet(this.getCurrentTemperature.bind(this));
43
- this.service
44
- .getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
45
- .onGet(this.getTargetTemperature.bind(this))
46
- .onSet(this.setTargetTemperature.bind(this))
47
- .setProps({
48
- minValue: this.configDev.AC_options.minTemp,
49
- maxValue: this.configDev.AC_options.maxTemp,
50
- minStep: this.configDev.AC_options.tempStep,
51
- });
52
- this.service
53
- .getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
54
- .onGet(this.getTargetTemperature.bind(this))
55
- .onSet(this.setTargetTemperature.bind(this))
56
- .setProps({
57
- minValue: this.configDev.AC_options.minTemp,
58
- maxValue: this.configDev.AC_options.maxTemp,
59
- minStep: this.configDev.AC_options.tempStep,
60
- });
61
- this.service
62
- .getCharacteristic(this.platform.Characteristic.RotationSpeed)
63
- .onGet(this.getRotationSpeed.bind(this))
64
- .onSet(this.setRotationSpeed.bind(this));
65
- // Swing modes
66
- if (this.configDev.AC_options.swing.mode !== platformUtils_1.SwingMode.NONE) {
67
- this.service
68
- .getCharacteristic(this.platform.Characteristic.SwingMode)
69
- .onGet(this.getSwingMode.bind(this))
70
- .onSet(this.setSwingMode.bind(this));
71
- }
72
- // Outdoor temperature sensor
73
- this.outDoorTemperatureService = this.accessory.getServiceById(this.platform.Service.TemperatureSensor, 'Outdoor');
74
- if (this.configDev.AC_options.outDoorTemp) {
75
- (_a = this.outDoorTemperatureService) !== null && _a !== void 0 ? _a : (this.outDoorTemperatureService = this.accessory.addService(this.platform.Service.TemperatureSensor, `${this.device.name} Outdoor`, 'Outdoor'));
76
- this.outDoorTemperatureService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Outdoor`);
77
- this.outDoorTemperatureService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Outdoor`);
78
- this.outDoorTemperatureService
79
- .getCharacteristic(this.platform.Characteristic.CurrentTemperature)
80
- .onGet(this.getOutdoorTemperature.bind(this));
81
- this.outDoorTemperatureService
82
- .getCharacteristic(this.platform.Characteristic.StatusFault)
83
- .onGet(() => this.device.attributes.OUTDOOR_TEMPERATURE === undefined
84
- ? this.platform.Characteristic.StatusFault.GENERAL_FAULT
85
- : this.platform.Characteristic.StatusFault.NO_FAULT);
86
- }
87
- else if (this.outDoorTemperatureService) {
88
- this.accessory.removeService(this.outDoorTemperatureService);
89
- }
90
- // Fan-only mode switch
91
- this.fanOnlyService = this.accessory.getServiceById(this.platform.Service.Switch, 'FanOnly');
92
- if (this.configDev.AC_options.fanOnlyModeSwitch) {
93
- (_b = this.fanOnlyService) !== null && _b !== void 0 ? _b : (this.fanOnlyService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} FanOnly`, 'FanOnly'));
94
- this.fanOnlyService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Fan-only Mode`);
95
- this.fanOnlyService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Fan-only Mode`);
96
- this.fanOnlyService
97
- .getCharacteristic(this.platform.Characteristic.On)
98
- .onGet(this.getFanOnlyMode.bind(this))
99
- .onSet(this.setFanOnlyMode.bind(this));
100
- }
101
- else if (this.fanOnlyService) {
102
- this.accessory.removeService(this.fanOnlyService);
103
- }
104
- // Fan accessory
105
- this.fanService = this.accessory.getServiceById(this.platform.Service.Fanv2, 'Fan');
106
- if (this.configDev.AC_options.fanAccessory) {
107
- (_c = this.fanService) !== null && _c !== void 0 ? _c : (this.fanService = this.accessory.addService(this.platform.Service.Fanv2, `${this.device.name} Fan`, 'Fan'));
108
- this.fanService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Fan`);
109
- this.fanService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Fan`);
110
- this.fanService
111
- .getCharacteristic(this.platform.Characteristic.Active)
112
- .onGet(this.getActive.bind(this))
113
- .onSet(this.setActive.bind(this));
114
- this.fanService
115
- .getCharacteristic(this.platform.Characteristic.RotationSpeed)
116
- .onGet(this.getRotationSpeed.bind(this))
117
- .onSet(this.setRotationSpeed.bind(this));
118
- this.fanService
119
- .getCharacteristic(this.platform.Characteristic.TargetFanState)
120
- .onGet(this.getFanState.bind(this))
121
- .onSet(this.setFanState.bind(this));
122
- this.fanService
123
- .getCharacteristic(this.platform.Characteristic.SwingMode)
124
- .onGet(this.getSwingMode.bind(this))
125
- .onSet(this.setSwingMode.bind(this));
126
- }
127
- else if (this.fanService) {
128
- this.accessory.removeService(this.fanService);
129
- }
130
- // Display switch
131
- this.displayService = this.accessory.getServiceById(this.platform.Service.Switch, 'Display');
132
- if (this.configDev.AC_options.displaySwitch.flag) {
133
- this.device.set_alternate_switch_display(this.configDev.AC_options.displaySwitch.command);
134
- (_d = this.displayService) !== null && _d !== void 0 ? _d : (this.displayService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Display`, 'Display'));
135
- this.displayService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Display`);
136
- this.displayService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Display`);
137
- this.displayService
138
- .getCharacteristic(this.platform.Characteristic.On)
139
- .onGet(this.getDisplayActive.bind(this))
140
- .onSet(this.setDisplayActive.bind(this));
141
- }
142
- else if (this.displayService) {
143
- this.accessory.removeService(this.displayService);
144
- }
145
- // Eco mode switch
146
- this.ecoModeService = this.accessory.getServiceById(this.platform.Service.Switch, 'EcoMode');
147
- if (this.configDev.AC_options.ecoSwitch) {
148
- (_e = this.ecoModeService) !== null && _e !== void 0 ? _e : (this.ecoModeService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Eco`, 'EcoMode'));
149
- this.ecoModeService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Eco`);
150
- this.ecoModeService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Eco`);
151
- this.ecoModeService
152
- .getCharacteristic(this.platform.Characteristic.On)
153
- .onGet(this.getEcoMode.bind(this))
154
- .onSet(this.setEcoMode.bind(this));
155
- }
156
- else if (this.ecoModeService) {
157
- this.accessory.removeService(this.ecoModeService);
158
- }
159
- // Breeze away switch
160
- this.breezeAwayService = this.accessory.getServiceById(this.platform.Service.Switch, 'BreezeAway');
161
- if (this.configDev.AC_options.breezeAwaySwitch) {
162
- (_f = this.breezeAwayService) !== null && _f !== void 0 ? _f : (this.breezeAwayService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Breeze`, 'BreezeAway'));
163
- this.breezeAwayService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Breeze`);
164
- this.breezeAwayService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Breeze`);
165
- this.breezeAwayService
166
- .getCharacteristic(this.platform.Characteristic.On)
167
- .onGet(this.getBreezeAway.bind(this))
168
- .onSet(this.setBreezeAway.bind(this));
169
- }
170
- else if (this.breezeAwayService) {
171
- this.accessory.removeService(this.breezeAwayService);
172
- }
173
- // Dry mode switch
174
- this.dryModeService = this.accessory.getServiceById(this.platform.Service.Switch, 'DryMode');
175
- if (this.configDev.AC_options.dryModeSwitch) {
176
- (_g = this.dryModeService) !== null && _g !== void 0 ? _g : (this.dryModeService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Dry`, 'DryMode'));
177
- this.dryModeService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Dry`);
178
- this.dryModeService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Dry`);
179
- this.dryModeService
180
- .getCharacteristic(this.platform.Characteristic.On)
181
- .onGet(this.getDryMode.bind(this))
182
- .onSet(this.setDryMode.bind(this));
183
- }
184
- else if (this.dryModeService) {
185
- this.accessory.removeService(this.dryModeService);
186
- }
187
- this.boostModeService = this.accessory.getServiceById(this.platform.Service.Switch, 'BoostMode');
188
- if (this.configDev.AC_options.boostModeSwitch) {
189
- (_h = this.boostModeService) !== null && _h !== void 0 ? _h : (this.boostModeService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Boost`, 'BoostMode'));
190
- this.boostModeService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Boost`);
191
- this.boostModeService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Boost`);
192
- this.boostModeService
193
- .getCharacteristic(this.platform.Characteristic.On)
194
- .onGet(this.getBoostMode.bind(this))
195
- .onSet(this.setBoostMode.bind(this));
196
- }
197
- else if (this.boostModeService) {
198
- this.accessory.removeService(this.boostModeService);
199
- }
200
- // Aux switch
201
- this.auxService = this.accessory.getServiceById(this.platform.Service.Switch, 'Aux');
202
- if (this.configDev.AC_options.auxHeatingSwitches) {
203
- (_j = this.auxService) !== null && _j !== void 0 ? _j : (this.auxService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Aux`, 'Aux'));
204
- this.auxService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Aux`);
205
- this.auxService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Aux`);
206
- this.auxService.getCharacteristic(this.platform.Characteristic.On).onGet(this.getAux.bind(this)).onSet(this.setAux.bind(this));
207
- }
208
- else if (this.auxService) {
209
- this.accessory.removeService(this.auxService);
210
- }
211
- // Aux+Heat switch
212
- this.auxHeatingService = this.accessory.getServiceById(this.platform.Service.Switch, 'AuxHeating');
213
- if (this.configDev.AC_options.auxHeatingSwitches) {
214
- (_k = this.auxHeatingService) !== null && _k !== void 0 ? _k : (this.auxHeatingService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Aux+Heat`, 'AuxHeating'));
215
- this.auxHeatingService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Aux+Heat`);
216
- this.auxHeatingService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Aux+Heat`);
217
- this.auxHeatingService
218
- .getCharacteristic(this.platform.Characteristic.On)
219
- .onGet(this.getAuxHeating.bind(this))
220
- .onSet(this.setAuxHeating.bind(this));
221
- }
222
- else if (this.auxHeatingService) {
223
- this.accessory.removeService(this.auxHeatingService);
224
- }
225
- // Self-cleaning switch
226
- this.selfCleanService = this.accessory.getServiceById(this.platform.Service.Switch, 'SelfClean');
227
- if (this.configDev.AC_options.selfCleanSwitch) {
228
- (_l = this.selfCleanService) !== null && _l !== void 0 ? _l : (this.selfCleanService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Self-cleaning`, 'SelfClean'));
229
- this.selfCleanService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Self-cleaning`);
230
- this.selfCleanService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Self-cleaning`);
231
- this.selfCleanService
232
- .getCharacteristic(this.platform.Characteristic.On)
233
- .onGet(this.getSelfCleanState.bind(this))
234
- .onSet(this.setSelfCleanState.bind(this));
235
- }
236
- else if (this.selfCleanService) {
237
- this.accessory.removeService(this.selfCleanService);
238
- }
239
- // ION switch
240
- this.ionService = this.accessory.getServiceById(this.platform.Service.Switch, 'ION');
241
- if (this.configDev.AC_options.ionSwitch) {
242
- (_m = this.ionService) !== null && _m !== void 0 ? _m : (this.ionService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} ION`, 'ION'));
243
- this.ionService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} ION`);
244
- this.ionService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} ION`);
245
- this.ionService
246
- .getCharacteristic(this.platform.Characteristic.On)
247
- .onGet(this.getIonState.bind(this))
248
- .onSet(this.setIonState.bind(this));
249
- }
250
- else if (this.ionService) {
251
- this.accessory.removeService(this.ionService);
252
- }
253
- // Rate select slider
254
- this.rateSelectService = this.accessory.getServiceById(this.platform.Service.Lightbulb, 'Gear');
255
- if (this.configDev.AC_options.rateSelector) {
256
- (_o = this.rateSelectService) !== null && _o !== void 0 ? _o : (this.rateSelectService = this.accessory.addService(this.platform.Service.Lightbulb, `${this.device.name} Gear`, 'Gear'));
257
- this.rateSelectService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Gear`);
258
- this.rateSelectService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Gear`);
259
- this.rateSelectService
260
- .getCharacteristic(this.platform.Characteristic.On)
261
- .onGet(this.getActive.bind(this))
262
- .onSet(this.setActive.bind(this));
263
- this.rateSelectService
264
- .getCharacteristic(this.platform.Characteristic.Brightness)
265
- .setProps({
266
- validValues: [0, 50, 75, 100],
267
- })
268
- .onGet(this.getRateSelect.bind(this))
269
- .onSet(this.setRateSelect.bind(this));
270
- }
271
- else if (this.rateSelectService) {
272
- this.accessory.removeService(this.rateSelectService);
273
- }
274
- const swingProps = this.configDev.AC_options.swing;
275
- this.swingAngleMainControl =
276
- swingProps.mode === platformUtils_1.SwingMode.VERTICAL || (swingProps.mode === platformUtils_1.SwingMode.BOTH && swingProps.angleMainControl === platformUtils_1.SwingAngle.VERTICAL)
277
- ? platformUtils_1.SwingAngle.VERTICAL
278
- : platformUtils_1.SwingAngle.HORIZONTAL;
279
- // Swing angle accessory
280
- this.swingAngleService = this.accessory.getServiceById(this.platform.Service.WindowCovering, 'SwingAngle');
281
- if (swingProps.mode !== platformUtils_1.SwingMode.NONE && swingProps.angleAccessory) {
282
- (_p = this.swingAngleService) !== null && _p !== void 0 ? _p : (this.swingAngleService = this.accessory.addService(this.platform.Service.WindowCovering, `${this.device.name} Swing`, 'SwingAngle'));
283
- this.swingAngleService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Swing`);
284
- this.swingAngleService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Swing`);
285
- this.swingAngleService
286
- .getCharacteristic(this.platform.Characteristic.CurrentPosition)
287
- .onGet(this.getSwingAngleCurrentPosition.bind(this));
288
- this.swingAngleService
289
- .getCharacteristic(this.platform.Characteristic.TargetPosition)
290
- .onGet(this.getSwingAngleTargetPosition.bind(this))
291
- .onSet(this.setSwingAngleTargetPosition.bind(this));
292
- this.swingAngleService
293
- .getCharacteristic(this.platform.Characteristic.PositionState)
294
- .onGet(this.getSwingAnglePositionState.bind(this));
295
- if (swingProps.mode === platformUtils_1.SwingMode.BOTH) {
296
- this.swingAngleService
297
- .getCharacteristic(this.platform.Characteristic.CurrentHorizontalTiltAngle)
298
- .onGet(this.getSwingAngleCurrentHorizontalTiltAngle.bind(this));
299
- this.swingAngleService
300
- .getCharacteristic(this.platform.Characteristic.TargetHorizontalTiltAngle)
301
- .onGet(this.getSwingAngleTargetHorizontalTiltAngle.bind(this))
302
- .onSet(this.setSwingAngleTargetHorizontalTiltAngle.bind(this));
303
- this.swingAngleService
304
- .getCharacteristic(this.platform.Characteristic.CurrentVerticalTiltAngle)
305
- .onGet(this.getSwingAngleCurrentVerticalTiltAngle.bind(this));
306
- this.swingAngleService
307
- .getCharacteristic(this.platform.Characteristic.TargetVerticalTiltAngle)
308
- .onGet(this.getSwingAngleTargetVerticalTiltAngle.bind(this))
309
- .onSet(this.setSwingAngleTargetVerticalTiltAngle.bind(this));
310
- }
311
- }
312
- // Misc
313
- this.device.attributes.PROMPT_TONE = this.configDev.AC_options.audioFeedback;
314
- this.device.attributes.TEMP_FAHRENHEIT = this.configDev.AC_options.fahrenheit;
315
- }
316
- /*********************************************************************
317
- * Callback function called by MideaDevice whenever there is a change to
318
- * any attribute value.
319
- */
320
- async updateCharacteristics(attributes) {
321
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
322
- for (const [k, v] of Object.entries(attributes)) {
323
- this.platform.log.debug(`[${this.device.name}] Set attribute ${k} to: ${v}`);
324
- let updateState = false;
325
- switch (k.toLowerCase()) {
326
- case 'power':
327
- updateState = true;
328
- break;
329
- case 'temp_fahrenheit':
330
- this.service.updateCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits, this.getTemperatureDisplayUnits());
331
- break;
332
- case 'screen_display':
333
- case 'screen_display_new':
334
- (_a = this.displayService) === null || _a === void 0 ? void 0 : _a.updateCharacteristic(this.platform.Characteristic.On, this.getDisplayActive());
335
- break;
336
- case 'target_temperature':
337
- // If MODE is 4 then device is heating. Therefore target temperature value must be heating target? Right?
338
- if (this.device.attributes.MODE === 4) {
339
- this.service.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.getTargetTemperature());
340
- }
341
- else {
342
- this.service.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.getTargetTemperature());
343
- }
344
- updateState = true;
345
- break;
346
- case 'indoor_temperature':
347
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.getCurrentTemperature());
348
- break;
349
- case 'outdoor_temperature':
350
- (_b = this.outDoorTemperatureService) === null || _b === void 0 ? void 0 : _b.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.getOutdoorTemperature());
351
- break;
352
- case 'fan_speed':
353
- updateState = true;
354
- break;
355
- case 'fan_auto':
356
- (_c = this.fanService) === null || _c === void 0 ? void 0 : _c.updateCharacteristic(this.platform.Characteristic.TargetFanState, this.getFanState());
357
- break;
358
- case 'swing_vertical':
359
- case 'swing_horizontal':
360
- this.service.updateCharacteristic(this.platform.Characteristic.SwingMode, this.getSwingMode());
361
- break;
362
- case 'mode':
363
- updateState = true;
364
- break;
365
- case 'eco_mode':
366
- (_d = this.ecoModeService) === null || _d === void 0 ? void 0 : _d.updateCharacteristic(this.platform.Characteristic.On, this.getEcoMode());
367
- break;
368
- case 'indirect_wind':
369
- (_e = this.breezeAwayService) === null || _e === void 0 ? void 0 : _e.updateCharacteristic(this.platform.Characteristic.On, this.getBreezeAway());
370
- break;
371
- case 'aux_heating':
372
- (_f = this.auxHeatingService) === null || _f === void 0 ? void 0 : _f.updateCharacteristic(this.platform.Characteristic.On, this.getAuxHeating());
373
- break;
374
- case 'smart_eye':
375
- (_g = this.auxService) === null || _g === void 0 ? void 0 : _g.updateCharacteristic(this.platform.Characteristic.On, this.getAux());
376
- break;
377
- case 'wind_swing_lr_angle':
378
- case 'wind_swing_ud_angle':
379
- (_h = this.swingAngleService) === null || _h === void 0 ? void 0 : _h.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.getSwingAngleCurrentPosition());
380
- (_j = this.swingAngleService) === null || _j === void 0 ? void 0 : _j.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.getSwingAngleTargetPosition());
381
- if (this.configDev.AC_options.swing.mode === platformUtils_1.SwingMode.BOTH) {
382
- (_k = this.swingAngleService) === null || _k === void 0 ? void 0 : _k.updateCharacteristic(this.platform.Characteristic.CurrentHorizontalTiltAngle, this.getSwingAngleCurrentHorizontalTiltAngle());
383
- (_l = this.swingAngleService) === null || _l === void 0 ? void 0 : _l.updateCharacteristic(this.platform.Characteristic.CurrentVerticalTiltAngle, this.getSwingAngleCurrentVerticalTiltAngle());
384
- (_m = this.swingAngleService) === null || _m === void 0 ? void 0 : _m.updateCharacteristic(this.platform.Characteristic.TargetHorizontalTiltAngle, this.getSwingAngleTargetHorizontalTiltAngle());
385
- (_o = this.swingAngleService) === null || _o === void 0 ? void 0 : _o.updateCharacteristic(this.platform.Characteristic.TargetVerticalTiltAngle, this.getSwingAngleTargetVerticalTiltAngle());
386
- }
387
- break;
388
- case 'self_clean':
389
- updateState = true;
390
- (_p = this.selfCleanService) === null || _p === void 0 ? void 0 : _p.updateCharacteristic(this.platform.Characteristic.On, this.getSelfCleanState());
391
- break;
392
- case 'ion':
393
- (_q = this.ionService) === null || _q === void 0 ? void 0 : _q.updateCharacteristic(this.platform.Characteristic.On, this.getIonState());
394
- break;
395
- case 'rate_select':
396
- (_r = this.rateSelectService) === null || _r === void 0 ? void 0 : _r.updateCharacteristic(this.platform.Characteristic.Brightness, this.getRateSelect());
397
- break;
398
- default:
399
- this.platform.log.debug(`[${this.device.name}] Attempt to set unsupported attribute ${k} to ${v}`);
400
- }
401
- if (updateState) {
402
- this.service.updateCharacteristic(this.platform.Characteristic.Active, this.getActive());
403
- this.service.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.getTargetHeaterCoolerState());
404
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.getCurrentHeaterCoolerState());
405
- this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.getRotationSpeed());
406
- (_s = this.fanOnlyService) === null || _s === void 0 ? void 0 : _s.updateCharacteristic(this.platform.Characteristic.On, this.getFanOnlyMode());
407
- (_t = this.fanService) === null || _t === void 0 ? void 0 : _t.updateCharacteristic(this.platform.Characteristic.Active, this.getActive());
408
- (_u = this.fanService) === null || _u === void 0 ? void 0 : _u.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.getRotationSpeed());
409
- (_v = this.dryModeService) === null || _v === void 0 ? void 0 : _v.updateCharacteristic(this.platform.Characteristic.On, this.getDryMode());
410
- (_w = this.displayService) === null || _w === void 0 ? void 0 : _w.updateCharacteristic(this.platform.Characteristic.On, this.getDisplayActive());
411
- (_x = this.ecoModeService) === null || _x === void 0 ? void 0 : _x.updateCharacteristic(this.platform.Characteristic.On, this.getEcoMode());
412
- (_y = this.breezeAwayService) === null || _y === void 0 ? void 0 : _y.updateCharacteristic(this.platform.Characteristic.On, this.getBreezeAway());
413
- (_z = this.auxService) === null || _z === void 0 ? void 0 : _z.updateCharacteristic(this.platform.Characteristic.On, this.getAux());
414
- (_0 = this.auxHeatingService) === null || _0 === void 0 ? void 0 : _0.updateCharacteristic(this.platform.Characteristic.On, this.getAuxHeating());
415
- }
416
- }
417
- }
418
- /*********************************************************************
419
- * Callback functions for each Homebridge/HomeKit service
420
- *
421
- */
422
- getActive() {
423
- // Show as inactive if device is off
424
- return this.device.attributes.POWER ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE;
425
- }
426
- async setActive(value) {
427
- var _a;
428
- await this.device.set_attribute({ POWER: !!value });
429
- this.device.attributes.SCREEN_DISPLAY = !!value;
430
- (_a = this.displayService) === null || _a === void 0 ? void 0 : _a.updateCharacteristic(this.platform.Characteristic.On, !!value);
431
- }
432
- getTemperatureDisplayUnits() {
433
- return this.device.attributes.TEMP_FAHRENHEIT
434
- ? this.platform.Characteristic.TemperatureDisplayUnits.FAHRENHEIT
435
- : this.platform.Characteristic.TemperatureDisplayUnits.CELSIUS;
436
- }
437
- async setTemperatureDisplayUnits(value) {
438
- await this.device.set_attribute({ TEMP_FAHRENHEIT: value === this.platform.Characteristic.TemperatureDisplayUnits.FAHRENHEIT });
439
- }
440
- getCurrentHeaterCoolerState() {
441
- var _a;
442
- if (this.device.attributes.POWER && this.device.attributes.MODE > 0 && this.device.attributes.MODE < 5) {
443
- if (this.device.attributes.TARGET_TEMPERATURE < ((_a = this.device.attributes.INDOOR_TEMPERATURE) !== null && _a !== void 0 ? _a : 0)) {
444
- if ([1, 2].includes(this.device.attributes.MODE)) {
445
- return this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
446
- }
447
- else {
448
- return this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
449
- }
450
- }
451
- else if (this.device.attributes.TARGET_TEMPERATURE === this.device.attributes.INDOOR_TEMPERATURE) {
452
- return this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
453
- }
454
- else {
455
- if (this.device.attributes.MODE === 4) {
456
- return this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
457
- }
458
- else {
459
- return this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
460
- }
461
- }
462
- }
463
- else {
464
- return this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
465
- }
466
- }
467
- getTargetHeaterCoolerState() {
468
- if (this.device.attributes.MODE === 2) {
469
- return this.platform.Characteristic.TargetHeaterCoolerState.COOL;
470
- }
471
- else if (this.device.attributes.MODE === 4) {
472
- return this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
473
- }
474
- else {
475
- return this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
476
- }
477
- }
478
- async setTargetHeaterCoolerState(value) {
479
- switch (value) {
480
- case this.platform.Characteristic.TargetHeaterCoolerState.AUTO:
481
- await this.device.set_attribute({ POWER: true, MODE: 1 });
482
- break;
483
- case this.platform.Characteristic.TargetHeaterCoolerState.COOL:
484
- await this.device.set_attribute({ POWER: true, MODE: 2 });
485
- break;
486
- case this.platform.Characteristic.TargetHeaterCoolerState.HEAT:
487
- await this.device.set_attribute({ POWER: true, MODE: 4 });
488
- break;
489
- }
490
- }
491
- getCurrentTemperature() {
492
- var _a;
493
- return (_a = this.device.attributes.INDOOR_TEMPERATURE) !== null && _a !== void 0 ? _a : this.configDev.AC_options.minTemp;
494
- }
495
- getTargetTemperature() {
496
- return Math.max(this.configDev.AC_options.minTemp, Math.min(this.configDev.AC_options.maxTemp, this.device.attributes.TARGET_TEMPERATURE));
497
- }
498
- getFanOnlyMode() {
499
- return this.device.attributes.POWER === true && this.device.attributes.MODE === 5;
500
- }
501
- async setFanOnlyMode(value) {
502
- if (value) {
503
- await this.device.set_attribute({ POWER: true, MODE: 5 });
504
- }
505
- else {
506
- await this.device.set_attribute({ POWER: false, MODE: 0 });
507
- }
508
- }
509
- getFanState() {
510
- return this.device.attributes.FAN_AUTO;
511
- }
512
- async setFanState(value) {
513
- await this.device.set_fan_auto(value === this.platform.Characteristic.TargetFanState.AUTO);
514
- }
515
- async setTargetTemperature(value) {
516
- value = Math.max(this.configDev.AC_options.minTemp, Math.min(this.configDev.AC_options.maxTemp, value));
517
- await this.device.set_target_temperature(value);
518
- }
519
- getSwingMode() {
520
- return this.device.attributes.SWING_HORIZONTAL || this.device.attributes.SWING_VERTICAL
521
- ? this.platform.Characteristic.SwingMode.SWING_ENABLED
522
- : this.platform.Characteristic.SwingMode.SWING_DISABLED;
523
- }
524
- async setSwingMode(value) {
525
- switch (value) {
526
- case this.platform.Characteristic.SwingMode.SWING_ENABLED:
527
- await this.device.set_swing([platformUtils_1.SwingMode.HORIZONTAL, platformUtils_1.SwingMode.BOTH].includes(this.configDev.AC_options.swing.mode), [platformUtils_1.SwingMode.VERTICAL, platformUtils_1.SwingMode.BOTH].includes(this.configDev.AC_options.swing.mode));
528
- break;
529
- case this.platform.Characteristic.SwingMode.SWING_DISABLED:
530
- await this.device.set_swing(false, false);
531
- break;
532
- }
533
- }
534
- getRotationSpeed() {
535
- var _a;
536
- return Math.min(100, (_a = this.device.attributes.FAN_SPEED) !== null && _a !== void 0 ? _a : 0);
537
- }
538
- async setRotationSpeed(value) {
539
- await this.device.set_attribute({ FAN_SPEED: value });
540
- }
541
- getOutdoorTemperature() {
542
- var _a;
543
- return (_a = this.device.attributes.OUTDOOR_TEMPERATURE) !== null && _a !== void 0 ? _a : -270;
544
- }
545
- getDisplayActive() {
546
- return this.device.attributes.SCREEN_DISPLAY === true;
547
- }
548
- async setDisplayActive(value) {
549
- if (this.device.attributes.POWER) {
550
- await this.device.set_attribute({ SCREEN_DISPLAY: !!value });
551
- }
552
- }
553
- getEcoMode() {
554
- return this.device.attributes.POWER === true && this.device.attributes.ECO_MODE;
555
- }
556
- async setEcoMode(value) {
557
- await this.device.set_attribute({ ECO_MODE: !!value });
558
- }
559
- getBreezeAway() {
560
- return this.device.attributes.POWER === true && this.device.attributes.INDIRECT_WIND;
561
- }
562
- async setBreezeAway(value) {
563
- await this.device.set_attribute({ INDIRECT_WIND: !!value });
564
- }
565
- getDryMode() {
566
- return this.device.attributes.POWER === true && this.device.attributes.MODE === 3;
567
- }
568
- async setDryMode(value) {
569
- if (value) {
570
- await this.device.set_attribute({ POWER: true, MODE: 3 });
571
- }
572
- else {
573
- await this.device.set_attribute({ POWER: false, MODE: 0 });
574
- }
575
- }
576
- getBoostMode() {
577
- return this.device.attributes.POWER === true && this.device.attributes.BOOST_MODE;
578
- }
579
- async setBoostMode(value) {
580
- if (value) {
581
- await this.device.set_attribute({ POWER: true, BOOST_MODE: true });
582
- }
583
- else {
584
- await this.device.set_attribute({ BOOST_MODE: false });
585
- }
586
- }
587
- getAux() {
588
- return this.device.attributes.POWER === true && this.device.attributes.SMART_EYE === true;
589
- }
590
- async setAux(value) {
591
- if (value) {
592
- await this.device.set_attribute({ SMART_EYE: true });
593
- }
594
- else {
595
- await this.device.set_attribute({ SMART_EYE: false });
596
- }
597
- }
598
- getAuxHeating() {
599
- return this.device.attributes.POWER === true && this.device.attributes.AUX_HEATING === true;
600
- }
601
- async setAuxHeating(value) {
602
- if (value) {
603
- await this.device.set_attribute({ AUX_HEATING: true });
604
- }
605
- else {
606
- await this.device.set_attribute({ AUX_HEATING: false });
607
- }
608
- }
609
- getSelfCleanState() {
610
- return this.device.attributes.SELF_CLEAN === true;
611
- }
612
- async setSelfCleanState(value) {
613
- await this.device.set_self_clean(value === true);
614
- }
615
- getIonState() {
616
- return this.device.attributes.POWER === true && this.device.attributes.ION === true;
617
- }
618
- async setIonState(value) {
619
- await this.device.set_ion(value === true);
620
- }
621
- getRateSelect() {
622
- var _a;
623
- return (_a = this.device.attributes.RATE_SELECT) !== null && _a !== void 0 ? _a : 100;
624
- }
625
- async setRateSelect(value) {
626
- await this.device.set_rate_select(value);
627
- }
628
- getSwingAngleCurrentPosition() {
629
- const value = this.swingAngleMainControl === platformUtils_1.SwingAngle.VERTICAL
630
- ? this.device.attributes.WIND_SWING_UD_ANGLE
631
- : this.device.attributes.WIND_SWING_LR_ANGLE;
632
- return value === 1 ? 0 : value;
633
- }
634
- getSwingAngleTargetPosition() {
635
- return this.getSwingAngleCurrentPosition();
636
- }
637
- async setSwingAngleTargetPosition(value) {
638
- await this.device.set_swing_angle(this.swingAngleMainControl, Math.max(1, value));
639
- }
640
- getSwingAnglePositionState() {
641
- return this.platform.Characteristic.PositionState.STOPPED;
642
- }
643
- getSwingAngleCurrentHorizontalTiltAngle() {
644
- return this.device.attributes.WIND_SWING_LR_ANGLE === 1 ? 0 : this.device.attributes.WIND_SWING_LR_ANGLE;
645
- }
646
- getSwingAngleTargetHorizontalTiltAngle() {
647
- return this.getSwingAngleCurrentHorizontalTiltAngle();
648
- }
649
- async setSwingAngleTargetHorizontalTiltAngle(value) {
650
- await this.device.set_swing_angle(platformUtils_1.SwingAngle.HORIZONTAL, Math.max(1, value));
651
- }
652
- getSwingAngleCurrentVerticalTiltAngle() {
653
- return this.device.attributes.WIND_SWING_UD_ANGLE === 1 ? 0 : this.device.attributes.WIND_SWING_UD_ANGLE;
654
- }
655
- getSwingAngleTargetVerticalTiltAngle() {
656
- return this.getSwingAngleCurrentVerticalTiltAngle();
657
- }
658
- async setSwingAngleTargetVerticalTiltAngle(value) {
659
- await this.device.set_swing_angle(platformUtils_1.SwingAngle.VERTICAL, Math.max(1, value));
660
- }
661
- }
662
- exports.default = AirConditionerAccessory;
1
+ import BaseAccessory from './BaseAccessory.js';
2
+ import { SwingAngle, SwingMode } from '../platformUtils.js';
3
+ export default class AirConditionerAccessory extends BaseAccessory {
4
+ device;
5
+ configDev;
6
+ service;
7
+ outDoorTemperatureService;
8
+ displayService;
9
+ fanOnlyService;
10
+ fanService;
11
+ ecoModeService;
12
+ breezeAwayService;
13
+ dryModeService;
14
+ boostModeService;
15
+ auxService;
16
+ auxHeatingService;
17
+ selfCleanService;
18
+ ionService;
19
+ rateSelectService;
20
+ swingAngleService;
21
+ swingAngleMainControl;
22
+ /*********************************************************************
23
+ * Constructor registers all the service types with Homebridge, registers
24
+ * a callback function with the MideaDevice class, and requests device status.
25
+ */
26
+ constructor(platform, accessory, device, configDev) {
27
+ super(platform, accessory, device, configDev);
28
+ this.device = device;
29
+ this.configDev = configDev;
30
+ this.service =
31
+ this.accessory.getService(this.platform.Service.HeaterCooler) || this.accessory.addService(this.platform.Service.HeaterCooler);
32
+ this.service.setCharacteristic(this.platform.Characteristic.Name, this.device.name);
33
+ this.service.getCharacteristic(this.platform.Characteristic.Active).onGet(this.getActive.bind(this)).onSet(this.setActive.bind(this));
34
+ this.service
35
+ .getCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits)
36
+ .onGet(this.getTemperatureDisplayUnits.bind(this))
37
+ .onSet(this.setTemperatureDisplayUnits.bind(this));
38
+ this.service
39
+ .getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState)
40
+ .onGet(this.getCurrentHeaterCoolerState.bind(this));
41
+ this.service
42
+ .getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
43
+ .onGet(this.getTargetHeaterCoolerState.bind(this))
44
+ .onSet(this.setTargetHeaterCoolerState.bind(this))
45
+ .setProps({
46
+ validValues: this.configDev.AC_options.heatingCapable
47
+ ? [
48
+ this.platform.Characteristic.TargetHeaterCoolerState.AUTO,
49
+ this.platform.Characteristic.TargetHeaterCoolerState.HEAT,
50
+ this.platform.Characteristic.TargetHeaterCoolerState.COOL,
51
+ ]
52
+ : [this.platform.Characteristic.TargetHeaterCoolerState.AUTO, this.platform.Characteristic.TargetHeaterCoolerState.COOL],
53
+ });
54
+ this.service.getCharacteristic(this.platform.Characteristic.CurrentTemperature).onGet(this.getCurrentTemperature.bind(this));
55
+ this.service
56
+ .getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
57
+ .onGet(this.getTargetTemperature.bind(this))
58
+ .onSet(this.setTargetTemperature.bind(this))
59
+ .setProps({
60
+ minValue: this.configDev.AC_options.minTemp,
61
+ maxValue: this.configDev.AC_options.maxTemp,
62
+ minStep: this.configDev.AC_options.tempStep,
63
+ });
64
+ this.service
65
+ .getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
66
+ .onGet(this.getTargetTemperature.bind(this))
67
+ .onSet(this.setTargetTemperature.bind(this))
68
+ .setProps({
69
+ minValue: this.configDev.AC_options.minTemp,
70
+ maxValue: this.configDev.AC_options.maxTemp,
71
+ minStep: this.configDev.AC_options.tempStep,
72
+ });
73
+ this.service
74
+ .getCharacteristic(this.platform.Characteristic.RotationSpeed)
75
+ .onGet(this.getRotationSpeed.bind(this))
76
+ .onSet(this.setRotationSpeed.bind(this));
77
+ // Swing modes
78
+ if (this.configDev.AC_options.swing.mode !== SwingMode.NONE) {
79
+ this.service
80
+ .getCharacteristic(this.platform.Characteristic.SwingMode)
81
+ .onGet(this.getSwingMode.bind(this))
82
+ .onSet(this.setSwingMode.bind(this));
83
+ }
84
+ // Outdoor temperature sensor
85
+ this.outDoorTemperatureService = this.accessory.getServiceById(this.platform.Service.TemperatureSensor, 'Outdoor');
86
+ if (this.configDev.AC_options.outDoorTemp) {
87
+ this.outDoorTemperatureService ??= this.accessory.addService(this.platform.Service.TemperatureSensor, `${this.device.name} Outdoor`, 'Outdoor');
88
+ this.outDoorTemperatureService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Outdoor`);
89
+ this.outDoorTemperatureService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Outdoor`);
90
+ this.outDoorTemperatureService
91
+ .getCharacteristic(this.platform.Characteristic.CurrentTemperature)
92
+ .onGet(this.getOutdoorTemperature.bind(this));
93
+ this.outDoorTemperatureService
94
+ .getCharacteristic(this.platform.Characteristic.StatusFault)
95
+ .onGet(() => this.device.attributes.OUTDOOR_TEMPERATURE === undefined
96
+ ? this.platform.Characteristic.StatusFault.GENERAL_FAULT
97
+ : this.platform.Characteristic.StatusFault.NO_FAULT);
98
+ }
99
+ else if (this.outDoorTemperatureService) {
100
+ this.accessory.removeService(this.outDoorTemperatureService);
101
+ }
102
+ // Fan-only mode switch
103
+ this.fanOnlyService = this.accessory.getServiceById(this.platform.Service.Switch, 'FanOnly');
104
+ if (this.configDev.AC_options.fanOnlyModeSwitch) {
105
+ this.fanOnlyService ??= this.accessory.addService(this.platform.Service.Switch, `${this.device.name} FanOnly`, 'FanOnly');
106
+ this.fanOnlyService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Fan-only Mode`);
107
+ this.fanOnlyService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Fan-only Mode`);
108
+ this.fanOnlyService
109
+ .getCharacteristic(this.platform.Characteristic.On)
110
+ .onGet(this.getFanOnlyMode.bind(this))
111
+ .onSet(this.setFanOnlyMode.bind(this));
112
+ }
113
+ else if (this.fanOnlyService) {
114
+ this.accessory.removeService(this.fanOnlyService);
115
+ }
116
+ // Fan accessory
117
+ this.fanService = this.accessory.getServiceById(this.platform.Service.Fanv2, 'Fan');
118
+ if (this.configDev.AC_options.fanAccessory) {
119
+ this.fanService ??= this.accessory.addService(this.platform.Service.Fanv2, `${this.device.name} Fan`, 'Fan');
120
+ this.fanService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Fan`);
121
+ this.fanService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Fan`);
122
+ this.fanService
123
+ .getCharacteristic(this.platform.Characteristic.Active)
124
+ .onGet(this.getActive.bind(this))
125
+ .onSet(this.setActive.bind(this));
126
+ this.fanService
127
+ .getCharacteristic(this.platform.Characteristic.RotationSpeed)
128
+ .onGet(this.getRotationSpeed.bind(this))
129
+ .onSet(this.setRotationSpeed.bind(this));
130
+ this.fanService
131
+ .getCharacteristic(this.platform.Characteristic.TargetFanState)
132
+ .onGet(this.getFanState.bind(this))
133
+ .onSet(this.setFanState.bind(this));
134
+ this.fanService
135
+ .getCharacteristic(this.platform.Characteristic.SwingMode)
136
+ .onGet(this.getSwingMode.bind(this))
137
+ .onSet(this.setSwingMode.bind(this));
138
+ }
139
+ else if (this.fanService) {
140
+ this.accessory.removeService(this.fanService);
141
+ }
142
+ // Display switch
143
+ this.displayService = this.accessory.getServiceById(this.platform.Service.Switch, 'Display');
144
+ if (this.configDev.AC_options.displaySwitch.flag) {
145
+ this.device.set_alternate_switch_display(this.configDev.AC_options.displaySwitch.command);
146
+ this.displayService ??= this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Display`, 'Display');
147
+ this.displayService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Display`);
148
+ this.displayService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Display`);
149
+ this.displayService
150
+ .getCharacteristic(this.platform.Characteristic.On)
151
+ .onGet(this.getDisplayActive.bind(this))
152
+ .onSet(this.setDisplayActive.bind(this));
153
+ }
154
+ else if (this.displayService) {
155
+ this.accessory.removeService(this.displayService);
156
+ }
157
+ // Eco mode switch
158
+ this.ecoModeService = this.accessory.getServiceById(this.platform.Service.Switch, 'EcoMode');
159
+ if (this.configDev.AC_options.ecoSwitch) {
160
+ this.ecoModeService ??= this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Eco`, 'EcoMode');
161
+ this.ecoModeService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Eco`);
162
+ this.ecoModeService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Eco`);
163
+ this.ecoModeService
164
+ .getCharacteristic(this.platform.Characteristic.On)
165
+ .onGet(this.getEcoMode.bind(this))
166
+ .onSet(this.setEcoMode.bind(this));
167
+ }
168
+ else if (this.ecoModeService) {
169
+ this.accessory.removeService(this.ecoModeService);
170
+ }
171
+ // Breeze away switch
172
+ this.breezeAwayService = this.accessory.getServiceById(this.platform.Service.Switch, 'BreezeAway');
173
+ if (this.configDev.AC_options.breezeAwaySwitch) {
174
+ this.breezeAwayService ??= this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Breeze`, 'BreezeAway');
175
+ this.breezeAwayService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Breeze`);
176
+ this.breezeAwayService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Breeze`);
177
+ this.breezeAwayService
178
+ .getCharacteristic(this.platform.Characteristic.On)
179
+ .onGet(this.getBreezeAway.bind(this))
180
+ .onSet(this.setBreezeAway.bind(this));
181
+ }
182
+ else if (this.breezeAwayService) {
183
+ this.accessory.removeService(this.breezeAwayService);
184
+ }
185
+ // Dry mode switch
186
+ this.dryModeService = this.accessory.getServiceById(this.platform.Service.Switch, 'DryMode');
187
+ if (this.configDev.AC_options.dryModeSwitch) {
188
+ this.dryModeService ??= this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Dry`, 'DryMode');
189
+ this.dryModeService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Dry`);
190
+ this.dryModeService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Dry`);
191
+ this.dryModeService
192
+ .getCharacteristic(this.platform.Characteristic.On)
193
+ .onGet(this.getDryMode.bind(this))
194
+ .onSet(this.setDryMode.bind(this));
195
+ }
196
+ else if (this.dryModeService) {
197
+ this.accessory.removeService(this.dryModeService);
198
+ }
199
+ this.boostModeService = this.accessory.getServiceById(this.platform.Service.Switch, 'BoostMode');
200
+ if (this.configDev.AC_options.boostModeSwitch) {
201
+ this.boostModeService ??= this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Boost`, 'BoostMode');
202
+ this.boostModeService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Boost`);
203
+ this.boostModeService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Boost`);
204
+ this.boostModeService
205
+ .getCharacteristic(this.platform.Characteristic.On)
206
+ .onGet(this.getBoostMode.bind(this))
207
+ .onSet(this.setBoostMode.bind(this));
208
+ }
209
+ else if (this.boostModeService) {
210
+ this.accessory.removeService(this.boostModeService);
211
+ }
212
+ // Aux switch
213
+ this.auxService = this.accessory.getServiceById(this.platform.Service.Switch, 'Aux');
214
+ if (this.configDev.AC_options.auxHeatingSwitches) {
215
+ this.auxService ??= this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Aux`, 'Aux');
216
+ this.auxService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Aux`);
217
+ this.auxService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Aux`);
218
+ this.auxService.getCharacteristic(this.platform.Characteristic.On).onGet(this.getAux.bind(this)).onSet(this.setAux.bind(this));
219
+ }
220
+ else if (this.auxService) {
221
+ this.accessory.removeService(this.auxService);
222
+ }
223
+ // Aux+Heat switch
224
+ this.auxHeatingService = this.accessory.getServiceById(this.platform.Service.Switch, 'AuxHeating');
225
+ if (this.configDev.AC_options.auxHeatingSwitches) {
226
+ this.auxHeatingService ??= this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Aux+Heat`, 'AuxHeating');
227
+ this.auxHeatingService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Aux+Heat`);
228
+ this.auxHeatingService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Aux+Heat`);
229
+ this.auxHeatingService
230
+ .getCharacteristic(this.platform.Characteristic.On)
231
+ .onGet(this.getAuxHeating.bind(this))
232
+ .onSet(this.setAuxHeating.bind(this));
233
+ }
234
+ else if (this.auxHeatingService) {
235
+ this.accessory.removeService(this.auxHeatingService);
236
+ }
237
+ // Self-cleaning switch
238
+ this.selfCleanService = this.accessory.getServiceById(this.platform.Service.Switch, 'SelfClean');
239
+ if (this.configDev.AC_options.selfCleanSwitch) {
240
+ this.selfCleanService ??= this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Self-cleaning`, 'SelfClean');
241
+ this.selfCleanService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Self-cleaning`);
242
+ this.selfCleanService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Self-cleaning`);
243
+ this.selfCleanService
244
+ .getCharacteristic(this.platform.Characteristic.On)
245
+ .onGet(this.getSelfCleanState.bind(this))
246
+ .onSet(this.setSelfCleanState.bind(this));
247
+ }
248
+ else if (this.selfCleanService) {
249
+ this.accessory.removeService(this.selfCleanService);
250
+ }
251
+ // ION switch
252
+ this.ionService = this.accessory.getServiceById(this.platform.Service.Switch, 'ION');
253
+ if (this.configDev.AC_options.ionSwitch) {
254
+ this.ionService ??= this.accessory.addService(this.platform.Service.Switch, `${this.device.name} ION`, 'ION');
255
+ this.ionService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} ION`);
256
+ this.ionService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} ION`);
257
+ this.ionService
258
+ .getCharacteristic(this.platform.Characteristic.On)
259
+ .onGet(this.getIonState.bind(this))
260
+ .onSet(this.setIonState.bind(this));
261
+ }
262
+ else if (this.ionService) {
263
+ this.accessory.removeService(this.ionService);
264
+ }
265
+ // Rate select slider
266
+ this.rateSelectService = this.accessory.getServiceById(this.platform.Service.Lightbulb, 'Gear');
267
+ if (this.configDev.AC_options.rateSelector) {
268
+ this.rateSelectService ??= this.accessory.addService(this.platform.Service.Lightbulb, `${this.device.name} Gear`, 'Gear');
269
+ this.rateSelectService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Gear`);
270
+ this.rateSelectService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Gear`);
271
+ this.rateSelectService
272
+ .getCharacteristic(this.platform.Characteristic.On)
273
+ .onGet(this.getActive.bind(this))
274
+ .onSet(this.setActive.bind(this));
275
+ this.rateSelectService
276
+ .getCharacteristic(this.platform.Characteristic.Brightness)
277
+ .setProps({
278
+ validValues: [0, 50, 75, 100],
279
+ })
280
+ .onGet(this.getRateSelect.bind(this))
281
+ .onSet(this.setRateSelect.bind(this));
282
+ }
283
+ else if (this.rateSelectService) {
284
+ this.accessory.removeService(this.rateSelectService);
285
+ }
286
+ const swingProps = this.configDev.AC_options.swing;
287
+ this.swingAngleMainControl =
288
+ swingProps.mode === SwingMode.VERTICAL || (swingProps.mode === SwingMode.BOTH && swingProps.angleMainControl === SwingAngle.VERTICAL)
289
+ ? SwingAngle.VERTICAL
290
+ : SwingAngle.HORIZONTAL;
291
+ // Swing angle accessory
292
+ this.swingAngleService = this.accessory.getServiceById(this.platform.Service.WindowCovering, 'SwingAngle');
293
+ if (swingProps.mode !== SwingMode.NONE && swingProps.angleAccessory) {
294
+ this.swingAngleService ??= this.accessory.addService(this.platform.Service.WindowCovering, `${this.device.name} Swing`, 'SwingAngle');
295
+ this.swingAngleService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Swing`);
296
+ this.swingAngleService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Swing`);
297
+ this.swingAngleService
298
+ .getCharacteristic(this.platform.Characteristic.CurrentPosition)
299
+ .onGet(this.getSwingAngleCurrentPosition.bind(this));
300
+ this.swingAngleService
301
+ .getCharacteristic(this.platform.Characteristic.TargetPosition)
302
+ .onGet(this.getSwingAngleTargetPosition.bind(this))
303
+ .onSet(this.setSwingAngleTargetPosition.bind(this));
304
+ this.swingAngleService
305
+ .getCharacteristic(this.platform.Characteristic.PositionState)
306
+ .onGet(this.getSwingAnglePositionState.bind(this));
307
+ if (swingProps.mode === SwingMode.BOTH) {
308
+ this.swingAngleService
309
+ .getCharacteristic(this.platform.Characteristic.CurrentHorizontalTiltAngle)
310
+ .onGet(this.getSwingAngleCurrentHorizontalTiltAngle.bind(this));
311
+ this.swingAngleService
312
+ .getCharacteristic(this.platform.Characteristic.TargetHorizontalTiltAngle)
313
+ .onGet(this.getSwingAngleTargetHorizontalTiltAngle.bind(this))
314
+ .onSet(this.setSwingAngleTargetHorizontalTiltAngle.bind(this));
315
+ this.swingAngleService
316
+ .getCharacteristic(this.platform.Characteristic.CurrentVerticalTiltAngle)
317
+ .onGet(this.getSwingAngleCurrentVerticalTiltAngle.bind(this));
318
+ this.swingAngleService
319
+ .getCharacteristic(this.platform.Characteristic.TargetVerticalTiltAngle)
320
+ .onGet(this.getSwingAngleTargetVerticalTiltAngle.bind(this))
321
+ .onSet(this.setSwingAngleTargetVerticalTiltAngle.bind(this));
322
+ }
323
+ }
324
+ // Misc
325
+ this.device.attributes.PROMPT_TONE = this.configDev.AC_options.audioFeedback;
326
+ this.device.attributes.TEMP_FAHRENHEIT = this.configDev.AC_options.fahrenheit;
327
+ }
328
+ /*********************************************************************
329
+ * Callback function called by MideaDevice whenever there is a change to
330
+ * any attribute value.
331
+ */
332
+ async updateCharacteristics(attributes) {
333
+ for (const [k, v] of Object.entries(attributes)) {
334
+ this.platform.log.debug(`[${this.device.name}] Set attribute ${k} to: ${v}`);
335
+ let updateState = false;
336
+ switch (k.toLowerCase()) {
337
+ case 'power':
338
+ updateState = true;
339
+ break;
340
+ case 'temp_fahrenheit':
341
+ this.service.updateCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits, this.getTemperatureDisplayUnits());
342
+ break;
343
+ case 'screen_display':
344
+ case 'screen_display_new':
345
+ this.displayService?.updateCharacteristic(this.platform.Characteristic.On, this.getDisplayActive());
346
+ break;
347
+ case 'target_temperature':
348
+ // If MODE is 4 then device is heating. Therefore target temperature value must be heating target? Right?
349
+ if (this.device.attributes.MODE === 4) {
350
+ this.service.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.getTargetTemperature());
351
+ }
352
+ else {
353
+ this.service.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.getTargetTemperature());
354
+ }
355
+ updateState = true;
356
+ break;
357
+ case 'indoor_temperature':
358
+ this.service.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.getCurrentTemperature());
359
+ break;
360
+ case 'outdoor_temperature':
361
+ this.outDoorTemperatureService?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.getOutdoorTemperature());
362
+ break;
363
+ case 'fan_speed':
364
+ updateState = true;
365
+ break;
366
+ case 'fan_auto':
367
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.TargetFanState, this.getFanState());
368
+ break;
369
+ case 'swing_vertical':
370
+ case 'swing_horizontal':
371
+ this.service.updateCharacteristic(this.platform.Characteristic.SwingMode, this.getSwingMode());
372
+ break;
373
+ case 'mode':
374
+ updateState = true;
375
+ break;
376
+ case 'eco_mode':
377
+ this.ecoModeService?.updateCharacteristic(this.platform.Characteristic.On, this.getEcoMode());
378
+ break;
379
+ case 'indirect_wind':
380
+ this.breezeAwayService?.updateCharacteristic(this.platform.Characteristic.On, this.getBreezeAway());
381
+ break;
382
+ case 'aux_heating':
383
+ this.auxHeatingService?.updateCharacteristic(this.platform.Characteristic.On, this.getAuxHeating());
384
+ break;
385
+ case 'smart_eye':
386
+ this.auxService?.updateCharacteristic(this.platform.Characteristic.On, this.getAux());
387
+ break;
388
+ case 'wind_swing_lr_angle':
389
+ case 'wind_swing_ud_angle':
390
+ this.swingAngleService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.getSwingAngleCurrentPosition());
391
+ this.swingAngleService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.getSwingAngleTargetPosition());
392
+ if (this.configDev.AC_options.swing.mode === SwingMode.BOTH) {
393
+ this.swingAngleService?.updateCharacteristic(this.platform.Characteristic.CurrentHorizontalTiltAngle, this.getSwingAngleCurrentHorizontalTiltAngle());
394
+ this.swingAngleService?.updateCharacteristic(this.platform.Characteristic.CurrentVerticalTiltAngle, this.getSwingAngleCurrentVerticalTiltAngle());
395
+ this.swingAngleService?.updateCharacteristic(this.platform.Characteristic.TargetHorizontalTiltAngle, this.getSwingAngleTargetHorizontalTiltAngle());
396
+ this.swingAngleService?.updateCharacteristic(this.platform.Characteristic.TargetVerticalTiltAngle, this.getSwingAngleTargetVerticalTiltAngle());
397
+ }
398
+ break;
399
+ case 'self_clean':
400
+ updateState = true;
401
+ this.selfCleanService?.updateCharacteristic(this.platform.Characteristic.On, this.getSelfCleanState());
402
+ break;
403
+ case 'ion':
404
+ this.ionService?.updateCharacteristic(this.platform.Characteristic.On, this.getIonState());
405
+ break;
406
+ case 'rate_select':
407
+ this.rateSelectService?.updateCharacteristic(this.platform.Characteristic.Brightness, this.getRateSelect());
408
+ break;
409
+ default:
410
+ this.platform.log.debug(`[${this.device.name}] Attempt to set unsupported attribute ${k} to ${v}`);
411
+ }
412
+ if (updateState) {
413
+ this.service.updateCharacteristic(this.platform.Characteristic.Active, this.getActive());
414
+ this.service.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.getTargetHeaterCoolerState());
415
+ this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.getCurrentHeaterCoolerState());
416
+ this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.getRotationSpeed());
417
+ this.fanOnlyService?.updateCharacteristic(this.platform.Characteristic.On, this.getFanOnlyMode());
418
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.getActive());
419
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.getRotationSpeed());
420
+ this.dryModeService?.updateCharacteristic(this.platform.Characteristic.On, this.getDryMode());
421
+ this.displayService?.updateCharacteristic(this.platform.Characteristic.On, this.getDisplayActive());
422
+ this.ecoModeService?.updateCharacteristic(this.platform.Characteristic.On, this.getEcoMode());
423
+ this.breezeAwayService?.updateCharacteristic(this.platform.Characteristic.On, this.getBreezeAway());
424
+ this.auxService?.updateCharacteristic(this.platform.Characteristic.On, this.getAux());
425
+ this.auxHeatingService?.updateCharacteristic(this.platform.Characteristic.On, this.getAuxHeating());
426
+ }
427
+ }
428
+ }
429
+ /*********************************************************************
430
+ * Callback functions for each Homebridge/HomeKit service
431
+ *
432
+ */
433
+ getActive() {
434
+ // Show as inactive if device is off
435
+ return this.device.attributes.POWER ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE;
436
+ }
437
+ async setActive(value) {
438
+ await this.device.set_attribute({ POWER: !!value });
439
+ this.device.attributes.SCREEN_DISPLAY = !!value;
440
+ this.displayService?.updateCharacteristic(this.platform.Characteristic.On, !!value);
441
+ }
442
+ getTemperatureDisplayUnits() {
443
+ return this.device.attributes.TEMP_FAHRENHEIT
444
+ ? this.platform.Characteristic.TemperatureDisplayUnits.FAHRENHEIT
445
+ : this.platform.Characteristic.TemperatureDisplayUnits.CELSIUS;
446
+ }
447
+ async setTemperatureDisplayUnits(value) {
448
+ await this.device.set_attribute({ TEMP_FAHRENHEIT: value === this.platform.Characteristic.TemperatureDisplayUnits.FAHRENHEIT });
449
+ }
450
+ getCurrentHeaterCoolerState() {
451
+ if (this.device.attributes.POWER && this.device.attributes.MODE > 0 && this.device.attributes.MODE < 5) {
452
+ if (this.device.attributes.TARGET_TEMPERATURE < (this.device.attributes.INDOOR_TEMPERATURE ?? 0)) {
453
+ if ([1, 2].includes(this.device.attributes.MODE)) {
454
+ return this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
455
+ }
456
+ else {
457
+ return this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
458
+ }
459
+ }
460
+ else if (this.device.attributes.TARGET_TEMPERATURE === this.device.attributes.INDOOR_TEMPERATURE) {
461
+ return this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
462
+ }
463
+ else {
464
+ if (this.device.attributes.MODE === 4) {
465
+ return this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
466
+ }
467
+ else {
468
+ return this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
469
+ }
470
+ }
471
+ }
472
+ else {
473
+ return this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
474
+ }
475
+ }
476
+ getTargetHeaterCoolerState() {
477
+ if (this.device.attributes.MODE === 2) {
478
+ return this.platform.Characteristic.TargetHeaterCoolerState.COOL;
479
+ }
480
+ else if (this.device.attributes.MODE === 4) {
481
+ return this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
482
+ }
483
+ else {
484
+ return this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
485
+ }
486
+ }
487
+ async setTargetHeaterCoolerState(value) {
488
+ switch (value) {
489
+ case this.platform.Characteristic.TargetHeaterCoolerState.AUTO:
490
+ await this.device.set_attribute({ POWER: true, MODE: 1 });
491
+ break;
492
+ case this.platform.Characteristic.TargetHeaterCoolerState.COOL:
493
+ await this.device.set_attribute({ POWER: true, MODE: 2 });
494
+ break;
495
+ case this.platform.Characteristic.TargetHeaterCoolerState.HEAT:
496
+ await this.device.set_attribute({ POWER: true, MODE: 4 });
497
+ break;
498
+ }
499
+ }
500
+ getCurrentTemperature() {
501
+ return this.device.attributes.INDOOR_TEMPERATURE ?? this.configDev.AC_options.minTemp;
502
+ }
503
+ getTargetTemperature() {
504
+ return Math.max(this.configDev.AC_options.minTemp, Math.min(this.configDev.AC_options.maxTemp, this.device.attributes.TARGET_TEMPERATURE));
505
+ }
506
+ getFanOnlyMode() {
507
+ return this.device.attributes.POWER === true && this.device.attributes.MODE === 5;
508
+ }
509
+ async setFanOnlyMode(value) {
510
+ if (value) {
511
+ await this.device.set_attribute({ POWER: true, MODE: 5 });
512
+ }
513
+ else {
514
+ await this.device.set_attribute({ POWER: false, MODE: 0 });
515
+ }
516
+ }
517
+ getFanState() {
518
+ return this.device.attributes.FAN_AUTO;
519
+ }
520
+ async setFanState(value) {
521
+ await this.device.set_fan_auto(value === this.platform.Characteristic.TargetFanState.AUTO);
522
+ }
523
+ async setTargetTemperature(value) {
524
+ value = Math.max(this.configDev.AC_options.minTemp, Math.min(this.configDev.AC_options.maxTemp, value));
525
+ await this.device.set_target_temperature(value);
526
+ }
527
+ getSwingMode() {
528
+ return this.device.attributes.SWING_HORIZONTAL || this.device.attributes.SWING_VERTICAL
529
+ ? this.platform.Characteristic.SwingMode.SWING_ENABLED
530
+ : this.platform.Characteristic.SwingMode.SWING_DISABLED;
531
+ }
532
+ async setSwingMode(value) {
533
+ switch (value) {
534
+ case this.platform.Characteristic.SwingMode.SWING_ENABLED:
535
+ await this.device.set_swing([SwingMode.HORIZONTAL, SwingMode.BOTH].includes(this.configDev.AC_options.swing.mode), [SwingMode.VERTICAL, SwingMode.BOTH].includes(this.configDev.AC_options.swing.mode));
536
+ break;
537
+ case this.platform.Characteristic.SwingMode.SWING_DISABLED:
538
+ await this.device.set_swing(false, false);
539
+ break;
540
+ }
541
+ }
542
+ getRotationSpeed() {
543
+ return Math.min(100, this.device.attributes.FAN_SPEED ?? 0);
544
+ }
545
+ async setRotationSpeed(value) {
546
+ await this.device.set_attribute({ FAN_SPEED: value });
547
+ }
548
+ getOutdoorTemperature() {
549
+ return this.device.attributes.OUTDOOR_TEMPERATURE ?? -270;
550
+ }
551
+ getDisplayActive() {
552
+ return this.device.attributes.SCREEN_DISPLAY === true;
553
+ }
554
+ async setDisplayActive(value) {
555
+ if (this.device.attributes.POWER) {
556
+ await this.device.set_attribute({ SCREEN_DISPLAY: !!value });
557
+ }
558
+ }
559
+ getEcoMode() {
560
+ return this.device.attributes.POWER === true && this.device.attributes.ECO_MODE;
561
+ }
562
+ async setEcoMode(value) {
563
+ await this.device.set_attribute({ ECO_MODE: !!value });
564
+ }
565
+ getBreezeAway() {
566
+ return this.device.attributes.POWER === true && this.device.attributes.INDIRECT_WIND;
567
+ }
568
+ async setBreezeAway(value) {
569
+ await this.device.set_attribute({ INDIRECT_WIND: !!value });
570
+ }
571
+ getDryMode() {
572
+ return this.device.attributes.POWER === true && this.device.attributes.MODE === 3;
573
+ }
574
+ async setDryMode(value) {
575
+ if (value) {
576
+ await this.device.set_attribute({ POWER: true, MODE: 3 });
577
+ }
578
+ else {
579
+ await this.device.set_attribute({ POWER: false, MODE: 0 });
580
+ }
581
+ }
582
+ getBoostMode() {
583
+ return this.device.attributes.POWER === true && this.device.attributes.BOOST_MODE;
584
+ }
585
+ async setBoostMode(value) {
586
+ if (value) {
587
+ await this.device.set_attribute({ POWER: true, BOOST_MODE: true });
588
+ }
589
+ else {
590
+ await this.device.set_attribute({ BOOST_MODE: false });
591
+ }
592
+ }
593
+ getAux() {
594
+ return this.device.attributes.POWER === true && this.device.attributes.SMART_EYE === true;
595
+ }
596
+ async setAux(value) {
597
+ if (value) {
598
+ await this.device.set_attribute({ SMART_EYE: true });
599
+ }
600
+ else {
601
+ await this.device.set_attribute({ SMART_EYE: false });
602
+ }
603
+ }
604
+ getAuxHeating() {
605
+ return this.device.attributes.POWER === true && this.device.attributes.AUX_HEATING === true;
606
+ }
607
+ async setAuxHeating(value) {
608
+ if (value) {
609
+ await this.device.set_attribute({ AUX_HEATING: true });
610
+ }
611
+ else {
612
+ await this.device.set_attribute({ AUX_HEATING: false });
613
+ }
614
+ }
615
+ getSelfCleanState() {
616
+ return this.device.attributes.SELF_CLEAN === true;
617
+ }
618
+ async setSelfCleanState(value) {
619
+ await this.device.set_self_clean(value === true);
620
+ }
621
+ getIonState() {
622
+ return this.device.attributes.POWER === true && this.device.attributes.ION === true;
623
+ }
624
+ async setIonState(value) {
625
+ await this.device.set_ion(value === true);
626
+ }
627
+ getRateSelect() {
628
+ return this.device.attributes.RATE_SELECT ?? 100;
629
+ }
630
+ async setRateSelect(value) {
631
+ await this.device.set_rate_select(value);
632
+ }
633
+ getSwingAngleCurrentPosition() {
634
+ const value = this.swingAngleMainControl === SwingAngle.VERTICAL
635
+ ? this.device.attributes.WIND_SWING_UD_ANGLE
636
+ : this.device.attributes.WIND_SWING_LR_ANGLE;
637
+ return value === 1 ? 0 : value;
638
+ }
639
+ getSwingAngleTargetPosition() {
640
+ return this.getSwingAngleCurrentPosition();
641
+ }
642
+ async setSwingAngleTargetPosition(value) {
643
+ await this.device.set_swing_angle(this.swingAngleMainControl, Math.max(1, value));
644
+ }
645
+ getSwingAnglePositionState() {
646
+ return this.platform.Characteristic.PositionState.STOPPED;
647
+ }
648
+ getSwingAngleCurrentHorizontalTiltAngle() {
649
+ return this.device.attributes.WIND_SWING_LR_ANGLE === 1 ? 0 : this.device.attributes.WIND_SWING_LR_ANGLE;
650
+ }
651
+ getSwingAngleTargetHorizontalTiltAngle() {
652
+ return this.getSwingAngleCurrentHorizontalTiltAngle();
653
+ }
654
+ async setSwingAngleTargetHorizontalTiltAngle(value) {
655
+ await this.device.set_swing_angle(SwingAngle.HORIZONTAL, Math.max(1, value));
656
+ }
657
+ getSwingAngleCurrentVerticalTiltAngle() {
658
+ return this.device.attributes.WIND_SWING_UD_ANGLE === 1 ? 0 : this.device.attributes.WIND_SWING_UD_ANGLE;
659
+ }
660
+ getSwingAngleTargetVerticalTiltAngle() {
661
+ return this.getSwingAngleCurrentVerticalTiltAngle();
662
+ }
663
+ async setSwingAngleTargetVerticalTiltAngle(value) {
664
+ await this.device.set_swing_angle(SwingAngle.VERTICAL, Math.max(1, value));
665
+ }
666
+ }
663
667
  //# sourceMappingURL=AirConditionerAccessory.js.map