homebridge-midea-platform 1.1.1-beta.1 → 1.1.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/pre-commit +0 -0
- package/dist/accessory/AccessoryFactory.d.ts +11 -11
- package/dist/accessory/AccessoryFactory.js +28 -28
- package/dist/accessory/AirConditionerAccessory.d.ts +86 -86
- package/dist/accessory/AirConditionerAccessory.js +560 -560
- package/dist/accessory/BaseAccessory.d.ts +11 -11
- package/dist/accessory/BaseAccessory.js +21 -21
- package/dist/accessory/DehumidifierAccessory.d.ts +45 -45
- package/dist/accessory/DehumidifierAccessory.js +343 -343
- package/dist/accessory/ElectricWaterHeaterAccessory.d.ts +44 -44
- package/dist/accessory/ElectricWaterHeaterAccessory.js +176 -176
- package/dist/accessory/FanAccessory.d.ts +39 -39
- package/dist/accessory/FanAccessory.js +123 -123
- package/dist/accessory/FrontLoadWasherAccessory.d.ts +31 -0
- package/dist/accessory/FrontLoadWasherAccessory.d.ts.map +1 -0
- package/dist/accessory/FrontLoadWasherAccessory.js +61 -0
- package/dist/accessory/FrontLoadWasherAccessory.js.map +1 -0
- package/dist/accessory/GasWaterHeaterAccessory.d.ts +51 -51
- package/dist/accessory/GasWaterHeaterAccessory.js +216 -216
- package/dist/core/MideaCloud.d.ts +35 -35
- package/dist/core/MideaCloud.js +350 -350
- package/dist/core/MideaConstants.d.ts +49 -48
- package/dist/core/MideaConstants.d.ts.map +1 -1
- package/dist/core/MideaConstants.js +57 -56
- package/dist/core/MideaConstants.js.map +1 -1
- package/dist/core/MideaDevice.d.ts +76 -76
- package/dist/core/MideaDevice.d.ts.map +1 -1
- package/dist/core/MideaDevice.js +411 -411
- package/dist/core/MideaDiscover.d.ts +35 -35
- package/dist/core/MideaDiscover.js +212 -212
- package/dist/core/MideaMessage.d.ts +75 -75
- package/dist/core/MideaMessage.d.ts.map +1 -1
- package/dist/core/MideaMessage.js +184 -191
- package/dist/core/MideaMessage.js.map +1 -1
- package/dist/core/MideaPacketBuilder.d.ts +10 -10
- package/dist/core/MideaPacketBuilder.js +60 -60
- package/dist/core/MideaSecurity.d.ts +63 -63
- package/dist/core/MideaSecurity.js +242 -242
- package/dist/core/MideaUtils.d.ts +32 -32
- package/dist/core/MideaUtils.js +181 -181
- package/dist/devices/DeviceFactory.d.ts +11 -11
- package/dist/devices/DeviceFactory.js +30 -30
- package/dist/devices/a1/MideaA1Device.d.ts +76 -76
- package/dist/devices/a1/MideaA1Device.js +136 -136
- package/dist/devices/a1/MideaA1Message.d.ts +40 -40
- package/dist/devices/a1/MideaA1Message.js +198 -198
- package/dist/devices/ac/MideaACDevice.d.ts +100 -100
- package/dist/devices/ac/MideaACDevice.js +370 -370
- package/dist/devices/ac/MideaACMessage.d.ts +92 -92
- package/dist/devices/ac/MideaACMessage.d.ts.map +1 -1
- package/dist/devices/ac/MideaACMessage.js +589 -591
- package/dist/devices/ac/MideaACMessage.js.map +1 -1
- package/dist/devices/db/MideaDBDevice.d.ts +30 -0
- package/dist/devices/db/MideaDBDevice.d.ts.map +1 -0
- package/dist/devices/db/MideaDBDevice.js +89 -0
- package/dist/devices/db/MideaDBDevice.js.map +1 -0
- package/dist/devices/db/MideaDBMessage.d.ts +33 -0
- package/dist/devices/db/MideaDBMessage.d.ts.map +1 -0
- package/dist/devices/db/MideaDBMessage.js +102 -0
- package/dist/devices/db/MideaDBMessage.js.map +1 -0
- package/dist/devices/e2/MideaE2Device.d.ts +44 -44
- package/dist/devices/e2/MideaE2Device.js +119 -119
- package/dist/devices/e2/MideaE2Message.d.ts +33 -33
- package/dist/devices/e2/MideaE2Message.js +132 -132
- package/dist/devices/e3/MideaE3Device.d.ts +43 -43
- package/dist/devices/e3/MideaE3Device.js +125 -125
- package/dist/devices/e3/MideaE3Message.d.ts +51 -51
- package/dist/devices/e3/MideaE3Message.js +136 -136
- package/dist/devices/fa/MideaFADevice.d.ts +36 -36
- package/dist/devices/fa/MideaFADevice.js +92 -92
- package/dist/devices/fa/MideaFAMessage.d.ts +38 -38
- package/dist/devices/fa/MideaFAMessage.js +98 -98
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/platform.d.ts +60 -60
- package/dist/platform.js +213 -213
- package/dist/platformUtils.d.ts +97 -97
- package/dist/platformUtils.js +95 -95
- package/dist/settings.d.ts +8 -8
- package/dist/settings.js +11 -11
- package/package.json +9 -4
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/***********************************************************************
|
|
3
|
-
* Homebridge-midea-platform miscellaneous support functions.
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2023 Kovalovszky Patrik, https://github.com/kovapatrik
|
|
6
|
-
* Portions Copyright (c) 2023 David Kerr, https://github.com/dkerr64
|
|
7
|
-
*
|
|
8
|
-
* Includes very basic implementation of a promise-wrapped Socket class.
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
import { Logger } from 'homebridge';
|
|
12
|
-
import { Endianness } from './MideaConstants';
|
|
13
|
-
export declare function numberToUint8Array(num: number, byte_length: number, endianness: Endianness): Uint8Array;
|
|
14
|
-
export declare function strxor(a: Buffer, b: Buffer): Buffer;
|
|
15
|
-
export declare function calculate(data: Buffer): number;
|
|
16
|
-
/*********************************************************************
|
|
17
|
-
* PromiseSocket
|
|
18
|
-
* A very basic implementation of promise-wrapped Socket
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
export declare class PromiseSocket {
|
|
22
|
-
private readonly logger;
|
|
23
|
-
private readonly logerror;
|
|
24
|
-
private innerSok;
|
|
25
|
-
destroyed: boolean;
|
|
26
|
-
constructor(logger: Logger, logerror: boolean);
|
|
27
|
-
connect(port: number, host: string): Promise<void>;
|
|
28
|
-
setTimeout(t: number): void;
|
|
29
|
-
destroy(): void;
|
|
30
|
-
write(data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
|
|
31
|
-
read(): Promise<Buffer>;
|
|
32
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/***********************************************************************
|
|
3
|
+
* Homebridge-midea-platform miscellaneous support functions.
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2023 Kovalovszky Patrik, https://github.com/kovapatrik
|
|
6
|
+
* Portions Copyright (c) 2023 David Kerr, https://github.com/dkerr64
|
|
7
|
+
*
|
|
8
|
+
* Includes very basic implementation of a promise-wrapped Socket class.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
import { Logger } from 'homebridge';
|
|
12
|
+
import { Endianness } from './MideaConstants';
|
|
13
|
+
export declare function numberToUint8Array(num: number, byte_length: number, endianness: Endianness): Uint8Array;
|
|
14
|
+
export declare function strxor(a: Buffer, b: Buffer): Buffer;
|
|
15
|
+
export declare function calculate(data: Buffer): number;
|
|
16
|
+
/*********************************************************************
|
|
17
|
+
* PromiseSocket
|
|
18
|
+
* A very basic implementation of promise-wrapped Socket
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export declare class PromiseSocket {
|
|
22
|
+
private readonly logger;
|
|
23
|
+
private readonly logerror;
|
|
24
|
+
private innerSok;
|
|
25
|
+
destroyed: boolean;
|
|
26
|
+
constructor(logger: Logger, logerror: boolean);
|
|
27
|
+
connect(port: number, host: string): Promise<void>;
|
|
28
|
+
setTimeout(t: number): void;
|
|
29
|
+
destroy(): void;
|
|
30
|
+
write(data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
|
|
31
|
+
read(): Promise<Buffer>;
|
|
32
|
+
}
|
|
33
33
|
//# sourceMappingURL=MideaUtils.d.ts.map
|
package/dist/core/MideaUtils.js
CHANGED
|
@@ -1,182 +1,182 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PromiseSocket = exports.calculate = exports.strxor = exports.numberToUint8Array = void 0;
|
|
4
|
-
const MideaConstants_1 = require("./MideaConstants");
|
|
5
|
-
const net_1 = require("net");
|
|
6
|
-
function numberToUint8Array(num, byte_length, endianness) {
|
|
7
|
-
const arr = new Uint8Array(byte_length);
|
|
8
|
-
for (let i = 0; i < byte_length; i++) {
|
|
9
|
-
arr[i] = num % 256;
|
|
10
|
-
num = Math.floor(num / 256);
|
|
11
|
-
}
|
|
12
|
-
return endianness === MideaConstants_1.Endianness.Big ? arr.reverse() : arr;
|
|
13
|
-
}
|
|
14
|
-
exports.numberToUint8Array = numberToUint8Array;
|
|
15
|
-
function strxor(a, b) {
|
|
16
|
-
if (a.length !== b.length) {
|
|
17
|
-
throw Error('strxor: a and b must have the same length!');
|
|
18
|
-
}
|
|
19
|
-
const output = Buffer.alloc(a.length);
|
|
20
|
-
for (let i = 0; i < a.length; i++) {
|
|
21
|
-
output[i] = a[i] ^ b[i];
|
|
22
|
-
}
|
|
23
|
-
return output;
|
|
24
|
-
}
|
|
25
|
-
exports.strxor = strxor;
|
|
26
|
-
const CRC8_854_TABLE = [
|
|
27
|
-
0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41, 0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40,
|
|
28
|
-
0x1e, 0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc, 0x23, 0x7d, 0x9f, 0xc1, 0x42, 0x1c, 0xfe, 0xa0, 0xe1, 0xbf, 0x5d, 0x03, 0x80, 0xde,
|
|
29
|
-
0x3c, 0x62, 0xbe, 0xe0, 0x02, 0x5c, 0xdf, 0x81, 0x63, 0x3d, 0x7c, 0x22, 0xc0, 0x9e, 0x1d, 0x43, 0xa1, 0xff, 0x46, 0x18, 0xfa, 0xa4, 0x27,
|
|
30
|
-
0x79, 0x9b, 0xc5, 0x84, 0xda, 0x38, 0x66, 0xe5, 0xbb, 0x59, 0x07, 0xdb, 0x85, 0x67, 0x39, 0xba, 0xe4, 0x06, 0x58, 0x19, 0x47, 0xa5, 0xfb,
|
|
31
|
-
0x78, 0x26, 0xc4, 0x9a, 0x65, 0x3b, 0xd9, 0x87, 0x04, 0x5a, 0xb8, 0xe6, 0xa7, 0xf9, 0x1b, 0x45, 0xc6, 0x98, 0x7a, 0x24, 0xf8, 0xa6, 0x44,
|
|
32
|
-
0x1a, 0x99, 0xc7, 0x25, 0x7b, 0x3a, 0x64, 0x86, 0xd8, 0x5b, 0x05, 0xe7, 0xb9, 0x8c, 0xd2, 0x30, 0x6e, 0xed, 0xb3, 0x51, 0x0f, 0x4e, 0x10,
|
|
33
|
-
0xf2, 0xac, 0x2f, 0x71, 0x93, 0xcd, 0x11, 0x4f, 0xad, 0xf3, 0x70, 0x2e, 0xcc, 0x92, 0xd3, 0x8d, 0x6f, 0x31, 0xb2, 0xec, 0x0e, 0x50, 0xaf,
|
|
34
|
-
0xf1, 0x13, 0x4d, 0xce, 0x90, 0x72, 0x2c, 0x6d, 0x33, 0xd1, 0x8f, 0x0c, 0x52, 0xb0, 0xee, 0x32, 0x6c, 0x8e, 0xd0, 0x53, 0x0d, 0xef, 0xb1,
|
|
35
|
-
0xf0, 0xae, 0x4c, 0x12, 0x91, 0xcf, 0x2d, 0x73, 0xca, 0x94, 0x76, 0x28, 0xab, 0xf5, 0x17, 0x49, 0x08, 0x56, 0xb4, 0xea, 0x69, 0x37, 0xd5,
|
|
36
|
-
0x8b, 0x57, 0x09, 0xeb, 0xb5, 0x36, 0x68, 0x8a, 0xd4, 0x95, 0xcb, 0x29, 0x77, 0xf4, 0xaa, 0x48, 0x16, 0xe9, 0xb7, 0x55, 0x0b, 0x88, 0xd6,
|
|
37
|
-
0x34, 0x6a, 0x2b, 0x75, 0x97, 0xc9, 0x4a, 0x14, 0xf6, 0xa8, 0x74, 0x2a, 0xc8, 0x96, 0x15, 0x4b, 0xa9, 0xf7, 0xb6, 0xe8, 0x0a, 0x54, 0xd7,
|
|
38
|
-
0x89, 0x6b, 0x35,
|
|
39
|
-
];
|
|
40
|
-
function calculate(data) {
|
|
41
|
-
let crc = 0;
|
|
42
|
-
for (let i = 0; i < data.length; i++) {
|
|
43
|
-
let k = crc ^ data[i];
|
|
44
|
-
if (k > 256) {
|
|
45
|
-
k -= 256;
|
|
46
|
-
}
|
|
47
|
-
if (k < 0) {
|
|
48
|
-
k += 256;
|
|
49
|
-
}
|
|
50
|
-
crc = CRC8_854_TABLE[k];
|
|
51
|
-
}
|
|
52
|
-
return crc;
|
|
53
|
-
}
|
|
54
|
-
exports.calculate = calculate;
|
|
55
|
-
/*********************************************************************
|
|
56
|
-
* PromiseSocket
|
|
57
|
-
* A very basic implementation of promise-wrapped Socket
|
|
58
|
-
*
|
|
59
|
-
*/
|
|
60
|
-
class PromiseSocket {
|
|
61
|
-
constructor(logger, logerror) {
|
|
62
|
-
this.logger = logger;
|
|
63
|
-
this.logerror = logerror;
|
|
64
|
-
this.innerSok = new net_1.Socket();
|
|
65
|
-
this.destroyed = false;
|
|
66
|
-
this.innerSok.on('error', (e) => {
|
|
67
|
-
// Log the error
|
|
68
|
-
const msg = e instanceof Error ? e.stack : e;
|
|
69
|
-
if (this.logerror) {
|
|
70
|
-
this.logger.warn(`Socket error:\n${msg}`);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
this.logger.debug(`Socket error:\n${msg}`);
|
|
74
|
-
}
|
|
75
|
-
// According to https://nodejs.org/api/net.html#event-error_1 the "close" event
|
|
76
|
-
// will be called immediately following an "error" event. So don't throw an error
|
|
77
|
-
// and handle the destory in the close event.
|
|
78
|
-
});
|
|
79
|
-
this.innerSok.on('close', async (hadError) => {
|
|
80
|
-
this.destroy();
|
|
81
|
-
if (this.logerror) {
|
|
82
|
-
this.logger.warn(`Socket closed ${hadError ? 'with' : 'without'} error`);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
this.logger.debug(`Socket closed ${hadError ? 'with' : 'without'} error`);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
async connect(port, host) {
|
|
90
|
-
return new Promise((resolve, reject) => {
|
|
91
|
-
const errorHandler = (err) => {
|
|
92
|
-
removeListeners();
|
|
93
|
-
reject(err);
|
|
94
|
-
};
|
|
95
|
-
const removeListeners = () => {
|
|
96
|
-
this.innerSok.removeListener('error', errorHandler);
|
|
97
|
-
};
|
|
98
|
-
this.innerSok.connect(port, host, () => {
|
|
99
|
-
// This function is added as a "connect" listener so called
|
|
100
|
-
// on successful connection.
|
|
101
|
-
removeListeners();
|
|
102
|
-
resolve();
|
|
103
|
-
});
|
|
104
|
-
this.innerSok.on('error', errorHandler);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
setTimeout(t) {
|
|
108
|
-
this.innerSok.setTimeout(t);
|
|
109
|
-
}
|
|
110
|
-
destroy() {
|
|
111
|
-
this.destroyed = true;
|
|
112
|
-
this.innerSok.destroy();
|
|
113
|
-
}
|
|
114
|
-
async write(data, encoding) {
|
|
115
|
-
return new Promise((resolve, reject) => {
|
|
116
|
-
const errorHandler = (err) => {
|
|
117
|
-
removeListeners();
|
|
118
|
-
reject(err);
|
|
119
|
-
};
|
|
120
|
-
const removeListeners = () => {
|
|
121
|
-
this.innerSok.removeListener('error', errorHandler);
|
|
122
|
-
};
|
|
123
|
-
this.innerSok.on('error', errorHandler);
|
|
124
|
-
try {
|
|
125
|
-
this.innerSok.write(data, encoding, (err) => {
|
|
126
|
-
// This function is called when all data successfully sent
|
|
127
|
-
removeListeners();
|
|
128
|
-
if (err) {
|
|
129
|
-
reject(err);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
resolve();
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
catch (err) {
|
|
137
|
-
removeListeners();
|
|
138
|
-
reject(err);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
async read() {
|
|
143
|
-
return new Promise((resolve, reject) => {
|
|
144
|
-
let buf = Buffer.alloc(0);
|
|
145
|
-
const dataHandler = (data) => {
|
|
146
|
-
buf = Buffer.concat([buf, data]);
|
|
147
|
-
removeListeners();
|
|
148
|
-
resolve(buf);
|
|
149
|
-
};
|
|
150
|
-
const timeoutHandler = () => {
|
|
151
|
-
removeListeners();
|
|
152
|
-
resolve(buf);
|
|
153
|
-
};
|
|
154
|
-
const endHandler = () => {
|
|
155
|
-
removeListeners();
|
|
156
|
-
resolve(buf);
|
|
157
|
-
};
|
|
158
|
-
const errorHandler = (err) => {
|
|
159
|
-
removeListeners();
|
|
160
|
-
reject(err);
|
|
161
|
-
};
|
|
162
|
-
const closeHandler = () => {
|
|
163
|
-
removeListeners();
|
|
164
|
-
resolve(buf);
|
|
165
|
-
};
|
|
166
|
-
const removeListeners = () => {
|
|
167
|
-
this.innerSok.removeListener('close', closeHandler);
|
|
168
|
-
this.innerSok.removeListener('data', dataHandler);
|
|
169
|
-
this.innerSok.removeListener('timeout', timeoutHandler);
|
|
170
|
-
this.innerSok.removeListener('end', endHandler);
|
|
171
|
-
this.innerSok.removeListener('error', errorHandler);
|
|
172
|
-
};
|
|
173
|
-
this.innerSok.on('close', closeHandler);
|
|
174
|
-
this.innerSok.on('data', dataHandler);
|
|
175
|
-
this.innerSok.on('timeout', timeoutHandler);
|
|
176
|
-
this.innerSok.on('end', endHandler);
|
|
177
|
-
this.innerSok.on('error', errorHandler);
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
exports.PromiseSocket = PromiseSocket;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromiseSocket = exports.calculate = exports.strxor = exports.numberToUint8Array = void 0;
|
|
4
|
+
const MideaConstants_1 = require("./MideaConstants");
|
|
5
|
+
const net_1 = require("net");
|
|
6
|
+
function numberToUint8Array(num, byte_length, endianness) {
|
|
7
|
+
const arr = new Uint8Array(byte_length);
|
|
8
|
+
for (let i = 0; i < byte_length; i++) {
|
|
9
|
+
arr[i] = num % 256;
|
|
10
|
+
num = Math.floor(num / 256);
|
|
11
|
+
}
|
|
12
|
+
return endianness === MideaConstants_1.Endianness.Big ? arr.reverse() : arr;
|
|
13
|
+
}
|
|
14
|
+
exports.numberToUint8Array = numberToUint8Array;
|
|
15
|
+
function strxor(a, b) {
|
|
16
|
+
if (a.length !== b.length) {
|
|
17
|
+
throw Error('strxor: a and b must have the same length!');
|
|
18
|
+
}
|
|
19
|
+
const output = Buffer.alloc(a.length);
|
|
20
|
+
for (let i = 0; i < a.length; i++) {
|
|
21
|
+
output[i] = a[i] ^ b[i];
|
|
22
|
+
}
|
|
23
|
+
return output;
|
|
24
|
+
}
|
|
25
|
+
exports.strxor = strxor;
|
|
26
|
+
const CRC8_854_TABLE = [
|
|
27
|
+
0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41, 0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40,
|
|
28
|
+
0x1e, 0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc, 0x23, 0x7d, 0x9f, 0xc1, 0x42, 0x1c, 0xfe, 0xa0, 0xe1, 0xbf, 0x5d, 0x03, 0x80, 0xde,
|
|
29
|
+
0x3c, 0x62, 0xbe, 0xe0, 0x02, 0x5c, 0xdf, 0x81, 0x63, 0x3d, 0x7c, 0x22, 0xc0, 0x9e, 0x1d, 0x43, 0xa1, 0xff, 0x46, 0x18, 0xfa, 0xa4, 0x27,
|
|
30
|
+
0x79, 0x9b, 0xc5, 0x84, 0xda, 0x38, 0x66, 0xe5, 0xbb, 0x59, 0x07, 0xdb, 0x85, 0x67, 0x39, 0xba, 0xe4, 0x06, 0x58, 0x19, 0x47, 0xa5, 0xfb,
|
|
31
|
+
0x78, 0x26, 0xc4, 0x9a, 0x65, 0x3b, 0xd9, 0x87, 0x04, 0x5a, 0xb8, 0xe6, 0xa7, 0xf9, 0x1b, 0x45, 0xc6, 0x98, 0x7a, 0x24, 0xf8, 0xa6, 0x44,
|
|
32
|
+
0x1a, 0x99, 0xc7, 0x25, 0x7b, 0x3a, 0x64, 0x86, 0xd8, 0x5b, 0x05, 0xe7, 0xb9, 0x8c, 0xd2, 0x30, 0x6e, 0xed, 0xb3, 0x51, 0x0f, 0x4e, 0x10,
|
|
33
|
+
0xf2, 0xac, 0x2f, 0x71, 0x93, 0xcd, 0x11, 0x4f, 0xad, 0xf3, 0x70, 0x2e, 0xcc, 0x92, 0xd3, 0x8d, 0x6f, 0x31, 0xb2, 0xec, 0x0e, 0x50, 0xaf,
|
|
34
|
+
0xf1, 0x13, 0x4d, 0xce, 0x90, 0x72, 0x2c, 0x6d, 0x33, 0xd1, 0x8f, 0x0c, 0x52, 0xb0, 0xee, 0x32, 0x6c, 0x8e, 0xd0, 0x53, 0x0d, 0xef, 0xb1,
|
|
35
|
+
0xf0, 0xae, 0x4c, 0x12, 0x91, 0xcf, 0x2d, 0x73, 0xca, 0x94, 0x76, 0x28, 0xab, 0xf5, 0x17, 0x49, 0x08, 0x56, 0xb4, 0xea, 0x69, 0x37, 0xd5,
|
|
36
|
+
0x8b, 0x57, 0x09, 0xeb, 0xb5, 0x36, 0x68, 0x8a, 0xd4, 0x95, 0xcb, 0x29, 0x77, 0xf4, 0xaa, 0x48, 0x16, 0xe9, 0xb7, 0x55, 0x0b, 0x88, 0xd6,
|
|
37
|
+
0x34, 0x6a, 0x2b, 0x75, 0x97, 0xc9, 0x4a, 0x14, 0xf6, 0xa8, 0x74, 0x2a, 0xc8, 0x96, 0x15, 0x4b, 0xa9, 0xf7, 0xb6, 0xe8, 0x0a, 0x54, 0xd7,
|
|
38
|
+
0x89, 0x6b, 0x35,
|
|
39
|
+
];
|
|
40
|
+
function calculate(data) {
|
|
41
|
+
let crc = 0;
|
|
42
|
+
for (let i = 0; i < data.length; i++) {
|
|
43
|
+
let k = crc ^ data[i];
|
|
44
|
+
if (k > 256) {
|
|
45
|
+
k -= 256;
|
|
46
|
+
}
|
|
47
|
+
if (k < 0) {
|
|
48
|
+
k += 256;
|
|
49
|
+
}
|
|
50
|
+
crc = CRC8_854_TABLE[k];
|
|
51
|
+
}
|
|
52
|
+
return crc;
|
|
53
|
+
}
|
|
54
|
+
exports.calculate = calculate;
|
|
55
|
+
/*********************************************************************
|
|
56
|
+
* PromiseSocket
|
|
57
|
+
* A very basic implementation of promise-wrapped Socket
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
class PromiseSocket {
|
|
61
|
+
constructor(logger, logerror) {
|
|
62
|
+
this.logger = logger;
|
|
63
|
+
this.logerror = logerror;
|
|
64
|
+
this.innerSok = new net_1.Socket();
|
|
65
|
+
this.destroyed = false;
|
|
66
|
+
this.innerSok.on('error', (e) => {
|
|
67
|
+
// Log the error
|
|
68
|
+
const msg = e instanceof Error ? e.stack : e;
|
|
69
|
+
if (this.logerror) {
|
|
70
|
+
this.logger.warn(`Socket error:\n${msg}`);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.logger.debug(`Socket error:\n${msg}`);
|
|
74
|
+
}
|
|
75
|
+
// According to https://nodejs.org/api/net.html#event-error_1 the "close" event
|
|
76
|
+
// will be called immediately following an "error" event. So don't throw an error
|
|
77
|
+
// and handle the destory in the close event.
|
|
78
|
+
});
|
|
79
|
+
this.innerSok.on('close', async (hadError) => {
|
|
80
|
+
this.destroy();
|
|
81
|
+
if (this.logerror) {
|
|
82
|
+
this.logger.warn(`Socket closed ${hadError ? 'with' : 'without'} error`);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
this.logger.debug(`Socket closed ${hadError ? 'with' : 'without'} error`);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async connect(port, host) {
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
const errorHandler = (err) => {
|
|
92
|
+
removeListeners();
|
|
93
|
+
reject(err);
|
|
94
|
+
};
|
|
95
|
+
const removeListeners = () => {
|
|
96
|
+
this.innerSok.removeListener('error', errorHandler);
|
|
97
|
+
};
|
|
98
|
+
this.innerSok.connect(port, host, () => {
|
|
99
|
+
// This function is added as a "connect" listener so called
|
|
100
|
+
// on successful connection.
|
|
101
|
+
removeListeners();
|
|
102
|
+
resolve();
|
|
103
|
+
});
|
|
104
|
+
this.innerSok.on('error', errorHandler);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
setTimeout(t) {
|
|
108
|
+
this.innerSok.setTimeout(t);
|
|
109
|
+
}
|
|
110
|
+
destroy() {
|
|
111
|
+
this.destroyed = true;
|
|
112
|
+
this.innerSok.destroy();
|
|
113
|
+
}
|
|
114
|
+
async write(data, encoding) {
|
|
115
|
+
return new Promise((resolve, reject) => {
|
|
116
|
+
const errorHandler = (err) => {
|
|
117
|
+
removeListeners();
|
|
118
|
+
reject(err);
|
|
119
|
+
};
|
|
120
|
+
const removeListeners = () => {
|
|
121
|
+
this.innerSok.removeListener('error', errorHandler);
|
|
122
|
+
};
|
|
123
|
+
this.innerSok.on('error', errorHandler);
|
|
124
|
+
try {
|
|
125
|
+
this.innerSok.write(data, encoding, (err) => {
|
|
126
|
+
// This function is called when all data successfully sent
|
|
127
|
+
removeListeners();
|
|
128
|
+
if (err) {
|
|
129
|
+
reject(err);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
resolve();
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
removeListeners();
|
|
138
|
+
reject(err);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
async read() {
|
|
143
|
+
return new Promise((resolve, reject) => {
|
|
144
|
+
let buf = Buffer.alloc(0);
|
|
145
|
+
const dataHandler = (data) => {
|
|
146
|
+
buf = Buffer.concat([buf, data]);
|
|
147
|
+
removeListeners();
|
|
148
|
+
resolve(buf);
|
|
149
|
+
};
|
|
150
|
+
const timeoutHandler = () => {
|
|
151
|
+
removeListeners();
|
|
152
|
+
resolve(buf);
|
|
153
|
+
};
|
|
154
|
+
const endHandler = () => {
|
|
155
|
+
removeListeners();
|
|
156
|
+
resolve(buf);
|
|
157
|
+
};
|
|
158
|
+
const errorHandler = (err) => {
|
|
159
|
+
removeListeners();
|
|
160
|
+
reject(err);
|
|
161
|
+
};
|
|
162
|
+
const closeHandler = () => {
|
|
163
|
+
removeListeners();
|
|
164
|
+
resolve(buf);
|
|
165
|
+
};
|
|
166
|
+
const removeListeners = () => {
|
|
167
|
+
this.innerSok.removeListener('close', closeHandler);
|
|
168
|
+
this.innerSok.removeListener('data', dataHandler);
|
|
169
|
+
this.innerSok.removeListener('timeout', timeoutHandler);
|
|
170
|
+
this.innerSok.removeListener('end', endHandler);
|
|
171
|
+
this.innerSok.removeListener('error', errorHandler);
|
|
172
|
+
};
|
|
173
|
+
this.innerSok.on('close', closeHandler);
|
|
174
|
+
this.innerSok.on('data', dataHandler);
|
|
175
|
+
this.innerSok.on('timeout', timeoutHandler);
|
|
176
|
+
this.innerSok.on('end', endHandler);
|
|
177
|
+
this.innerSok.on('error', errorHandler);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.PromiseSocket = PromiseSocket;
|
|
182
182
|
//# sourceMappingURL=MideaUtils.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Logger } from 'homebridge';
|
|
2
|
-
import { DeviceInfo } from '../core/MideaConstants';
|
|
3
|
-
import { Config, DeviceConfig } from '../platformUtils';
|
|
4
|
-
import MideaACDevice from './ac/MideaACDevice';
|
|
5
|
-
import MideaA1Device from './a1/MideaA1Device';
|
|
6
|
-
import MideaE2Device from './e2/MideaE2Device';
|
|
7
|
-
import MideaE3Device from './e3/MideaE3Device';
|
|
8
|
-
import MideaFADevice from './fa/MideaFADevice';
|
|
9
|
-
export default class DeviceFactory {
|
|
10
|
-
static createDevice(logger: Logger, device_info: DeviceInfo, config: Config, deviceConfig: DeviceConfig): MideaACDevice | MideaA1Device | MideaE2Device | MideaE3Device | MideaFADevice | null;
|
|
11
|
-
}
|
|
1
|
+
import { Logger } from 'homebridge';
|
|
2
|
+
import { DeviceInfo } from '../core/MideaConstants';
|
|
3
|
+
import { Config, DeviceConfig } from '../platformUtils';
|
|
4
|
+
import MideaACDevice from './ac/MideaACDevice';
|
|
5
|
+
import MideaA1Device from './a1/MideaA1Device';
|
|
6
|
+
import MideaE2Device from './e2/MideaE2Device';
|
|
7
|
+
import MideaE3Device from './e3/MideaE3Device';
|
|
8
|
+
import MideaFADevice from './fa/MideaFADevice';
|
|
9
|
+
export default class DeviceFactory {
|
|
10
|
+
static createDevice(logger: Logger, device_info: DeviceInfo, config: Config, deviceConfig: DeviceConfig): MideaACDevice | MideaA1Device | MideaE2Device | MideaE3Device | MideaFADevice | null;
|
|
11
|
+
}
|
|
12
12
|
//# sourceMappingURL=DeviceFactory.d.ts.map
|
|
@@ -1,31 +1,31 @@
|
|
|
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 MideaConstants_1 = require("../core/MideaConstants");
|
|
7
|
-
const MideaACDevice_1 = __importDefault(require("./ac/MideaACDevice"));
|
|
8
|
-
const MideaA1Device_1 = __importDefault(require("./a1/MideaA1Device"));
|
|
9
|
-
const MideaE2Device_1 = __importDefault(require("./e2/MideaE2Device"));
|
|
10
|
-
const MideaE3Device_1 = __importDefault(require("./e3/MideaE3Device"));
|
|
11
|
-
const MideaFADevice_1 = __importDefault(require("./fa/MideaFADevice"));
|
|
12
|
-
class DeviceFactory {
|
|
13
|
-
static createDevice(logger, device_info, config, deviceConfig) {
|
|
14
|
-
switch (device_info.type) {
|
|
15
|
-
case MideaConstants_1.DeviceType.AIR_CONDITIONER:
|
|
16
|
-
return new MideaACDevice_1.default(logger, device_info, config, deviceConfig);
|
|
17
|
-
case MideaConstants_1.DeviceType.DEHUMIDIFIER:
|
|
18
|
-
return new MideaA1Device_1.default(logger, device_info, config, deviceConfig);
|
|
19
|
-
case MideaConstants_1.DeviceType.ELECTRIC_WATER_HEATER:
|
|
20
|
-
return new MideaE2Device_1.default(logger, device_info, config, deviceConfig);
|
|
21
|
-
case MideaConstants_1.DeviceType.GAS_WATER_HEATER:
|
|
22
|
-
return new MideaE3Device_1.default(logger, device_info, config, deviceConfig);
|
|
23
|
-
case MideaConstants_1.DeviceType.FAN:
|
|
24
|
-
return new MideaFADevice_1.default(logger, device_info, config, deviceConfig);
|
|
25
|
-
default:
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.default = DeviceFactory;
|
|
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 MideaConstants_1 = require("../core/MideaConstants");
|
|
7
|
+
const MideaACDevice_1 = __importDefault(require("./ac/MideaACDevice"));
|
|
8
|
+
const MideaA1Device_1 = __importDefault(require("./a1/MideaA1Device"));
|
|
9
|
+
const MideaE2Device_1 = __importDefault(require("./e2/MideaE2Device"));
|
|
10
|
+
const MideaE3Device_1 = __importDefault(require("./e3/MideaE3Device"));
|
|
11
|
+
const MideaFADevice_1 = __importDefault(require("./fa/MideaFADevice"));
|
|
12
|
+
class DeviceFactory {
|
|
13
|
+
static createDevice(logger, device_info, config, deviceConfig) {
|
|
14
|
+
switch (device_info.type) {
|
|
15
|
+
case MideaConstants_1.DeviceType.AIR_CONDITIONER:
|
|
16
|
+
return new MideaACDevice_1.default(logger, device_info, config, deviceConfig);
|
|
17
|
+
case MideaConstants_1.DeviceType.DEHUMIDIFIER:
|
|
18
|
+
return new MideaA1Device_1.default(logger, device_info, config, deviceConfig);
|
|
19
|
+
case MideaConstants_1.DeviceType.ELECTRIC_WATER_HEATER:
|
|
20
|
+
return new MideaE2Device_1.default(logger, device_info, config, deviceConfig);
|
|
21
|
+
case MideaConstants_1.DeviceType.GAS_WATER_HEATER:
|
|
22
|
+
return new MideaE3Device_1.default(logger, device_info, config, deviceConfig);
|
|
23
|
+
case MideaConstants_1.DeviceType.FAN:
|
|
24
|
+
return new MideaFADevice_1.default(logger, device_info, config, deviceConfig);
|
|
25
|
+
default:
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.default = DeviceFactory;
|
|
31
31
|
//# sourceMappingURL=DeviceFactory.js.map
|