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
package/dist/platform.js CHANGED
@@ -1,214 +1,214 @@
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
- exports.MideaPlatform = void 0;
7
- const settings_1 = require("./settings");
8
- const MideaDiscover_1 = __importDefault(require("./core/MideaDiscover"));
9
- const MideaConstants_1 = require("./core/MideaConstants");
10
- const AccessoryFactory_1 = __importDefault(require("./accessory/AccessoryFactory"));
11
- const DeviceFactory_1 = __importDefault(require("./devices/DeviceFactory"));
12
- const platformUtils_1 = require("./platformUtils");
13
- const lodash_1 = require("lodash");
14
- class MideaPlatform {
15
- constructor(log, config, api) {
16
- this.log = log;
17
- this.config = config;
18
- this.api = api;
19
- this.Service = this.api.hap.Service;
20
- this.Characteristic = this.api.hap.Characteristic;
21
- this.accessories = [];
22
- // Keep track of all devices discovered by broadcast
23
- this.discoveredDevices = {};
24
- this.discoveryInterval = 60; // seconds
25
- Error.stackTraceLimit = 100;
26
- // Add default config values
27
- this.platformConfig = (0, lodash_1.defaultsDeep)(config, platformUtils_1.defaultConfig);
28
- // Enforce min/max values
29
- this.platformConfig.refreshInterval = Math.max(0, Math.min(this.platformConfig.refreshInterval, 86400));
30
- this.platformConfig.heartbeatInterval = Math.max(10, Math.min(this.platformConfig.heartbeatInterval, 120));
31
- // debug log configuration
32
- this.log.debug(`Configuration:\n${JSON.stringify(this.platformConfig, null, 2)}`);
33
- this.discover = new MideaDiscover_1.default(log);
34
- // Register callback with Discover class that is called for each device as
35
- // they are discovered on the network.
36
- this.discover.on('device', this.deviceDiscovered.bind(this));
37
- // Register callback with Discover class that is called when we have exhausted
38
- // all retries to discover devices. We can now check what was found.
39
- this.discover.on('complete', this.discoveryComplete.bind(this));
40
- // When this event is fired it means Homebridge has restored all cached accessories from disk.
41
- // Dynamic Platform plugins should only register new accessories after this event was fired,
42
- // in order to ensure they weren't added to homebridge already. This event can also be used
43
- // to start discovery of new accessories.
44
- this.api.on('didFinishLaunching', this.finishedLaunching.bind(this));
45
- }
46
- /*********************************************************************
47
- * finishedLaunching
48
- * Function called when Homebridge has finished loading the plugin.
49
- */
50
- finishedLaunching() {
51
- this.log.info('Start device discovery...');
52
- // If IP address is in config then probe them directly
53
- this.platformConfig.devices.forEach((device) => {
54
- // for some reason, assigning the regex has to be inside the loop, else fails after first pass.
55
- const regexIPv4 = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gi;
56
- // Pull in defaults
57
- device = (0, lodash_1.defaultsDeep)(device, platformUtils_1.defaultDeviceConfig);
58
- const ip = device.advanced_options.ip.toString().trim();
59
- if (regexIPv4.test(ip)) {
60
- this.discover.discoverDeviceByIP(ip);
61
- }
62
- else if (ip) {
63
- // IP is non-empty, non-null, but not valid IP address
64
- this.log.warn(`[${device.name}] Invalid IP address in configuration: ${ip}`);
65
- }
66
- });
67
- // And then send broadcast to network(s)
68
- this.discover.startDiscover();
69
- }
70
- /*********************************************************************
71
- * deviceDiscovered
72
- * Function called by the 'device' on handler.
73
- */
74
- deviceDiscovered(device_info) {
75
- var _a;
76
- // Find device specific configuration from within the homebridge config file.
77
- // If we have configuration indexed by ID use that, if not use IP address.
78
- const deviceConfig = this.platformConfig.devices.find((device) => device.id === device_info.id);
79
- if (deviceConfig) {
80
- // keep track of discovered devices
81
- this.discoveredDevices[device_info.id] = true;
82
- // Override name with that provided in the config.json settings
83
- device_info.name = (_a = deviceConfig.name) !== null && _a !== void 0 ? _a : device_info.name;
84
- this.addDevice(device_info, deviceConfig);
85
- }
86
- else {
87
- this.log.warn(`[${device_info.name} | ${device_info.ip}}] New device discovered, you must add it to the config.json settings.`);
88
- }
89
- }
90
- /*********************************************************************
91
- * discoveryComplete
92
- * Function called by the 'complete' on handler.
93
- */
94
- discoveryComplete() {
95
- this.log.debug(`Discovery complete, check for missing devices`);
96
- // Check if network broadcasting found all devices that user configured. If not then
97
- // we have to handle those.
98
- let missingDevices = 0;
99
- this.platformConfig.devices.forEach((device) => {
100
- if (!this.discoveredDevices[device.id]) {
101
- // This device was not found by network discovery.
102
- missingDevices++;
103
- if (this.discoveredDevices[device.id] === undefined) {
104
- this.discoveredDevices[device.id] = false;
105
- this.log.warn(`[${device.name}] Device not found (id: ${device.id}), will retry every ${this.discoveryInterval} seconds`);
106
- }
107
- else {
108
- this.log.debug(`[${device.name}] Device not found (id: ${device.id}), will retry in ${this.discoveryInterval} seconds`);
109
- }
110
- }
111
- });
112
- if (missingDevices > 0) {
113
- // Some devices not found. Keep retrying periodically until all are found.
114
- setTimeout(() => {
115
- missingDevices = 0;
116
- // on repeat attempts only retry once (so two broadcasts sent), 3000 miliseconds apart.
117
- this.discover.startDiscover(1, 3000);
118
- }, this.discoveryInterval * 1000);
119
- }
120
- else {
121
- this.log.info(`All configured devices added to Homebridge`);
122
- }
123
- }
124
- /*********************************************************************
125
- * addDevice
126
- * Called for each device as discovered on the network. Creates the
127
- * Midea device handler and the associated Homebridge accessory.
128
- */
129
- async addDevice(device_info, deviceConfig) {
130
- var _a, _b;
131
- const uuid = this.api.hap.uuid.generate(device_info.id.toString());
132
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
133
- // Add default config values
134
- (0, lodash_1.defaultsDeep)(deviceConfig, platformUtils_1.defaultDeviceConfig);
135
- const device = DeviceFactory_1.default.createDevice(this.log, device_info, this.platformConfig, deviceConfig);
136
- if (device === null) {
137
- this.log.error(`Device type is unsupported by the plugin: ${device_info.type}`);
138
- }
139
- else {
140
- if (existingAccessory) {
141
- // the accessory already exists, restore from Homebridge cache
142
- this.log.info(`[${device_info.name}] Restoring existing accessory from cache: ${existingAccessory.displayName}`);
143
- try {
144
- // Token/key is only required for V3 devices
145
- if (device_info.version === MideaConstants_1.ProtocolVersion.V3) {
146
- if (deviceConfig.advanced_options.token && deviceConfig.advanced_options.key) {
147
- // token/key provided in config file, use those... replacing values in cached context
148
- this.log.info(`[${device_info.name}] Cached device, using token/key from config file`);
149
- existingAccessory.context.token = deviceConfig.advanced_options.token;
150
- existingAccessory.context.key = deviceConfig.advanced_options.key;
151
- device.setCredentials(Buffer.from(existingAccessory.context.token, 'hex'), Buffer.from(existingAccessory.context.key, 'hex'));
152
- }
153
- else {
154
- // use token/key values from the accessory cached context
155
- this.log.info(`[${device_info.name}] Cached device, using saved credentials`);
156
- device.setCredentials(Buffer.from(existingAccessory.context.token, 'hex'), Buffer.from(existingAccessory.context.key, 'hex'));
157
- }
158
- }
159
- await device.connect(true);
160
- AccessoryFactory_1.default.createAccessory(this, existingAccessory, device, deviceConfig);
161
- }
162
- catch (err) {
163
- const msg = err instanceof Error ? err.stack : err;
164
- this.log.error(`Cannot connect to device from cache ${device_info.ip}:${device_info.port}, error:\n${msg}`);
165
- }
166
- }
167
- else {
168
- try {
169
- this.log.info('Adding new accessory:', device_info.name);
170
- const accessory = new this.api.platformAccessory(device_info.name, uuid);
171
- // Token/key is only required for V3 devices
172
- if (device_info.version === MideaConstants_1.ProtocolVersion.V3) {
173
- if (deviceConfig.advanced_options.token && deviceConfig.advanced_options.key) {
174
- // token/key provided in config file, use those... set values in cached context
175
- this.log.info(`[${device_info.name}] New device at ${device_info.ip}:${device_info.port}, using token/key from config file`);
176
- accessory.context.token = deviceConfig.advanced_options.token;
177
- accessory.context.key = deviceConfig.advanced_options.key;
178
- accessory.context.id = device_info.id.toString();
179
- device.setCredentials(Buffer.from(accessory.context.token, 'hex'), Buffer.from(accessory.context.key, 'hex'));
180
- }
181
- else {
182
- throw new Error(`Token/key not provided in config file, cannot add new device`);
183
- }
184
- }
185
- await device.connect(false);
186
- await device.refresh_status();
187
- // Set serial number and model into the context if they are provided.
188
- accessory.context.sn = (_a = device_info.sn) !== null && _a !== void 0 ? _a : 'unknown';
189
- accessory.context.model = (_b = device_info.model) !== null && _b !== void 0 ? _b : 'unknown';
190
- // create the accessory handler for the newly create accessory
191
- // this is imported from `platformAccessory.ts`
192
- AccessoryFactory_1.default.createAccessory(this, accessory, device, deviceConfig);
193
- // link the accessory to your platform
194
- this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
195
- }
196
- catch (err) {
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
+ exports.MideaPlatform = void 0;
7
+ const settings_1 = require("./settings");
8
+ const MideaDiscover_1 = __importDefault(require("./core/MideaDiscover"));
9
+ const MideaConstants_1 = require("./core/MideaConstants");
10
+ const AccessoryFactory_1 = __importDefault(require("./accessory/AccessoryFactory"));
11
+ const DeviceFactory_1 = __importDefault(require("./devices/DeviceFactory"));
12
+ const platformUtils_1 = require("./platformUtils");
13
+ const lodash_1 = require("lodash");
14
+ class MideaPlatform {
15
+ constructor(log, config, api) {
16
+ this.log = log;
17
+ this.config = config;
18
+ this.api = api;
19
+ this.Service = this.api.hap.Service;
20
+ this.Characteristic = this.api.hap.Characteristic;
21
+ this.accessories = [];
22
+ // Keep track of all devices discovered by broadcast
23
+ this.discoveredDevices = {};
24
+ this.discoveryInterval = 60; // seconds
25
+ Error.stackTraceLimit = 100;
26
+ // Add default config values
27
+ this.platformConfig = (0, lodash_1.defaultsDeep)(config, platformUtils_1.defaultConfig);
28
+ // Enforce min/max values
29
+ this.platformConfig.refreshInterval = Math.max(0, Math.min(this.platformConfig.refreshInterval, 86400));
30
+ this.platformConfig.heartbeatInterval = Math.max(10, Math.min(this.platformConfig.heartbeatInterval, 120));
31
+ // debug log configuration
32
+ this.log.debug(`Configuration:\n${JSON.stringify(this.platformConfig, null, 2)}`);
33
+ this.discover = new MideaDiscover_1.default(log);
34
+ // Register callback with Discover class that is called for each device as
35
+ // they are discovered on the network.
36
+ this.discover.on('device', this.deviceDiscovered.bind(this));
37
+ // Register callback with Discover class that is called when we have exhausted
38
+ // all retries to discover devices. We can now check what was found.
39
+ this.discover.on('complete', this.discoveryComplete.bind(this));
40
+ // When this event is fired it means Homebridge has restored all cached accessories from disk.
41
+ // Dynamic Platform plugins should only register new accessories after this event was fired,
42
+ // in order to ensure they weren't added to homebridge already. This event can also be used
43
+ // to start discovery of new accessories.
44
+ this.api.on('didFinishLaunching', this.finishedLaunching.bind(this));
45
+ }
46
+ /*********************************************************************
47
+ * finishedLaunching
48
+ * Function called when Homebridge has finished loading the plugin.
49
+ */
50
+ finishedLaunching() {
51
+ this.log.info('Start device discovery...');
52
+ // If IP address is in config then probe them directly
53
+ this.platformConfig.devices.forEach((device) => {
54
+ // for some reason, assigning the regex has to be inside the loop, else fails after first pass.
55
+ const regexIPv4 = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gi;
56
+ // Pull in defaults
57
+ device = (0, lodash_1.defaultsDeep)(device, platformUtils_1.defaultDeviceConfig);
58
+ const ip = device.advanced_options.ip.toString().trim();
59
+ if (regexIPv4.test(ip)) {
60
+ this.discover.discoverDeviceByIP(ip);
61
+ }
62
+ else if (ip) {
63
+ // IP is non-empty, non-null, but not valid IP address
64
+ this.log.warn(`[${device.name}] Invalid IP address in configuration: ${ip}`);
65
+ }
66
+ });
67
+ // And then send broadcast to network(s)
68
+ this.discover.startDiscover();
69
+ }
70
+ /*********************************************************************
71
+ * deviceDiscovered
72
+ * Function called by the 'device' on handler.
73
+ */
74
+ deviceDiscovered(device_info) {
75
+ var _a;
76
+ // Find device specific configuration from within the homebridge config file.
77
+ // If we have configuration indexed by ID use that, if not use IP address.
78
+ const deviceConfig = this.platformConfig.devices.find((device) => device.id === device_info.id);
79
+ if (deviceConfig) {
80
+ // keep track of discovered devices
81
+ this.discoveredDevices[device_info.id] = true;
82
+ // Override name with that provided in the config.json settings
83
+ device_info.name = (_a = deviceConfig.name) !== null && _a !== void 0 ? _a : device_info.name;
84
+ this.addDevice(device_info, deviceConfig);
85
+ }
86
+ else {
87
+ this.log.warn(`[${device_info.name} | ${device_info.ip}}] New device discovered, you must add it to the config.json settings.`);
88
+ }
89
+ }
90
+ /*********************************************************************
91
+ * discoveryComplete
92
+ * Function called by the 'complete' on handler.
93
+ */
94
+ discoveryComplete() {
95
+ this.log.debug(`Discovery complete, check for missing devices`);
96
+ // Check if network broadcasting found all devices that user configured. If not then
97
+ // we have to handle those.
98
+ let missingDevices = 0;
99
+ this.platformConfig.devices.forEach((device) => {
100
+ if (!this.discoveredDevices[device.id]) {
101
+ // This device was not found by network discovery.
102
+ missingDevices++;
103
+ if (this.discoveredDevices[device.id] === undefined) {
104
+ this.discoveredDevices[device.id] = false;
105
+ this.log.warn(`[${device.name}] Device not found (id: ${device.id}), will retry every ${this.discoveryInterval} seconds`);
106
+ }
107
+ else {
108
+ this.log.debug(`[${device.name}] Device not found (id: ${device.id}), will retry in ${this.discoveryInterval} seconds`);
109
+ }
110
+ }
111
+ });
112
+ if (missingDevices > 0) {
113
+ // Some devices not found. Keep retrying periodically until all are found.
114
+ setTimeout(() => {
115
+ missingDevices = 0;
116
+ // on repeat attempts only retry once (so two broadcasts sent), 3000 miliseconds apart.
117
+ this.discover.startDiscover(1, 3000);
118
+ }, this.discoveryInterval * 1000);
119
+ }
120
+ else {
121
+ this.log.info(`All configured devices added to Homebridge`);
122
+ }
123
+ }
124
+ /*********************************************************************
125
+ * addDevice
126
+ * Called for each device as discovered on the network. Creates the
127
+ * Midea device handler and the associated Homebridge accessory.
128
+ */
129
+ async addDevice(device_info, deviceConfig) {
130
+ var _a, _b;
131
+ const uuid = this.api.hap.uuid.generate(device_info.id.toString());
132
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
133
+ // Add default config values
134
+ (0, lodash_1.defaultsDeep)(deviceConfig, platformUtils_1.defaultDeviceConfig);
135
+ const device = DeviceFactory_1.default.createDevice(this.log, device_info, this.platformConfig, deviceConfig);
136
+ if (device === null) {
137
+ this.log.error(`Device type is unsupported by the plugin: ${device_info.type}`);
138
+ }
139
+ else {
140
+ if (existingAccessory) {
141
+ // the accessory already exists, restore from Homebridge cache
142
+ this.log.info(`[${device_info.name}] Restoring existing accessory from cache: ${existingAccessory.displayName}`);
143
+ try {
144
+ // Token/key is only required for V3 devices
145
+ if (device_info.version === MideaConstants_1.ProtocolVersion.V3) {
146
+ if (deviceConfig.advanced_options.token && deviceConfig.advanced_options.key) {
147
+ // token/key provided in config file, use those... replacing values in cached context
148
+ this.log.info(`[${device_info.name}] Cached device, using token/key from config file`);
149
+ existingAccessory.context.token = deviceConfig.advanced_options.token;
150
+ existingAccessory.context.key = deviceConfig.advanced_options.key;
151
+ device.setCredentials(Buffer.from(existingAccessory.context.token, 'hex'), Buffer.from(existingAccessory.context.key, 'hex'));
152
+ }
153
+ else {
154
+ // use token/key values from the accessory cached context
155
+ this.log.info(`[${device_info.name}] Cached device, using saved credentials`);
156
+ device.setCredentials(Buffer.from(existingAccessory.context.token, 'hex'), Buffer.from(existingAccessory.context.key, 'hex'));
157
+ }
158
+ }
159
+ await device.connect(true);
160
+ AccessoryFactory_1.default.createAccessory(this, existingAccessory, device, deviceConfig);
161
+ }
162
+ catch (err) {
163
+ const msg = err instanceof Error ? err.stack : err;
164
+ this.log.error(`Cannot connect to device from cache ${device_info.ip}:${device_info.port}, error:\n${msg}`);
165
+ }
166
+ }
167
+ else {
168
+ try {
169
+ this.log.info('Adding new accessory:', device_info.name);
170
+ const accessory = new this.api.platformAccessory(device_info.name, uuid);
171
+ // Token/key is only required for V3 devices
172
+ if (device_info.version === MideaConstants_1.ProtocolVersion.V3) {
173
+ if (deviceConfig.advanced_options.token && deviceConfig.advanced_options.key) {
174
+ // token/key provided in config file, use those... set values in cached context
175
+ this.log.info(`[${device_info.name}] New device at ${device_info.ip}:${device_info.port}, using token/key from config file`);
176
+ accessory.context.token = deviceConfig.advanced_options.token;
177
+ accessory.context.key = deviceConfig.advanced_options.key;
178
+ accessory.context.id = device_info.id.toString();
179
+ device.setCredentials(Buffer.from(accessory.context.token, 'hex'), Buffer.from(accessory.context.key, 'hex'));
180
+ }
181
+ else {
182
+ throw new Error(`Token/key not provided in config file, cannot add new device`);
183
+ }
184
+ }
185
+ await device.connect(false);
186
+ await device.refresh_status();
187
+ // Set serial number and model into the context if they are provided.
188
+ accessory.context.sn = (_a = device_info.sn) !== null && _a !== void 0 ? _a : 'unknown';
189
+ accessory.context.model = (_b = device_info.model) !== null && _b !== void 0 ? _b : 'unknown';
190
+ // create the accessory handler for the newly create accessory
191
+ // this is imported from `platformAccessory.ts`
192
+ AccessoryFactory_1.default.createAccessory(this, accessory, device, deviceConfig);
193
+ // link the accessory to your platform
194
+ this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]);
195
+ }
196
+ catch (err) {
197
197
  this.log.error(`[${device_info.name} | ${device_info.ip}:${device_info.port}}]
198
- Cannot add new device ${device_info.ip}:${device_info.port}, error:\n${err}`);
199
- }
200
- }
201
- }
202
- }
203
- /**
204
- * This function is invoked when homebridge restores cached accessories from disk at startup.
205
- * It should be used to setup event handlers for characteristics and update respective values.
206
- */
207
- configureAccessory(accessory) {
208
- this.log.info('Loading accessory from cache:', accessory.displayName);
209
- // add the restored accessory to the accessories cache so we can track if it has already been registered
210
- this.accessories.push(accessory);
211
- }
212
- }
213
- exports.MideaPlatform = MideaPlatform;
198
+ Cannot add new device ${device_info.ip}:${device_info.port}, error:\n${err}`);
199
+ }
200
+ }
201
+ }
202
+ }
203
+ /**
204
+ * This function is invoked when homebridge restores cached accessories from disk at startup.
205
+ * It should be used to setup event handlers for characteristics and update respective values.
206
+ */
207
+ configureAccessory(accessory) {
208
+ this.log.info('Loading accessory from cache:', accessory.displayName);
209
+ // add the restored accessory to the accessories cache so we can track if it has already been registered
210
+ this.accessories.push(accessory);
211
+ }
212
+ }
213
+ exports.MideaPlatform = MideaPlatform;
214
214
  //# sourceMappingURL=platform.js.map
@@ -1,107 +1,109 @@
1
- export type Config = {
2
- refreshInterval: number;
3
- heartbeatInterval: number;
4
- verbose: boolean;
5
- logRecoverableErrors: boolean;
6
- uiDebug: boolean;
7
- devices: DeviceConfig[];
8
- };
9
- export declare const defaultConfig: Config;
10
- export type DeviceConfig = {
11
- name?: string;
12
- id: number;
13
- type: string;
14
- advanced_options: {
15
- ip: string;
16
- token: string;
17
- key: string;
18
- verbose: boolean;
19
- logRecoverableErrors: boolean;
20
- registerIfOffline: boolean;
21
- };
22
- AC_options: ACOptions;
23
- A1_options: A1Options;
24
- DB_options: DBOptions;
25
- E1_options: E1Options;
26
- E2_options: E2Options;
27
- E3_options: E3Options;
28
- FA_options: FAOptions;
29
- };
30
- export declare enum SwingMode {
31
- NONE = "None",
32
- VERTICAL = "Vertical",
33
- HORIZONTAL = "Horizontal",
34
- BOTH = "Both"
35
- }
36
- export declare enum SwingAngle {
37
- VERTICAL = "Vertical",
38
- HORIZONTAL = "Horizontal"
39
- }
40
- export declare enum WaterTankSensor {
41
- NONE = "None",
42
- LEAK_SENSOR = "Leak Sensor",
43
- CONTACT_SENSOR = "Contact Sensor"
44
- }
45
- type ACOptions = {
46
- swing: {
47
- mode: SwingMode;
48
- angleAccessory: boolean;
49
- angleMainControl: SwingAngle;
50
- };
51
- heatingCapable: boolean;
52
- ecoSwitch: boolean;
53
- displaySwitch: {
54
- flag: boolean;
55
- command: boolean;
56
- };
57
- minTemp: number;
58
- maxTemp: number;
59
- tempStep: number;
60
- fahrenheit: boolean;
61
- fanOnlyModeSwitch: boolean;
62
- fanAccessory: boolean;
63
- breezeAwaySwitch: boolean;
64
- dryModeSwitch: boolean;
65
- boostModeSwitch: boolean;
66
- auxHeatingSwitches: boolean;
67
- selfCleanSwitch: boolean;
68
- outDoorTemp: boolean;
69
- audioFeedback: boolean;
70
- screenOff: boolean;
71
- };
72
- type A1Options = {
73
- temperatureSensor: boolean;
74
- fanAccessory: boolean;
75
- humiditySensor: boolean;
76
- pumpSwitch: boolean;
77
- waterTankSensor: WaterTankSensor;
78
- minHumidity: number;
79
- maxHumidity: number;
80
- humidityStep: number;
81
- humidityOffset: number;
82
- };
83
- type DBOptions = unknown;
84
- type E1Options = unknown;
85
- type E2Options = {
86
- protocol: string;
87
- minTemp: number;
88
- maxTemp: number;
89
- tempStep: number;
90
- variableHeatingSwitch: boolean;
91
- wholeTankHeatingSwitch: boolean;
92
- };
93
- type E3Options = {
94
- precisionHalves: boolean;
95
- minTemp: number;
96
- maxTemp: number;
97
- tempStep: number;
98
- burningStateSensor: boolean;
99
- protectionSensor: boolean;
100
- zeroColdWaterSwitch: boolean;
101
- zeroColdPulseSwitch: boolean;
102
- smartVolumeSwitch: boolean;
103
- };
104
- type FAOptions = unknown;
105
- export declare const defaultDeviceConfig: DeviceConfig;
106
- export {};
1
+ export type Config = {
2
+ refreshInterval: number;
3
+ heartbeatInterval: number;
4
+ verbose: boolean;
5
+ logRecoverableErrors: boolean;
6
+ uiDebug: boolean;
7
+ devices: DeviceConfig[];
8
+ };
9
+ export declare const defaultConfig: Config;
10
+ export type DeviceConfig = {
11
+ name?: string;
12
+ id: number;
13
+ type: string;
14
+ advanced_options: {
15
+ ip: string;
16
+ token: string;
17
+ key: string;
18
+ verbose: boolean;
19
+ logRecoverableErrors: boolean;
20
+ registerIfOffline: boolean;
21
+ };
22
+ AC_options: ACOptions;
23
+ A1_options: A1Options;
24
+ DB_options: DBOptions;
25
+ E1_options: E1Options;
26
+ E2_options: E2Options;
27
+ E3_options: E3Options;
28
+ FA_options: FAOptions;
29
+ };
30
+ export declare enum SwingMode {
31
+ NONE = "None",
32
+ VERTICAL = "Vertical",
33
+ HORIZONTAL = "Horizontal",
34
+ BOTH = "Both"
35
+ }
36
+ export declare enum SwingAngle {
37
+ VERTICAL = "Vertical",
38
+ HORIZONTAL = "Horizontal"
39
+ }
40
+ export declare enum WaterTankSensor {
41
+ NONE = "None",
42
+ LEAK_SENSOR = "Leak Sensor",
43
+ CONTACT_SENSOR = "Contact Sensor"
44
+ }
45
+ type ACOptions = {
46
+ swing: {
47
+ mode: SwingMode;
48
+ angleAccessory: boolean;
49
+ angleMainControl: SwingAngle;
50
+ };
51
+ heatingCapable: boolean;
52
+ ecoSwitch: boolean;
53
+ displaySwitch: {
54
+ flag: boolean;
55
+ command: boolean;
56
+ };
57
+ minTemp: number;
58
+ maxTemp: number;
59
+ tempStep: number;
60
+ fahrenheit: boolean;
61
+ fanOnlyModeSwitch: boolean;
62
+ fanAccessory: boolean;
63
+ breezeAwaySwitch: boolean;
64
+ dryModeSwitch: boolean;
65
+ boostModeSwitch: boolean;
66
+ auxHeatingSwitches: boolean;
67
+ selfCleanSwitch: boolean;
68
+ ionSwitch: boolean;
69
+ rateSelector: boolean;
70
+ outDoorTemp: boolean;
71
+ audioFeedback: boolean;
72
+ screenOff: boolean;
73
+ };
74
+ type A1Options = {
75
+ temperatureSensor: boolean;
76
+ fanAccessory: boolean;
77
+ humiditySensor: boolean;
78
+ pumpSwitch: boolean;
79
+ waterTankSensor: WaterTankSensor;
80
+ minHumidity: number;
81
+ maxHumidity: number;
82
+ humidityStep: number;
83
+ humidityOffset: number;
84
+ };
85
+ type DBOptions = unknown;
86
+ type E1Options = unknown;
87
+ type E2Options = {
88
+ protocol: string;
89
+ minTemp: number;
90
+ maxTemp: number;
91
+ tempStep: number;
92
+ variableHeatingSwitch: boolean;
93
+ wholeTankHeatingSwitch: boolean;
94
+ };
95
+ type E3Options = {
96
+ precisionHalves: boolean;
97
+ minTemp: number;
98
+ maxTemp: number;
99
+ tempStep: number;
100
+ burningStateSensor: boolean;
101
+ protectionSensor: boolean;
102
+ zeroColdWaterSwitch: boolean;
103
+ zeroColdPulseSwitch: boolean;
104
+ smartVolumeSwitch: boolean;
105
+ };
106
+ type FAOptions = unknown;
107
+ export declare const defaultDeviceConfig: DeviceConfig;
108
+ export {};
107
109
  //# sourceMappingURL=platformUtils.d.ts.map