homebridge-midea-platform 1.2.0-beta.2 → 1.2.0-beta.4

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 (89) hide show
  1. package/.husky/pre-commit +0 -0
  2. package/AC_ori.lua +5140 -0
  3. package/config.schema.json +14 -2
  4. package/dist/accessory/AccessoryFactory.d.ts +13 -12
  5. package/dist/accessory/AccessoryFactory.d.ts.map +1 -1
  6. package/dist/accessory/AccessoryFactory.js +37 -31
  7. package/dist/accessory/AccessoryFactory.js.map +1 -1
  8. package/dist/accessory/AirConditionerAccessory.d.ts +98 -92
  9. package/dist/accessory/AirConditionerAccessory.d.ts.map +1 -1
  10. package/dist/accessory/AirConditionerAccessory.js +662 -607
  11. package/dist/accessory/AirConditionerAccessory.js.map +1 -1
  12. package/dist/accessory/BaseAccessory.d.ts +11 -11
  13. package/dist/accessory/BaseAccessory.js +21 -21
  14. package/dist/accessory/DehumidifierAccessory.d.ts +45 -45
  15. package/dist/accessory/DehumidifierAccessory.js +344 -344
  16. package/dist/accessory/DishwasherAccessory.d.ts +30 -30
  17. package/dist/accessory/DishwasherAccessory.js +63 -63
  18. package/dist/accessory/ElectricWaterHeaterAccessory.d.ts +44 -44
  19. package/dist/accessory/ElectricWaterHeaterAccessory.js +176 -176
  20. package/dist/accessory/FanAccessory.d.ts +39 -39
  21. package/dist/accessory/FanAccessory.js +123 -123
  22. package/dist/accessory/FrontLoadWasherAccessory.d.ts +30 -30
  23. package/dist/accessory/FrontLoadWasherAccessory.js +66 -66
  24. package/dist/accessory/GasWaterHeaterAccessory.d.ts +51 -51
  25. package/dist/accessory/GasWaterHeaterAccessory.js +216 -216
  26. package/dist/core/MideaCloud.d.ts +35 -35
  27. package/dist/core/MideaCloud.js +350 -350
  28. package/dist/core/MideaConstants.d.ts +50 -50
  29. package/dist/core/MideaConstants.js +58 -58
  30. package/dist/core/MideaDevice.d.ts +76 -76
  31. package/dist/core/MideaDevice.js +409 -409
  32. package/dist/core/MideaDiscover.d.ts +35 -35
  33. package/dist/core/MideaDiscover.js +212 -212
  34. package/dist/core/MideaMessage.d.ts +75 -75
  35. package/dist/core/MideaMessage.js +184 -184
  36. package/dist/core/MideaPacketBuilder.d.ts +10 -10
  37. package/dist/core/MideaPacketBuilder.js +60 -60
  38. package/dist/core/MideaSecurity.d.ts +63 -63
  39. package/dist/core/MideaSecurity.js +251 -251
  40. package/dist/core/MideaUtils.d.ts +32 -32
  41. package/dist/core/MideaUtils.js +181 -181
  42. package/dist/devices/DeviceFactory.d.ts +13 -13
  43. package/dist/devices/DeviceFactory.d.ts.map +1 -1
  44. package/dist/devices/DeviceFactory.js +37 -36
  45. package/dist/devices/DeviceFactory.js.map +1 -1
  46. package/dist/devices/a1/MideaA1Device.d.ts +76 -76
  47. package/dist/devices/a1/MideaA1Device.js +145 -145
  48. package/dist/devices/a1/MideaA1Message.d.ts +40 -40
  49. package/dist/devices/a1/MideaA1Message.js +198 -198
  50. package/dist/devices/ac/MideaACDevice.d.ts +106 -104
  51. package/dist/devices/ac/MideaACDevice.d.ts.map +1 -1
  52. package/dist/devices/ac/MideaACDevice.js +400 -384
  53. package/dist/devices/ac/MideaACDevice.js.map +1 -1
  54. package/dist/devices/ac/MideaACMessage.d.ts +95 -94
  55. package/dist/devices/ac/MideaACMessage.d.ts.map +1 -1
  56. package/dist/devices/ac/MideaACMessage.js +619 -611
  57. package/dist/devices/ac/MideaACMessage.js.map +1 -1
  58. package/dist/devices/db/MideaDBDevice.d.ts +29 -29
  59. package/dist/devices/db/MideaDBDevice.js +100 -100
  60. package/dist/devices/db/MideaDBMessage.d.ts +32 -32
  61. package/dist/devices/db/MideaDBMessage.js +101 -101
  62. package/dist/devices/e1/MideaE1Device.d.ts +56 -56
  63. package/dist/devices/e1/MideaE1Device.js +128 -128
  64. package/dist/devices/e1/MideaE1Message.d.ts +28 -28
  65. package/dist/devices/e1/MideaE1Message.js +107 -107
  66. package/dist/devices/e2/MideaE2Device.d.ts +44 -44
  67. package/dist/devices/e2/MideaE2Device.js +129 -129
  68. package/dist/devices/e2/MideaE2Message.d.ts +33 -33
  69. package/dist/devices/e2/MideaE2Message.js +132 -132
  70. package/dist/devices/e3/MideaE3Device.d.ts +43 -43
  71. package/dist/devices/e3/MideaE3Device.js +137 -137
  72. package/dist/devices/e3/MideaE3Message.d.ts +51 -51
  73. package/dist/devices/e3/MideaE3Message.js +136 -136
  74. package/dist/devices/fa/MideaFADevice.d.ts +36 -36
  75. package/dist/devices/fa/MideaFADevice.js +106 -106
  76. package/dist/devices/fa/MideaFAMessage.d.ts +38 -38
  77. package/dist/devices/fa/MideaFAMessage.js +98 -98
  78. package/dist/index.d.ts +6 -6
  79. package/dist/index.js +6 -6
  80. package/dist/platform.d.ts +60 -60
  81. package/dist/platform.js +212 -212
  82. package/dist/platformUtils.d.ts +108 -106
  83. package/dist/platformUtils.d.ts.map +1 -1
  84. package/dist/platformUtils.js +103 -101
  85. package/dist/platformUtils.js.map +1 -1
  86. package/dist/settings.d.ts +8 -8
  87. package/dist/settings.js +11 -11
  88. package/docs/ac.md +6 -0
  89. package/package.json +1 -1
@@ -1,31 +1,31 @@
1
- /***********************************************************************
2
- * Midea Platform Dishwasher Accessory class
3
- *
4
- * Copyright (c) 2024 Kovalovszky Patrik, https://github.com/kovapatrik
5
- *
6
- * Based on https://github.com/homebridge/homebridge-plugin-template
7
- *
8
- * An instance of this class is created for each accessory the platform registers.
9
- *
10
- */
11
- import { CharacteristicValue } from 'homebridge';
12
- import { MideaAccessory, MideaPlatform } from '../platform';
13
- import BaseAccessory from './BaseAccessory';
14
- import { DeviceConfig } from '../platformUtils';
15
- import MideaE1Device, { E1Attributes } from '../devices/e1/MideaE1Device';
16
- export default class DishwasherAccessory extends BaseAccessory<MideaE1Device> {
17
- protected readonly device: MideaE1Device;
18
- protected readonly configDev: DeviceConfig;
19
- private service;
20
- /*********************************************************************
21
- * Constructor registers all the service types with Homebridge, registers
22
- * a callback function with the MideaDevice class, and requests device status.
23
- */
24
- constructor(platform: MideaPlatform, accessory: MideaAccessory, device: MideaE1Device, configDev: DeviceConfig);
25
- updateCharacteristics(attributes: Partial<E1Attributes>): Promise<void>;
26
- getActive(): CharacteristicValue;
27
- setActive(value: CharacteristicValue): Promise<void>;
28
- getInUse(): CharacteristicValue;
29
- getRemainingDuration(): CharacteristicValue;
30
- }
1
+ /***********************************************************************
2
+ * Midea Platform Dishwasher Accessory class
3
+ *
4
+ * Copyright (c) 2024 Kovalovszky Patrik, https://github.com/kovapatrik
5
+ *
6
+ * Based on https://github.com/homebridge/homebridge-plugin-template
7
+ *
8
+ * An instance of this class is created for each accessory the platform registers.
9
+ *
10
+ */
11
+ import { CharacteristicValue } from 'homebridge';
12
+ import { MideaAccessory, MideaPlatform } from '../platform';
13
+ import BaseAccessory from './BaseAccessory';
14
+ import { DeviceConfig } from '../platformUtils';
15
+ import MideaE1Device, { E1Attributes } from '../devices/e1/MideaE1Device';
16
+ export default class DishwasherAccessory extends BaseAccessory<MideaE1Device> {
17
+ protected readonly device: MideaE1Device;
18
+ protected readonly configDev: DeviceConfig;
19
+ private service;
20
+ /*********************************************************************
21
+ * Constructor registers all the service types with Homebridge, registers
22
+ * a callback function with the MideaDevice class, and requests device status.
23
+ */
24
+ constructor(platform: MideaPlatform, accessory: MideaAccessory, device: MideaE1Device, configDev: DeviceConfig);
25
+ updateCharacteristics(attributes: Partial<E1Attributes>): Promise<void>;
26
+ getActive(): CharacteristicValue;
27
+ setActive(value: CharacteristicValue): Promise<void>;
28
+ getInUse(): CharacteristicValue;
29
+ getRemainingDuration(): CharacteristicValue;
30
+ }
31
31
  //# sourceMappingURL=DishwasherAccessory.d.ts.map
@@ -1,64 +1,64 @@
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
- class DishwasherAccessory extends BaseAccessory_1.default {
8
- /*********************************************************************
9
- * Constructor registers all the service types with Homebridge, registers
10
- * a callback function with the MideaDevice class, and requests device status.
11
- */
12
- constructor(platform, accessory, device, configDev) {
13
- super(platform, accessory, device, configDev);
14
- this.device = device;
15
- this.configDev = configDev;
16
- this.service = this.accessory.getService(this.platform.Service.Valve) || this.accessory.addService(this.platform.Service.Valve);
17
- this.service.getCharacteristic(this.platform.Characteristic.Active).onGet(this.getActive.bind(this)).onSet(this.setActive.bind(this));
18
- this.service.getCharacteristic(this.platform.Characteristic.InUse).onGet(this.getInUse.bind(this));
19
- this.service
20
- .getCharacteristic(this.platform.Characteristic.ValveType)
21
- .onGet(() => this.platform.Characteristic.ValveType.GENERIC_VALVE);
22
- this.service
23
- .getCharacteristic(this.platform.Characteristic.RemainingDuration)
24
- .setProps({ minValue: 0, maxValue: 60 * 60 * 8, minStep: 1 })
25
- .onGet(this.getRemainingDuration.bind(this));
26
- }
27
- async updateCharacteristics(attributes) {
28
- let updateState = false;
29
- for (const [k, v] of Object.entries(attributes)) {
30
- this.platform.log.debug(`[${this.device.name}] Set attribute ${k} to: ${v}`);
31
- switch (k) {
32
- case 'power':
33
- updateState = true;
34
- break;
35
- case 'mode':
36
- updateState = true;
37
- break;
38
- default:
39
- this.platform.log.debug(`[${this.device.name}] Attempt to set unsupported attribute ${k} to ${v}`);
40
- break;
41
- }
42
- }
43
- if (updateState) {
44
- this.service.updateCharacteristic(this.platform.Characteristic.Active, this.getActive());
45
- this.service.updateCharacteristic(this.platform.Characteristic.InUse, this.getInUse());
46
- this.service.updateCharacteristic(this.platform.Characteristic.RemainingDuration, this.getRemainingDuration());
47
- }
48
- }
49
- getActive() {
50
- return this.device.attributes.POWER ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE;
51
- }
52
- async setActive(value) {
53
- await this.device.set_attribute({ POWER: value === this.platform.Characteristic.Active.ACTIVE });
54
- }
55
- getInUse() {
56
- return this.device.attributes.START ? this.platform.Characteristic.InUse.IN_USE : this.platform.Characteristic.InUse.NOT_IN_USE;
57
- }
58
- getRemainingDuration() {
59
- var _a;
60
- return ((_a = this.device.attributes.TIME_REMAINING) !== null && _a !== void 0 ? _a : 0) * 60; // in seconds
61
- }
62
- }
63
- exports.default = DishwasherAccessory;
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
+ class DishwasherAccessory extends BaseAccessory_1.default {
8
+ /*********************************************************************
9
+ * Constructor registers all the service types with Homebridge, registers
10
+ * a callback function with the MideaDevice class, and requests device status.
11
+ */
12
+ constructor(platform, accessory, device, configDev) {
13
+ super(platform, accessory, device, configDev);
14
+ this.device = device;
15
+ this.configDev = configDev;
16
+ this.service = this.accessory.getService(this.platform.Service.Valve) || this.accessory.addService(this.platform.Service.Valve);
17
+ this.service.getCharacteristic(this.platform.Characteristic.Active).onGet(this.getActive.bind(this)).onSet(this.setActive.bind(this));
18
+ this.service.getCharacteristic(this.platform.Characteristic.InUse).onGet(this.getInUse.bind(this));
19
+ this.service
20
+ .getCharacteristic(this.platform.Characteristic.ValveType)
21
+ .onGet(() => this.platform.Characteristic.ValveType.GENERIC_VALVE);
22
+ this.service
23
+ .getCharacteristic(this.platform.Characteristic.RemainingDuration)
24
+ .setProps({ minValue: 0, maxValue: 60 * 60 * 8, minStep: 1 })
25
+ .onGet(this.getRemainingDuration.bind(this));
26
+ }
27
+ async updateCharacteristics(attributes) {
28
+ let updateState = false;
29
+ for (const [k, v] of Object.entries(attributes)) {
30
+ this.platform.log.debug(`[${this.device.name}] Set attribute ${k} to: ${v}`);
31
+ switch (k) {
32
+ case 'power':
33
+ updateState = true;
34
+ break;
35
+ case 'mode':
36
+ updateState = true;
37
+ break;
38
+ default:
39
+ this.platform.log.debug(`[${this.device.name}] Attempt to set unsupported attribute ${k} to ${v}`);
40
+ break;
41
+ }
42
+ }
43
+ if (updateState) {
44
+ this.service.updateCharacteristic(this.platform.Characteristic.Active, this.getActive());
45
+ this.service.updateCharacteristic(this.platform.Characteristic.InUse, this.getInUse());
46
+ this.service.updateCharacteristic(this.platform.Characteristic.RemainingDuration, this.getRemainingDuration());
47
+ }
48
+ }
49
+ getActive() {
50
+ return this.device.attributes.POWER ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE;
51
+ }
52
+ async setActive(value) {
53
+ await this.device.set_attribute({ POWER: value === this.platform.Characteristic.Active.ACTIVE });
54
+ }
55
+ getInUse() {
56
+ return this.device.attributes.START ? this.platform.Characteristic.InUse.IN_USE : this.platform.Characteristic.InUse.NOT_IN_USE;
57
+ }
58
+ getRemainingDuration() {
59
+ var _a;
60
+ return ((_a = this.device.attributes.TIME_REMAINING) !== null && _a !== void 0 ? _a : 0) * 60; // in seconds
61
+ }
62
+ }
63
+ exports.default = DishwasherAccessory;
64
64
  //# sourceMappingURL=DishwasherAccessory.js.map
@@ -1,45 +1,45 @@
1
- /***********************************************************************
2
- * Midea Platform Electric Water Heater Accessory class
3
- *
4
- * Copyright (c) 2024 Kovalovszky Patrik, https://github.com/kovapatrik
5
- *
6
- * Based on https://github.com/homebridge/homebridge-plugin-template
7
- *
8
- * An instance of this class is created for each accessory the platform registers.
9
- *
10
- */
11
- import { CharacteristicValue } from 'homebridge';
12
- import MideaE2Device, { E2Attributes } from '../devices/e2/MideaE2Device';
13
- import BaseAccessory from './BaseAccessory';
14
- import { MideaAccessory, MideaPlatform } from '../platform';
15
- import { DeviceConfig } from '../platformUtils';
16
- export default class ElectricWaterHeaterAccessory extends BaseAccessory<MideaE2Device> {
17
- protected readonly device: MideaE2Device;
18
- protected readonly configDev: DeviceConfig;
19
- private service;
20
- private variableHeatingService?;
21
- private wholeTankHeatingService?;
22
- constructor(platform: MideaPlatform, accessory: MideaAccessory, device: MideaE2Device, configDev: DeviceConfig);
23
- /*********************************************************************
24
- * Callback function called by MideaDevice whenever there is a change to
25
- * any attribute value.
26
- */
27
- protected updateCharacteristics(attributes: Partial<E2Attributes>): Promise<void>;
28
- /*********************************************************************
29
- * Callback functions for each Homebridge/HomeKit service
30
- *
31
- */
32
- getActive(): CharacteristicValue;
33
- setActive(value: CharacteristicValue): Promise<void>;
34
- getCurrentHeaterCoolerState(): CharacteristicValue;
35
- getTargetHeaterCoolerState(): CharacteristicValue;
36
- setTargetHeaterCoolerState(value: CharacteristicValue): Promise<void>;
37
- getCurrentTemperature(): CharacteristicValue;
38
- getTargetTemperature(): CharacteristicValue;
39
- setTargetTemperature(value: CharacteristicValue): Promise<void>;
40
- getVariableHeating(): CharacteristicValue;
41
- setVariableHeating(value: CharacteristicValue): Promise<void>;
42
- getWholeTankHeating(): CharacteristicValue;
43
- setWholeTankHeating(value: CharacteristicValue): Promise<void>;
44
- }
1
+ /***********************************************************************
2
+ * Midea Platform Electric Water Heater Accessory class
3
+ *
4
+ * Copyright (c) 2024 Kovalovszky Patrik, https://github.com/kovapatrik
5
+ *
6
+ * Based on https://github.com/homebridge/homebridge-plugin-template
7
+ *
8
+ * An instance of this class is created for each accessory the platform registers.
9
+ *
10
+ */
11
+ import { CharacteristicValue } from 'homebridge';
12
+ import MideaE2Device, { E2Attributes } from '../devices/e2/MideaE2Device';
13
+ import BaseAccessory from './BaseAccessory';
14
+ import { MideaAccessory, MideaPlatform } from '../platform';
15
+ import { DeviceConfig } from '../platformUtils';
16
+ export default class ElectricWaterHeaterAccessory extends BaseAccessory<MideaE2Device> {
17
+ protected readonly device: MideaE2Device;
18
+ protected readonly configDev: DeviceConfig;
19
+ private service;
20
+ private variableHeatingService?;
21
+ private wholeTankHeatingService?;
22
+ constructor(platform: MideaPlatform, accessory: MideaAccessory, device: MideaE2Device, configDev: DeviceConfig);
23
+ /*********************************************************************
24
+ * Callback function called by MideaDevice whenever there is a change to
25
+ * any attribute value.
26
+ */
27
+ protected updateCharacteristics(attributes: Partial<E2Attributes>): Promise<void>;
28
+ /*********************************************************************
29
+ * Callback functions for each Homebridge/HomeKit service
30
+ *
31
+ */
32
+ getActive(): CharacteristicValue;
33
+ setActive(value: CharacteristicValue): Promise<void>;
34
+ getCurrentHeaterCoolerState(): CharacteristicValue;
35
+ getTargetHeaterCoolerState(): CharacteristicValue;
36
+ setTargetHeaterCoolerState(value: CharacteristicValue): Promise<void>;
37
+ getCurrentTemperature(): CharacteristicValue;
38
+ getTargetTemperature(): CharacteristicValue;
39
+ setTargetTemperature(value: CharacteristicValue): Promise<void>;
40
+ getVariableHeating(): CharacteristicValue;
41
+ setVariableHeating(value: CharacteristicValue): Promise<void>;
42
+ getWholeTankHeating(): CharacteristicValue;
43
+ setWholeTankHeating(value: CharacteristicValue): Promise<void>;
44
+ }
45
45
  //# sourceMappingURL=ElectricWaterHeaterAccessory.d.ts.map
@@ -1,177 +1,177 @@
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
- class ElectricWaterHeaterAccessory extends BaseAccessory_1.default {
8
- constructor(platform, accessory, device, configDev) {
9
- var _a, _b;
10
- super(platform, accessory, device, configDev);
11
- this.device = device;
12
- this.configDev = configDev;
13
- this.service =
14
- this.accessory.getService(this.platform.Service.HeaterCooler) || this.accessory.addService(this.platform.Service.HeaterCooler);
15
- this.service.setCharacteristic(this.platform.Characteristic.Name, this.device.name);
16
- this.service.getCharacteristic(this.platform.Characteristic.Active).onGet(this.getActive.bind(this)).onSet(this.setActive.bind(this));
17
- this.service
18
- .getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState)
19
- .onGet(this.getCurrentHeaterCoolerState.bind(this));
20
- this.service
21
- .getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
22
- .onGet(this.getTargetHeaterCoolerState.bind(this))
23
- .onSet(this.setTargetHeaterCoolerState.bind(this))
24
- .setProps({
25
- validValues: [
26
- this.platform.Characteristic.TargetHeatingCoolingState.OFF,
27
- this.platform.Characteristic.TargetHeaterCoolerState.HEAT,
28
- ],
29
- });
30
- this.service.getCharacteristic(this.platform.Characteristic.CurrentTemperature).onGet(this.getCurrentTemperature.bind(this));
31
- this.service
32
- .getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
33
- .onGet(this.getTargetTemperature.bind(this))
34
- .onSet(this.setTargetTemperature.bind(this))
35
- .setProps({
36
- minValue: this.configDev.E2_options.minTemp,
37
- maxValue: this.configDev.E2_options.maxTemp,
38
- minStep: this.configDev.E2_options.tempStep,
39
- });
40
- this.variableHeatingService = this.accessory.getServiceById(this.platform.Service.Switch, 'VariableHeating');
41
- if (this.configDev.E2_options.variableHeatingSwitch) {
42
- (_a = this.variableHeatingService) !== null && _a !== void 0 ? _a : (this.variableHeatingService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Variable Heating`, 'VariableHeating'));
43
- this.variableHeatingService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Variable Heating`);
44
- this.variableHeatingService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Variable Heating`);
45
- this.variableHeatingService
46
- .getCharacteristic(this.platform.Characteristic.On)
47
- .onGet(this.getVariableHeating.bind(this))
48
- .onSet(this.setVariableHeating.bind(this));
49
- }
50
- else if (this.variableHeatingService) {
51
- this.accessory.removeService(this.variableHeatingService);
52
- }
53
- this.wholeTankHeatingService = this.accessory.getServiceById(this.platform.Service.Switch, 'WholeTankHeating');
54
- if (this.configDev.E2_options.wholeTankHeatingSwitch) {
55
- (_b = this.wholeTankHeatingService) !== null && _b !== void 0 ? _b : (this.wholeTankHeatingService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Whole Tank Heating`, 'WholeTankHeating'));
56
- this.wholeTankHeatingService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Whole Tank Heating`);
57
- this.wholeTankHeatingService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Whole Tank Heating`);
58
- this.wholeTankHeatingService
59
- .getCharacteristic(this.platform.Characteristic.On)
60
- .onGet(this.getWholeTankHeating.bind(this))
61
- .onSet(this.setWholeTankHeating.bind(this));
62
- }
63
- else if (this.wholeTankHeatingService) {
64
- this.accessory.removeService(this.wholeTankHeatingService);
65
- }
66
- }
67
- /*********************************************************************
68
- * Callback function called by MideaDevice whenever there is a change to
69
- * any attribute value.
70
- */
71
- async updateCharacteristics(attributes) {
72
- var _a, _b;
73
- for (const [k, v] of Object.entries(attributes)) {
74
- this.platform.log.debug(`[${this.device.name}] Set attribute ${k} to: ${v}`);
75
- let updateState = false;
76
- switch (k.toLowerCase()) {
77
- case 'power':
78
- this.service.updateCharacteristic(this.platform.Characteristic.Active, v ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE);
79
- updateState = true;
80
- break;
81
- case 'heating':
82
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, v ? this.platform.Characteristic.CurrentHeaterCoolerState.HEATING : this.platform.Characteristic.CurrentHeaterCoolerState.IDLE);
83
- updateState = true;
84
- break;
85
- // case 'keep_warm':
86
- // this.platform.log.debug(`[${this.device.name}] Keep warm: ${v}`);
87
- // break;
88
- // case 'protection':
89
- // this.platform.log.debug(`[${this.device.name}] Protection: ${v}`);
90
- // break;
91
- case 'current_temperature':
92
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, v);
93
- updateState = true;
94
- break;
95
- case 'target_temperature':
96
- this.service.updateCharacteristic(this.platform.Characteristic.TargetTemperature, v);
97
- updateState = true;
98
- break;
99
- case 'whole_tank_heating':
100
- (_a = this.wholeTankHeatingService) === null || _a === void 0 ? void 0 : _a.updateCharacteristic(this.platform.Characteristic.On, v);
101
- break;
102
- case 'variable_heating':
103
- (_b = this.variableHeatingService) === null || _b === void 0 ? void 0 : _b.updateCharacteristic(this.platform.Characteristic.On, v);
104
- break;
105
- // case 'heating_time_remaining':
106
- // this.platform.log.debug(`[${this.device.name}] Heating time remaining: ${v}`);
107
- // break;
108
- // case 'water_consumption':
109
- // this.platform.log.debug(`[${this.device.name}] Water consumption: ${v}`);
110
- // break;
111
- // case 'heating_power':
112
- // this.platform.log.debug(`[${this.device.name}] Heating power: ${v}`);
113
- // break;
114
- default:
115
- this.platform.log.debug(`[${this.device.name}] Attempt to set unsupported attribute ${k} to ${v}`);
116
- }
117
- if (updateState) {
118
- this.service.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.getTargetHeaterCoolerState());
119
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.getCurrentHeaterCoolerState());
120
- }
121
- }
122
- }
123
- /*********************************************************************
124
- * Callback functions for each Homebridge/HomeKit service
125
- *
126
- */
127
- getActive() {
128
- return this.device.attributes.POWER ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE;
129
- }
130
- async setActive(value) {
131
- await this.device.set_attribute({ POWER: !!value });
132
- }
133
- getCurrentHeaterCoolerState() {
134
- if (this.device.attributes.POWER) {
135
- return this.device.attributes.HEATING
136
- ? this.platform.Characteristic.CurrentHeaterCoolerState.HEATING
137
- : this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
138
- }
139
- return this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
140
- }
141
- getTargetHeaterCoolerState() {
142
- return this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
143
- }
144
- async setTargetHeaterCoolerState(value) {
145
- if (value === this.platform.Characteristic.TargetHeaterCoolerState.HEAT) {
146
- await this.device.set_attribute({ POWER: true });
147
- }
148
- else {
149
- await this.device.set_attribute({ POWER: false });
150
- }
151
- }
152
- getCurrentTemperature() {
153
- var _a;
154
- return (_a = this.device.attributes.CURRENT_TEMPERATURE) !== null && _a !== void 0 ? _a : this.configDev.E2_options.minTemp;
155
- }
156
- getTargetTemperature() {
157
- return Math.max(this.configDev.E2_options.minTemp, Math.min(this.configDev.E2_options.maxTemp, this.device.attributes.TARGET_TEMPERATURE));
158
- }
159
- async setTargetTemperature(value) {
160
- value = Math.max(this.configDev.E2_options.minTemp, Math.min(this.configDev.E2_options.maxTemp, value));
161
- await this.device.set_attribute({ TARGET_TEMPERATURE: value });
162
- }
163
- getVariableHeating() {
164
- return this.device.attributes.VARIABLE_HEATING;
165
- }
166
- async setVariableHeating(value) {
167
- await this.device.set_attribute({ VARIABLE_HEATING: !!value });
168
- }
169
- getWholeTankHeating() {
170
- return this.device.attributes.WHOLE_TANK_HEATING;
171
- }
172
- async setWholeTankHeating(value) {
173
- await this.device.set_attribute({ WHOLE_TANK_HEATING: !!value });
174
- }
175
- }
176
- exports.default = ElectricWaterHeaterAccessory;
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
+ class ElectricWaterHeaterAccessory extends BaseAccessory_1.default {
8
+ constructor(platform, accessory, device, configDev) {
9
+ var _a, _b;
10
+ super(platform, accessory, device, configDev);
11
+ this.device = device;
12
+ this.configDev = configDev;
13
+ this.service =
14
+ this.accessory.getService(this.platform.Service.HeaterCooler) || this.accessory.addService(this.platform.Service.HeaterCooler);
15
+ this.service.setCharacteristic(this.platform.Characteristic.Name, this.device.name);
16
+ this.service.getCharacteristic(this.platform.Characteristic.Active).onGet(this.getActive.bind(this)).onSet(this.setActive.bind(this));
17
+ this.service
18
+ .getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState)
19
+ .onGet(this.getCurrentHeaterCoolerState.bind(this));
20
+ this.service
21
+ .getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
22
+ .onGet(this.getTargetHeaterCoolerState.bind(this))
23
+ .onSet(this.setTargetHeaterCoolerState.bind(this))
24
+ .setProps({
25
+ validValues: [
26
+ this.platform.Characteristic.TargetHeatingCoolingState.OFF,
27
+ this.platform.Characteristic.TargetHeaterCoolerState.HEAT,
28
+ ],
29
+ });
30
+ this.service.getCharacteristic(this.platform.Characteristic.CurrentTemperature).onGet(this.getCurrentTemperature.bind(this));
31
+ this.service
32
+ .getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
33
+ .onGet(this.getTargetTemperature.bind(this))
34
+ .onSet(this.setTargetTemperature.bind(this))
35
+ .setProps({
36
+ minValue: this.configDev.E2_options.minTemp,
37
+ maxValue: this.configDev.E2_options.maxTemp,
38
+ minStep: this.configDev.E2_options.tempStep,
39
+ });
40
+ this.variableHeatingService = this.accessory.getServiceById(this.platform.Service.Switch, 'VariableHeating');
41
+ if (this.configDev.E2_options.variableHeatingSwitch) {
42
+ (_a = this.variableHeatingService) !== null && _a !== void 0 ? _a : (this.variableHeatingService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Variable Heating`, 'VariableHeating'));
43
+ this.variableHeatingService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Variable Heating`);
44
+ this.variableHeatingService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Variable Heating`);
45
+ this.variableHeatingService
46
+ .getCharacteristic(this.platform.Characteristic.On)
47
+ .onGet(this.getVariableHeating.bind(this))
48
+ .onSet(this.setVariableHeating.bind(this));
49
+ }
50
+ else if (this.variableHeatingService) {
51
+ this.accessory.removeService(this.variableHeatingService);
52
+ }
53
+ this.wholeTankHeatingService = this.accessory.getServiceById(this.platform.Service.Switch, 'WholeTankHeating');
54
+ if (this.configDev.E2_options.wholeTankHeatingSwitch) {
55
+ (_b = this.wholeTankHeatingService) !== null && _b !== void 0 ? _b : (this.wholeTankHeatingService = this.accessory.addService(this.platform.Service.Switch, `${this.device.name} Whole Tank Heating`, 'WholeTankHeating'));
56
+ this.wholeTankHeatingService.setCharacteristic(this.platform.Characteristic.Name, `${this.device.name} Whole Tank Heating`);
57
+ this.wholeTankHeatingService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${this.device.name} Whole Tank Heating`);
58
+ this.wholeTankHeatingService
59
+ .getCharacteristic(this.platform.Characteristic.On)
60
+ .onGet(this.getWholeTankHeating.bind(this))
61
+ .onSet(this.setWholeTankHeating.bind(this));
62
+ }
63
+ else if (this.wholeTankHeatingService) {
64
+ this.accessory.removeService(this.wholeTankHeatingService);
65
+ }
66
+ }
67
+ /*********************************************************************
68
+ * Callback function called by MideaDevice whenever there is a change to
69
+ * any attribute value.
70
+ */
71
+ async updateCharacteristics(attributes) {
72
+ var _a, _b;
73
+ for (const [k, v] of Object.entries(attributes)) {
74
+ this.platform.log.debug(`[${this.device.name}] Set attribute ${k} to: ${v}`);
75
+ let updateState = false;
76
+ switch (k.toLowerCase()) {
77
+ case 'power':
78
+ this.service.updateCharacteristic(this.platform.Characteristic.Active, v ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE);
79
+ updateState = true;
80
+ break;
81
+ case 'heating':
82
+ this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, v ? this.platform.Characteristic.CurrentHeaterCoolerState.HEATING : this.platform.Characteristic.CurrentHeaterCoolerState.IDLE);
83
+ updateState = true;
84
+ break;
85
+ // case 'keep_warm':
86
+ // this.platform.log.debug(`[${this.device.name}] Keep warm: ${v}`);
87
+ // break;
88
+ // case 'protection':
89
+ // this.platform.log.debug(`[${this.device.name}] Protection: ${v}`);
90
+ // break;
91
+ case 'current_temperature':
92
+ this.service.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, v);
93
+ updateState = true;
94
+ break;
95
+ case 'target_temperature':
96
+ this.service.updateCharacteristic(this.platform.Characteristic.TargetTemperature, v);
97
+ updateState = true;
98
+ break;
99
+ case 'whole_tank_heating':
100
+ (_a = this.wholeTankHeatingService) === null || _a === void 0 ? void 0 : _a.updateCharacteristic(this.platform.Characteristic.On, v);
101
+ break;
102
+ case 'variable_heating':
103
+ (_b = this.variableHeatingService) === null || _b === void 0 ? void 0 : _b.updateCharacteristic(this.platform.Characteristic.On, v);
104
+ break;
105
+ // case 'heating_time_remaining':
106
+ // this.platform.log.debug(`[${this.device.name}] Heating time remaining: ${v}`);
107
+ // break;
108
+ // case 'water_consumption':
109
+ // this.platform.log.debug(`[${this.device.name}] Water consumption: ${v}`);
110
+ // break;
111
+ // case 'heating_power':
112
+ // this.platform.log.debug(`[${this.device.name}] Heating power: ${v}`);
113
+ // break;
114
+ default:
115
+ this.platform.log.debug(`[${this.device.name}] Attempt to set unsupported attribute ${k} to ${v}`);
116
+ }
117
+ if (updateState) {
118
+ this.service.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.getTargetHeaterCoolerState());
119
+ this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.getCurrentHeaterCoolerState());
120
+ }
121
+ }
122
+ }
123
+ /*********************************************************************
124
+ * Callback functions for each Homebridge/HomeKit service
125
+ *
126
+ */
127
+ getActive() {
128
+ return this.device.attributes.POWER ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE;
129
+ }
130
+ async setActive(value) {
131
+ await this.device.set_attribute({ POWER: !!value });
132
+ }
133
+ getCurrentHeaterCoolerState() {
134
+ if (this.device.attributes.POWER) {
135
+ return this.device.attributes.HEATING
136
+ ? this.platform.Characteristic.CurrentHeaterCoolerState.HEATING
137
+ : this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
138
+ }
139
+ return this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
140
+ }
141
+ getTargetHeaterCoolerState() {
142
+ return this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
143
+ }
144
+ async setTargetHeaterCoolerState(value) {
145
+ if (value === this.platform.Characteristic.TargetHeaterCoolerState.HEAT) {
146
+ await this.device.set_attribute({ POWER: true });
147
+ }
148
+ else {
149
+ await this.device.set_attribute({ POWER: false });
150
+ }
151
+ }
152
+ getCurrentTemperature() {
153
+ var _a;
154
+ return (_a = this.device.attributes.CURRENT_TEMPERATURE) !== null && _a !== void 0 ? _a : this.configDev.E2_options.minTemp;
155
+ }
156
+ getTargetTemperature() {
157
+ return Math.max(this.configDev.E2_options.minTemp, Math.min(this.configDev.E2_options.maxTemp, this.device.attributes.TARGET_TEMPERATURE));
158
+ }
159
+ async setTargetTemperature(value) {
160
+ value = Math.max(this.configDev.E2_options.minTemp, Math.min(this.configDev.E2_options.maxTemp, value));
161
+ await this.device.set_attribute({ TARGET_TEMPERATURE: value });
162
+ }
163
+ getVariableHeating() {
164
+ return this.device.attributes.VARIABLE_HEATING;
165
+ }
166
+ async setVariableHeating(value) {
167
+ await this.device.set_attribute({ VARIABLE_HEATING: !!value });
168
+ }
169
+ getWholeTankHeating() {
170
+ return this.device.attributes.WHOLE_TANK_HEATING;
171
+ }
172
+ async setWholeTankHeating(value) {
173
+ await this.device.set_attribute({ WHOLE_TANK_HEATING: !!value });
174
+ }
175
+ }
176
+ exports.default = ElectricWaterHeaterAccessory;
177
177
  //# sourceMappingURL=ElectricWaterHeaterAccessory.js.map