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,102 +1,102 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MessageDBResponse = exports.DBGeneralMessageBody = exports.MessageStart = exports.MessagePower = exports.MessageQuery = void 0;
4
- const MideaConstants_1 = require("../../core/MideaConstants");
5
- const MideaMessage_1 = require("../../core/MideaMessage");
6
- class MessageDBBase extends MideaMessage_1.MessageRequest {
7
- constructor(device_protocol_version, message_type, body_type) {
8
- super(MideaConstants_1.DeviceType.FRONT_LOAD_WASHER, message_type, body_type, device_protocol_version);
9
- }
10
- }
11
- class MessageQuery extends MessageDBBase {
12
- constructor(device_protocol_version) {
13
- super(device_protocol_version, MideaMessage_1.MessageType.QUERY, 0x03);
14
- }
15
- get _body() {
16
- return Buffer.alloc(0);
17
- }
18
- }
19
- exports.MessageQuery = MessageQuery;
20
- class MessagePower extends MessageDBBase {
21
- constructor(device_protocol_version) {
22
- super(device_protocol_version, MideaMessage_1.MessageType.SET, 0x02);
23
- this.power = false;
24
- }
25
- get _body() {
26
- const power = this.power ? 0x01 : 0x00;
27
- return Buffer.from([
28
- power,
29
- 0xff,
30
- 0xff,
31
- 0xff,
32
- 0xff,
33
- 0xff,
34
- 0xff,
35
- 0xff,
36
- 0xff,
37
- 0xff,
38
- 0xff,
39
- 0xff,
40
- 0xff,
41
- 0xff,
42
- 0xff,
43
- 0xff,
44
- 0xff,
45
- 0xff,
46
- 0xff,
47
- 0xff,
48
- 0xff,
49
- ]);
50
- }
51
- }
52
- exports.MessagePower = MessagePower;
53
- class MessageStart extends MessageDBBase {
54
- constructor(device_protocol_version) {
55
- super(device_protocol_version, MideaMessage_1.MessageType.SET, 0x02);
56
- this.start = false;
57
- this.washing_data = Buffer.alloc(0);
58
- }
59
- get _body() {
60
- if (this.start) {
61
- return Buffer.concat([Buffer.from([0xff, 0x01]), this.washing_data]);
62
- }
63
- else {
64
- return Buffer.from([0xff, 0x00]);
65
- }
66
- }
67
- }
68
- exports.MessageStart = MessageStart;
69
- class DBGeneralMessageBody extends MideaMessage_1.MessageBody {
70
- constructor(body) {
71
- super(body);
72
- this.power = body[1] > 0;
73
- this.start = [0x2, 0x6].includes(body[2]);
74
- this.washing_data = body.subarray(3, 16);
75
- this.progress = 0;
76
- this.time_remaining = 0;
77
- for (let i = 0; i < 7; i++) {
78
- if ((body[16] & (1 << i)) > 0) {
79
- this.progress = i + 1;
80
- break;
81
- }
82
- }
83
- if (this.power) {
84
- this.time_remaining = body[17] + (body[18] << 8);
85
- }
86
- else {
87
- this.time_remaining = undefined;
88
- }
89
- }
90
- }
91
- exports.DBGeneralMessageBody = DBGeneralMessageBody;
92
- class MessageDBResponse extends MideaMessage_1.MessageResponse {
93
- constructor(message) {
94
- super(message);
95
- if ([MideaMessage_1.MessageType.QUERY, MideaMessage_1.MessageType.SET].includes(this.message_type) ||
96
- (this.message_type === MideaMessage_1.MessageType.NOTIFY1 && this.body_type === 0x04)) {
97
- this.set_body(new DBGeneralMessageBody(this.body));
98
- }
99
- }
100
- }
101
- exports.MessageDBResponse = MessageDBResponse;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageDBResponse = exports.DBGeneralMessageBody = exports.MessageStart = exports.MessagePower = exports.MessageQuery = void 0;
4
+ const MideaConstants_1 = require("../../core/MideaConstants");
5
+ const MideaMessage_1 = require("../../core/MideaMessage");
6
+ class MessageDBBase extends MideaMessage_1.MessageRequest {
7
+ constructor(device_protocol_version, message_type, body_type) {
8
+ super(MideaConstants_1.DeviceType.FRONT_LOAD_WASHER, message_type, body_type, device_protocol_version);
9
+ }
10
+ }
11
+ class MessageQuery extends MessageDBBase {
12
+ constructor(device_protocol_version) {
13
+ super(device_protocol_version, MideaMessage_1.MessageType.QUERY, 0x03);
14
+ }
15
+ get _body() {
16
+ return Buffer.alloc(0);
17
+ }
18
+ }
19
+ exports.MessageQuery = MessageQuery;
20
+ class MessagePower extends MessageDBBase {
21
+ constructor(device_protocol_version) {
22
+ super(device_protocol_version, MideaMessage_1.MessageType.SET, 0x02);
23
+ this.power = false;
24
+ }
25
+ get _body() {
26
+ const power = this.power ? 0x01 : 0x00;
27
+ return Buffer.from([
28
+ power,
29
+ 0xff,
30
+ 0xff,
31
+ 0xff,
32
+ 0xff,
33
+ 0xff,
34
+ 0xff,
35
+ 0xff,
36
+ 0xff,
37
+ 0xff,
38
+ 0xff,
39
+ 0xff,
40
+ 0xff,
41
+ 0xff,
42
+ 0xff,
43
+ 0xff,
44
+ 0xff,
45
+ 0xff,
46
+ 0xff,
47
+ 0xff,
48
+ 0xff,
49
+ ]);
50
+ }
51
+ }
52
+ exports.MessagePower = MessagePower;
53
+ class MessageStart extends MessageDBBase {
54
+ constructor(device_protocol_version) {
55
+ super(device_protocol_version, MideaMessage_1.MessageType.SET, 0x02);
56
+ this.start = false;
57
+ this.washing_data = Buffer.alloc(0);
58
+ }
59
+ get _body() {
60
+ if (this.start) {
61
+ return Buffer.concat([Buffer.from([0xff, 0x01]), this.washing_data]);
62
+ }
63
+ else {
64
+ return Buffer.from([0xff, 0x00]);
65
+ }
66
+ }
67
+ }
68
+ exports.MessageStart = MessageStart;
69
+ class DBGeneralMessageBody extends MideaMessage_1.MessageBody {
70
+ constructor(body) {
71
+ super(body);
72
+ this.power = body[1] > 0;
73
+ this.start = [0x2, 0x6].includes(body[2]);
74
+ this.washing_data = body.subarray(3, 16);
75
+ this.progress = 0;
76
+ this.time_remaining = 0;
77
+ for (let i = 0; i < 7; i++) {
78
+ if ((body[16] & (1 << i)) > 0) {
79
+ this.progress = i + 1;
80
+ break;
81
+ }
82
+ }
83
+ if (this.power) {
84
+ this.time_remaining = body[17] + (body[18] << 8);
85
+ }
86
+ else {
87
+ this.time_remaining = undefined;
88
+ }
89
+ }
90
+ }
91
+ exports.DBGeneralMessageBody = DBGeneralMessageBody;
92
+ class MessageDBResponse extends MideaMessage_1.MessageResponse {
93
+ constructor(message) {
94
+ super(message);
95
+ if ([MideaMessage_1.MessageType.QUERY, MideaMessage_1.MessageType.SET].includes(this.message_type) ||
96
+ (this.message_type === MideaMessage_1.MessageType.NOTIFY1 && this.body_type === 0x04)) {
97
+ this.set_body(new DBGeneralMessageBody(this.body));
98
+ }
99
+ }
100
+ }
101
+ exports.MessageDBResponse = MessageDBResponse;
102
102
  //# sourceMappingURL=MideaDBMessage.js.map
@@ -1,57 +1,57 @@
1
- /***********************************************************************
2
- * Midea Dishwasher Device class
3
- *
4
- * Copyright (c) 2024 Kovalovszky Patrik, https://github.com/kovapatrik
5
- *
6
- * With thanks to https://github.com/georgezhao2010/midea_ac_lan
7
- *
8
- */
9
- /// <reference types="node" />
10
- import { Logger } from 'homebridge';
11
- import MideaDevice, { DeviceAttributeBase } from '../../core/MideaDevice';
12
- import { DeviceInfo } from '../../core/MideaConstants';
13
- import { Config, DeviceConfig } from '../../platformUtils';
14
- import { MessageQuery } from './MideaE1Message';
15
- export interface E1Attributes extends DeviceAttributeBase {
16
- POWER: boolean;
17
- STATUS?: number;
18
- MODE: number;
19
- ADDITIONAL: number;
20
- DOOR: boolean;
21
- RINSE_AID: boolean;
22
- SALT: boolean;
23
- START_PAUSE: boolean;
24
- START: boolean;
25
- CHILD_LOCK: boolean;
26
- UV: boolean;
27
- DRY: boolean;
28
- DRY_STATUS: boolean;
29
- STORAGE: boolean;
30
- STORAGE_STATUS: boolean;
31
- TIME_REMAINING?: number;
32
- PROGRESS?: number;
33
- STORAGE_REMAINING?: number;
34
- TEMPERATURE?: number;
35
- HUMIDITY?: number;
36
- WATERSWITCH: boolean;
37
- WATER_LACK: boolean;
38
- ERROR_CODE?: number;
39
- SOFTWATER: number;
40
- WRONG_OPERATION?: number;
41
- BRIGHT?: number;
42
- }
43
- export default class MideaE1Device extends MideaDevice {
44
- attributes: E1Attributes;
45
- /*********************************************************************
46
- * Constructor initializes all the attributes. We set some to invalid
47
- * values so that they are detected as "changed" on the first status
48
- * refresh... and passed back to the Homebridge/HomeKit accessory callback
49
- * function to set their initial values.
50
- */
51
- constructor(logger: Logger, device_info: DeviceInfo, config: Config, deviceConfig: DeviceConfig);
52
- build_query(): MessageQuery[];
53
- process_message(msg: Buffer): void;
54
- set_attribute(attributes: Partial<E1Attributes>): Promise<void>;
55
- protected set_subtype(): void;
56
- }
1
+ /***********************************************************************
2
+ * Midea Dishwasher Device class
3
+ *
4
+ * Copyright (c) 2024 Kovalovszky Patrik, https://github.com/kovapatrik
5
+ *
6
+ * With thanks to https://github.com/georgezhao2010/midea_ac_lan
7
+ *
8
+ */
9
+ /// <reference types="node" />
10
+ import { Logger } from 'homebridge';
11
+ import MideaDevice, { DeviceAttributeBase } from '../../core/MideaDevice';
12
+ import { DeviceInfo } from '../../core/MideaConstants';
13
+ import { Config, DeviceConfig } from '../../platformUtils';
14
+ import { MessageQuery } from './MideaE1Message';
15
+ export interface E1Attributes extends DeviceAttributeBase {
16
+ POWER: boolean;
17
+ STATUS?: number;
18
+ MODE: number;
19
+ ADDITIONAL: number;
20
+ DOOR: boolean;
21
+ RINSE_AID: boolean;
22
+ SALT: boolean;
23
+ START_PAUSE: boolean;
24
+ START: boolean;
25
+ CHILD_LOCK: boolean;
26
+ UV: boolean;
27
+ DRY: boolean;
28
+ DRY_STATUS: boolean;
29
+ STORAGE: boolean;
30
+ STORAGE_STATUS: boolean;
31
+ TIME_REMAINING?: number;
32
+ PROGRESS?: number;
33
+ STORAGE_REMAINING?: number;
34
+ TEMPERATURE?: number;
35
+ HUMIDITY?: number;
36
+ WATERSWITCH: boolean;
37
+ WATER_LACK: boolean;
38
+ ERROR_CODE?: number;
39
+ SOFTWATER: number;
40
+ WRONG_OPERATION?: number;
41
+ BRIGHT?: number;
42
+ }
43
+ export default class MideaE1Device extends MideaDevice {
44
+ attributes: E1Attributes;
45
+ /*********************************************************************
46
+ * Constructor initializes all the attributes. We set some to invalid
47
+ * values so that they are detected as "changed" on the first status
48
+ * refresh... and passed back to the Homebridge/HomeKit accessory callback
49
+ * function to set their initial values.
50
+ */
51
+ constructor(logger: Logger, device_info: DeviceInfo, config: Config, deviceConfig: DeviceConfig);
52
+ build_query(): MessageQuery[];
53
+ process_message(msg: Buffer): void;
54
+ set_attribute(attributes: Partial<E1Attributes>): Promise<void>;
55
+ protected set_subtype(): void;
56
+ }
57
57
  //# sourceMappingURL=MideaE1Device.d.ts.map
@@ -1,129 +1,129 @@
1
- "use strict";
2
- /***********************************************************************
3
- * Midea Dishwasher Device class
4
- *
5
- * Copyright (c) 2024 Kovalovszky Patrik, https://github.com/kovapatrik
6
- *
7
- * With thanks to https://github.com/georgezhao2010/midea_ac_lan
8
- *
9
- */
10
- var __importDefault = (this && this.__importDefault) || function (mod) {
11
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- const MideaDevice_1 = __importDefault(require("../../core/MideaDevice"));
15
- const MideaE1Message_1 = require("./MideaE1Message");
16
- class MideaE1Device extends MideaDevice_1.default {
17
- /*********************************************************************
18
- * Constructor initializes all the attributes. We set some to invalid
19
- * values so that they are detected as "changed" on the first status
20
- * refresh... and passed back to the Homebridge/HomeKit accessory callback
21
- * function to set their initial values.
22
- */
23
- constructor(logger, device_info, config, deviceConfig) {
24
- super(logger, device_info, config, deviceConfig);
25
- this.attributes = {
26
- POWER: false,
27
- STATUS: undefined,
28
- MODE: 0,
29
- ADDITIONAL: 0,
30
- DOOR: false,
31
- RINSE_AID: false,
32
- SALT: false,
33
- START_PAUSE: false,
34
- START: false,
35
- CHILD_LOCK: false,
36
- UV: false,
37
- DRY: false,
38
- DRY_STATUS: false,
39
- STORAGE: false,
40
- STORAGE_STATUS: false,
41
- TIME_REMAINING: undefined,
42
- PROGRESS: undefined,
43
- STORAGE_REMAINING: undefined,
44
- TEMPERATURE: undefined,
45
- HUMIDITY: undefined,
46
- WATERSWITCH: false,
47
- WATER_LACK: false,
48
- ERROR_CODE: undefined,
49
- SOFTWATER: 0,
50
- WRONG_OPERATION: undefined,
51
- BRIGHT: undefined,
52
- };
53
- }
54
- build_query() {
55
- return [new MideaE1Message_1.MessageQuery(this.device_protocol_version)];
56
- }
57
- process_message(msg) {
58
- const message = new MideaE1Message_1.MessageE1Response(msg);
59
- if (this.verbose) {
60
- this.logger.debug(`[${this.name}] Body:\n${JSON.stringify(message.body)}`);
61
- }
62
- const changed = {};
63
- for (const status of Object.keys(this.attributes)) {
64
- const value = message.get_body_attribute(status.toLowerCase());
65
- if (value !== undefined) {
66
- if (this.attributes[status] !== value) {
67
- // Track only those attributes that change value. So when we send to the Homebridge /
68
- // HomeKit accessory we only update values that change. First time through this
69
- // should be most/all attributes having initialized them to invalid values.
70
- this.logger.debug(`[${this.name}] Value for ${status} changed from '${this.attributes[status]}' to '${value}'`);
71
- changed[status] = value;
72
- }
73
- this.attributes[status] = value;
74
- }
75
- }
76
- // Now we update Homebridge / Homekit accessory
77
- if (Object.keys(changed).length > 0) {
78
- this.update(changed);
79
- }
80
- else {
81
- this.logger.debug(`[${this.name}] Status unchanged`);
82
- }
83
- }
84
- async set_attribute(attributes) {
85
- var _a, _b, _c;
86
- const messageToSend = {
87
- POWER: undefined,
88
- CHILD_LOCK: undefined,
89
- STORAGE: undefined,
90
- };
91
- try {
92
- for (const [k, v] of Object.entries(attributes)) {
93
- if (v === this.attributes[k]) {
94
- this.logger.info(`[${this.name}] Attribute ${k} already set to ${v}`);
95
- continue;
96
- }
97
- this.logger.info(`[${this.name}] Set device attribute ${k} to: ${v}`);
98
- this.attributes[k] = v;
99
- if (k === 'POWER') {
100
- (_a = messageToSend.POWER) !== null && _a !== void 0 ? _a : (messageToSend.POWER = new MideaE1Message_1.MessagePower(this.device_protocol_version));
101
- messageToSend.POWER.power = v;
102
- }
103
- else if (k === 'CHILD_LOCK') {
104
- (_b = messageToSend.CHILD_LOCK) !== null && _b !== void 0 ? _b : (messageToSend.CHILD_LOCK = new MideaE1Message_1.MessageLock(this.device_protocol_version));
105
- messageToSend.CHILD_LOCK.lock = v;
106
- }
107
- else if (k === 'STORAGE') {
108
- (_c = messageToSend.STORAGE) !== null && _c !== void 0 ? _c : (messageToSend.STORAGE = new MideaE1Message_1.MessageStorage(this.device_protocol_version));
109
- messageToSend.STORAGE.storage = v;
110
- }
111
- }
112
- for (const [k, v] of Object.entries(messageToSend)) {
113
- if (v !== undefined) {
114
- this.logger.debug(`[${this.name}] Set message ${k}:\n${JSON.stringify(v)}`);
115
- await this.build_send(v);
116
- }
117
- }
118
- }
119
- catch (err) {
120
- const msg = err instanceof Error ? err.stack : err;
121
- this.logger.debug(`[${this.name}] Error in set_attribute (${this.ip}:${this.port}):\n${msg}`);
122
- }
123
- }
124
- set_subtype() {
125
- this.logger.debug('No subtype for E1 device');
126
- }
127
- }
128
- exports.default = MideaE1Device;
1
+ "use strict";
2
+ /***********************************************************************
3
+ * Midea Dishwasher Device class
4
+ *
5
+ * Copyright (c) 2024 Kovalovszky Patrik, https://github.com/kovapatrik
6
+ *
7
+ * With thanks to https://github.com/georgezhao2010/midea_ac_lan
8
+ *
9
+ */
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ const MideaDevice_1 = __importDefault(require("../../core/MideaDevice"));
15
+ const MideaE1Message_1 = require("./MideaE1Message");
16
+ class MideaE1Device extends MideaDevice_1.default {
17
+ /*********************************************************************
18
+ * Constructor initializes all the attributes. We set some to invalid
19
+ * values so that they are detected as "changed" on the first status
20
+ * refresh... and passed back to the Homebridge/HomeKit accessory callback
21
+ * function to set their initial values.
22
+ */
23
+ constructor(logger, device_info, config, deviceConfig) {
24
+ super(logger, device_info, config, deviceConfig);
25
+ this.attributes = {
26
+ POWER: false,
27
+ STATUS: undefined,
28
+ MODE: 0,
29
+ ADDITIONAL: 0,
30
+ DOOR: false,
31
+ RINSE_AID: false,
32
+ SALT: false,
33
+ START_PAUSE: false,
34
+ START: false,
35
+ CHILD_LOCK: false,
36
+ UV: false,
37
+ DRY: false,
38
+ DRY_STATUS: false,
39
+ STORAGE: false,
40
+ STORAGE_STATUS: false,
41
+ TIME_REMAINING: undefined,
42
+ PROGRESS: undefined,
43
+ STORAGE_REMAINING: undefined,
44
+ TEMPERATURE: undefined,
45
+ HUMIDITY: undefined,
46
+ WATERSWITCH: false,
47
+ WATER_LACK: false,
48
+ ERROR_CODE: undefined,
49
+ SOFTWATER: 0,
50
+ WRONG_OPERATION: undefined,
51
+ BRIGHT: undefined,
52
+ };
53
+ }
54
+ build_query() {
55
+ return [new MideaE1Message_1.MessageQuery(this.device_protocol_version)];
56
+ }
57
+ process_message(msg) {
58
+ const message = new MideaE1Message_1.MessageE1Response(msg);
59
+ if (this.verbose) {
60
+ this.logger.debug(`[${this.name}] Body:\n${JSON.stringify(message.body)}`);
61
+ }
62
+ const changed = {};
63
+ for (const status of Object.keys(this.attributes)) {
64
+ const value = message.get_body_attribute(status.toLowerCase());
65
+ if (value !== undefined) {
66
+ if (this.attributes[status] !== value) {
67
+ // Track only those attributes that change value. So when we send to the Homebridge /
68
+ // HomeKit accessory we only update values that change. First time through this
69
+ // should be most/all attributes having initialized them to invalid values.
70
+ this.logger.debug(`[${this.name}] Value for ${status} changed from '${this.attributes[status]}' to '${value}'`);
71
+ changed[status] = value;
72
+ }
73
+ this.attributes[status] = value;
74
+ }
75
+ }
76
+ // Now we update Homebridge / Homekit accessory
77
+ if (Object.keys(changed).length > 0) {
78
+ this.update(changed);
79
+ }
80
+ else {
81
+ this.logger.debug(`[${this.name}] Status unchanged`);
82
+ }
83
+ }
84
+ async set_attribute(attributes) {
85
+ var _a, _b, _c;
86
+ const messageToSend = {
87
+ POWER: undefined,
88
+ CHILD_LOCK: undefined,
89
+ STORAGE: undefined,
90
+ };
91
+ try {
92
+ for (const [k, v] of Object.entries(attributes)) {
93
+ if (v === this.attributes[k]) {
94
+ this.logger.info(`[${this.name}] Attribute ${k} already set to ${v}`);
95
+ continue;
96
+ }
97
+ this.logger.info(`[${this.name}] Set device attribute ${k} to: ${v}`);
98
+ this.attributes[k] = v;
99
+ if (k === 'POWER') {
100
+ (_a = messageToSend.POWER) !== null && _a !== void 0 ? _a : (messageToSend.POWER = new MideaE1Message_1.MessagePower(this.device_protocol_version));
101
+ messageToSend.POWER.power = v;
102
+ }
103
+ else if (k === 'CHILD_LOCK') {
104
+ (_b = messageToSend.CHILD_LOCK) !== null && _b !== void 0 ? _b : (messageToSend.CHILD_LOCK = new MideaE1Message_1.MessageLock(this.device_protocol_version));
105
+ messageToSend.CHILD_LOCK.lock = v;
106
+ }
107
+ else if (k === 'STORAGE') {
108
+ (_c = messageToSend.STORAGE) !== null && _c !== void 0 ? _c : (messageToSend.STORAGE = new MideaE1Message_1.MessageStorage(this.device_protocol_version));
109
+ messageToSend.STORAGE.storage = v;
110
+ }
111
+ }
112
+ for (const [k, v] of Object.entries(messageToSend)) {
113
+ if (v !== undefined) {
114
+ this.logger.debug(`[${this.name}] Set message ${k}:\n${JSON.stringify(v)}`);
115
+ await this.build_send(v);
116
+ }
117
+ }
118
+ }
119
+ catch (err) {
120
+ const msg = err instanceof Error ? err.stack : err;
121
+ this.logger.debug(`[${this.name}] Error in set_attribute (${this.ip}:${this.port}):\n${msg}`);
122
+ }
123
+ }
124
+ set_subtype() {
125
+ this.logger.debug('No subtype for E1 device');
126
+ }
127
+ }
128
+ exports.default = MideaE1Device;
129
129
  //# sourceMappingURL=MideaE1Device.js.map
@@ -1,29 +1,29 @@
1
- /// <reference types="node" />
2
- import { MessageRequest, MessageResponse, MessageType } from '../../core/MideaMessage';
3
- declare abstract class MessageE1Base extends MessageRequest {
4
- constructor(device_protocol_version: number, message_type: MessageType, body_type: number);
5
- }
6
- export declare class MessagePower extends MessageE1Base {
7
- power: boolean;
8
- constructor(device_protocol_version: number);
9
- get _body(): Buffer;
10
- }
11
- export declare class MessageLock extends MessageE1Base {
12
- lock: boolean;
13
- constructor(device_protocol_version: number);
14
- get _body(): Buffer;
15
- }
16
- export declare class MessageStorage extends MessageE1Base {
17
- storage: boolean;
18
- constructor(device_protocol_version: number);
19
- get _body(): Buffer;
20
- }
21
- export declare class MessageQuery extends MessageE1Base {
22
- constructor(device_protocol_version: number);
23
- get _body(): Buffer;
24
- }
25
- export declare class MessageE1Response extends MessageResponse {
26
- constructor(message: Buffer);
27
- }
28
- export {};
1
+ /// <reference types="node" />
2
+ import { MessageRequest, MessageResponse, MessageType } from '../../core/MideaMessage';
3
+ declare abstract class MessageE1Base extends MessageRequest {
4
+ constructor(device_protocol_version: number, message_type: MessageType, body_type: number);
5
+ }
6
+ export declare class MessagePower extends MessageE1Base {
7
+ power: boolean;
8
+ constructor(device_protocol_version: number);
9
+ get _body(): Buffer;
10
+ }
11
+ export declare class MessageLock extends MessageE1Base {
12
+ lock: boolean;
13
+ constructor(device_protocol_version: number);
14
+ get _body(): Buffer;
15
+ }
16
+ export declare class MessageStorage extends MessageE1Base {
17
+ storage: boolean;
18
+ constructor(device_protocol_version: number);
19
+ get _body(): Buffer;
20
+ }
21
+ export declare class MessageQuery extends MessageE1Base {
22
+ constructor(device_protocol_version: number);
23
+ get _body(): Buffer;
24
+ }
25
+ export declare class MessageE1Response extends MessageResponse {
26
+ constructor(message: Buffer);
27
+ }
28
+ export {};
29
29
  //# sourceMappingURL=MideaE1Message.d.ts.map