homebridge-lg-thinq-2 2.0.4 → 2.0.6
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/CHANGELOG.md +29 -0
- package/README.md +1 -0
- package/dist/baseDevice.js +7 -1
- package/dist/devices/AirConditioner.js +23 -8
- package/dist/lib/API.js +22 -2
- package/dist/lib/mqttCertificate.js +12 -2
- package/dist/platformConfig.js +7 -2
- package/package.json +8 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## v2.0.6
|
|
4
|
+
|
|
5
|
+
### Reliability
|
|
6
|
+
|
|
7
|
+
* The default refresh interval is now 60 seconds, matching `config.schema.json`, instead of 5 seconds. The plugin asked LG for the full device list every 5 seconds as a fallback to MQTT, and LG now answers that with HTTP 429 (result code `9012`, "Please consider using the official API"). Invalid or zero values also fall back to 60 seconds. From [nVuln/homebridge-lg-thinq#395](https://github.com/nVuln/homebridge-lg-thinq/pull/395) by Frank Aune, fixing [nVuln/homebridge-lg-thinq#385](https://github.com/nVuln/homebridge-lg-thinq/issues/385).
|
|
8
|
+
* ThinQ1 devices, which only get updates from this refresh, now update every 60 seconds unless `refresh_interval` is set in the config.
|
|
9
|
+
* Documented the `refresh_interval` option in the README. The Homebridge UI does not show it, so it is set by editing the config JSON.
|
|
10
|
+
|
|
11
|
+
## v2.0.5
|
|
12
|
+
|
|
13
|
+
Fixes from [nVuln/homebridge-lg-thinq#401](https://github.com/nVuln/homebridge-lg-thinq/pull/401) by Vojtech Knyttl, which was never merged in the original repository.
|
|
14
|
+
|
|
15
|
+
### Air Conditioner
|
|
16
|
+
|
|
17
|
+
* The fan speed control now uses LG's own 5 speeds (HomeKit values 1 to 5) instead of a 0 to 100 percentage. With the percentage, most slider positions mapped to the speed the AC was already using, so the control seemed stuck and snapped back. Now every position selects a different speed. HomeKit speed 0 selects the lowest speed, because turning the AC off is a separate control.
|
|
18
|
+
|
|
19
|
+
### Devices
|
|
20
|
+
|
|
21
|
+
* The accessory name shown in HomeKit now follows the device name. Before, a device renamed in the ThinQ app or in the plugin config kept showing its old name in the Home app.
|
|
22
|
+
|
|
23
|
+
### Logging and Reliability
|
|
24
|
+
|
|
25
|
+
* Commands that a device rejects as not supported (ThinQ result codes `0101` and `9006`), such as the AC temperature keep-alive on some models, are now logged at debug level instead of as errors, which flooded the log every few minutes ([nVuln/homebridge-lg-thinq#391](https://github.com/nVuln/homebridge-lg-thinq/issues/391)).
|
|
26
|
+
* When ThinQ does not return an MQTT certificate, the plugin now logs a clear error and retries, instead of failing with `Cannot read properties of undefined (reading 'certificatePem')`.
|
|
27
|
+
|
|
28
|
+
### Dependencies
|
|
29
|
+
|
|
30
|
+
* Cleared all known vulnerabilities in the published package's dependencies (`npm audit --omit=dev` reports 0, was 9): `node-forge` 1.4.3, `qs` 6.17.1, and overrides for `ws` 8.23.0, `glob` 14.0.6, and `brace-expansion` 5.0.13. `ws` is forced to 8.x for `aws-iot-device-sdk` and `mqtt`, which pin a vulnerable 7.x; the plugin connects to MQTT over TLS, not websockets, and was verified to still connect.
|
|
31
|
+
|
|
3
32
|
## v2.0.4
|
|
4
33
|
|
|
5
34
|
### Dependencies
|
package/README.md
CHANGED
|
@@ -107,6 +107,7 @@ To enable or configure only specific devices, list them by device id:
|
|
|
107
107
|
| `language` | Yes | LG account language code, for example `en-US`. |
|
|
108
108
|
| `devices` | No | Empty or omitted enables all supported discovered devices. |
|
|
109
109
|
| `thinq1` | No | Advanced legacy option. Set to `true` manually to enable ThinQ1 devices. |
|
|
110
|
+
| `refresh_interval` | No | Seconds between device status refreshes from LG. Default `60`. ThinQ2 devices also get instant updates over MQTT, so this is only a fallback for them; ThinQ1 devices are updated only by this refresh. Low values can make LG reject requests with HTTP 429 (too many requests). |
|
|
110
111
|
|
|
111
112
|
Device type is detected from LG discovery data. Device-specific settings appear in the Homebridge UI after devices have been discovered.
|
|
112
113
|
|
package/dist/baseDevice.js
CHANGED
|
@@ -18,7 +18,13 @@ export class BaseDevice extends EventEmitter {
|
|
|
18
18
|
serviceAccessoryInformation
|
|
19
19
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'LG')
|
|
20
20
|
.setCharacteristic(this.platform.Characteristic.Model, device.salesModel || device.model || 'Unknown')
|
|
21
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, this.config.serial_number || device.serialNumber || 'Unknown')
|
|
21
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, this.config.serial_number || device.serialNumber || 'Unknown')
|
|
22
|
+
// Keep the accessory-information name in sync with the device name. This
|
|
23
|
+
// characteristic is what controllers show as the accessory's identity, and
|
|
24
|
+
// it is restored from the accessory cache - so without this a device that
|
|
25
|
+
// was renamed in the ThinQ app keeps displaying its old name indefinitely,
|
|
26
|
+
// even though the accessory's displayName and its other services update.
|
|
27
|
+
.setCharacteristic(this.platform.Characteristic.Name, device.name);
|
|
22
28
|
}
|
|
23
29
|
updateAccessoryCharacteristic(device) {
|
|
24
30
|
this.accessory.context.device = device;
|
|
@@ -19,10 +19,22 @@ export var FanSpeed;
|
|
|
19
19
|
FanSpeed[FanSpeed["MEDIUM_HIGH"] = 5] = "MEDIUM_HIGH";
|
|
20
20
|
FanSpeed[FanSpeed["HIGH"] = 6] = "HIGH";
|
|
21
21
|
})(FanSpeed || (FanSpeed = {}));
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
// The LG fan has a small number of discrete steps (LOW..HIGH), so RotationSpeed
|
|
23
|
+
// is exposed as a step count rather than a 0-100 percentage: HomeKit speed N maps
|
|
24
|
+
// to the Nth LG step. A percentage scale collapses many slider positions onto the
|
|
25
|
+
// same windStrength, which makes the control send the speed the unit is already
|
|
26
|
+
// at and then snap back to the quantised readback.
|
|
27
|
+
const LG_FAN_SPEEDS = [
|
|
28
|
+
FanSpeed.LOW,
|
|
29
|
+
FanSpeed.LOW_MEDIUM,
|
|
30
|
+
FanSpeed.MEDIUM,
|
|
31
|
+
FanSpeed.MEDIUM_HIGH,
|
|
32
|
+
FanSpeed.HIGH,
|
|
33
|
+
];
|
|
34
|
+
const HOMEKIT_FAN_SPEED_MAX = LG_FAN_SPEEDS.length;
|
|
35
|
+
// Automatic (or unrecognised) fan speed has no step of its own; report the top of
|
|
36
|
+
// the range, matching the behaviour this plugin has always had.
|
|
37
|
+
const HOMEKIT_FAN_SPEED_DEFAULT = HOMEKIT_FAN_SPEED_MAX;
|
|
26
38
|
var OpMode;
|
|
27
39
|
(function (OpMode) {
|
|
28
40
|
OpMode[OpMode["AUTO"] = 6] = "AUTO";
|
|
@@ -95,8 +107,9 @@ function readWindStrength(data) {
|
|
|
95
107
|
if (num === FAN_SPEED_AUTO) {
|
|
96
108
|
return HOMEKIT_FAN_SPEED_DEFAULT;
|
|
97
109
|
}
|
|
98
|
-
|
|
99
|
-
|
|
110
|
+
const step = LG_FAN_SPEEDS.indexOf(num);
|
|
111
|
+
if (step !== -1) {
|
|
112
|
+
return step + 1;
|
|
100
113
|
}
|
|
101
114
|
}
|
|
102
115
|
return HOMEKIT_FAN_SPEED_DEFAULT;
|
|
@@ -288,8 +301,10 @@ export function windStrengthFromRotationSpeed(value) {
|
|
|
288
301
|
if (vNum === null) {
|
|
289
302
|
return null;
|
|
290
303
|
}
|
|
291
|
-
|
|
292
|
-
|
|
304
|
+
// Speed 0 means "off" in HomeKit, but the AC has no off fan step - treat it as
|
|
305
|
+
// the slowest speed, as turning the unit off is a separate characteristic.
|
|
306
|
+
const step = Math.min(HOMEKIT_FAN_SPEED_MAX, Math.max(1, Math.round(vNum)));
|
|
307
|
+
return LG_FAN_SPEEDS[step - 1];
|
|
293
308
|
}
|
|
294
309
|
export function swingCommandsForMode(value, swingMode) {
|
|
295
310
|
if (!isSwingModeEnabled(swingMode)) {
|
package/dist/lib/API.js
CHANGED
|
@@ -8,6 +8,16 @@ import { ManualProcessNeeded, MonitorError, NotConnectedError, TokenExpiredError
|
|
|
8
8
|
import crypto from 'crypto';
|
|
9
9
|
import axios from 'axios';
|
|
10
10
|
import { createNoopLogger } from './noopLogger.js';
|
|
11
|
+
/**
|
|
12
|
+
* ThinQ result codes returned for commands a device simply does not support
|
|
13
|
+
* (for example the AC temperature keep-alive on models that reject it). The
|
|
14
|
+
* calling code already treats these as a non-fatal "not supported", so they are
|
|
15
|
+
* logged at debug level instead of error to avoid flooding the log. (#391)
|
|
16
|
+
*/
|
|
17
|
+
const BENIGN_REQUEST_RESULT_CODES = new Set([
|
|
18
|
+
'0101', // command not supported by device
|
|
19
|
+
'9006', // device rejected the (optional) command
|
|
20
|
+
]);
|
|
11
21
|
/**
|
|
12
22
|
* The `API` class provides methods to interact with the LG ThinQ API, enabling
|
|
13
23
|
* device management, home management, and command execution. It handles
|
|
@@ -133,8 +143,18 @@ export class API {
|
|
|
133
143
|
throw err;
|
|
134
144
|
}
|
|
135
145
|
if (axios.isAxiosError(err)) {
|
|
136
|
-
|
|
137
|
-
|
|
146
|
+
const resultCode = err.response?.data?.resultCode;
|
|
147
|
+
// Some device models reject optional commands - e.g. the AC
|
|
148
|
+
// temperature keep-alive (`allEventEnable` / `airState.mon.timeout`) -
|
|
149
|
+
// with a benign result code. These failures are already handled by the
|
|
150
|
+
// caller, so logging them at error level only floods the log. (#391)
|
|
151
|
+
if (resultCode !== undefined && BENIGN_REQUEST_RESULT_CODES.has(resultCode)) {
|
|
152
|
+
this.logger.debug('request rejected by device (resultCode ' + resultCode + '): ', err.response?.data, data);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
this.logger.error('axios request error: ', err.response?.data, data);
|
|
156
|
+
this.logger.error(err.stack || 'No stack error');
|
|
157
|
+
}
|
|
138
158
|
}
|
|
139
159
|
else {
|
|
140
160
|
this.logger.error('request error: ', err);
|
|
@@ -48,9 +48,19 @@ export function createMqttCsr(keys) {
|
|
|
48
48
|
}
|
|
49
49
|
export async function requestMqttCertificate(api, csr) {
|
|
50
50
|
await api.postRequest(MQTT_CLIENT_PATH, {});
|
|
51
|
-
|
|
51
|
+
const response = await api.postRequest(MQTT_CERTIFICATE_PATH, {
|
|
52
52
|
csr: certificateRequestBody(csr),
|
|
53
|
-
})
|
|
53
|
+
});
|
|
54
|
+
const certificate = response?.result;
|
|
55
|
+
// `API.request` resolves to `{}` when the ThinQ API returns an error, so
|
|
56
|
+
// `result` (and therefore the certificate) can be missing. Fail with an
|
|
57
|
+
// actionable message instead of letting a downstream read of
|
|
58
|
+
// `certificate.certificatePem` throw a cryptic TypeError, which previously
|
|
59
|
+
// surfaced as an unhandled rejection on MQTT reconnect. (#391)
|
|
60
|
+
if (!certificate || typeof certificate.certificatePem !== 'string') {
|
|
61
|
+
throw new Error('ThinQ did not return an MQTT certificate; skipping this connection attempt.');
|
|
62
|
+
}
|
|
63
|
+
return certificate;
|
|
54
64
|
}
|
|
55
65
|
export async function loadMqttConnectionSetup(options) {
|
|
56
66
|
const { api, persist, logger, createKeys = generateMqttKeyPair, createCsr = createMqttCsr, } = options;
|
package/dist/platformConfig.js
CHANGED
|
@@ -8,9 +8,14 @@ export function hasRequiredThinQConfig(config) {
|
|
|
8
8
|
export function isThinQ1Enabled(config) {
|
|
9
9
|
return config.thinq1 === true;
|
|
10
10
|
}
|
|
11
|
+
// Matches the `refresh_interval` default declared in config.schema.json. ThinQ2
|
|
12
|
+
// devices receive real-time updates over MQTT, so polling is only a fallback and
|
|
13
|
+
// must not run aggressively or LG's API returns HTTP 429 (too many requests).
|
|
14
|
+
export const DEFAULT_REFRESH_INTERVAL_SECONDS = 60;
|
|
11
15
|
export function refreshIntervalMs(config) {
|
|
12
|
-
const seconds = Number(config.refresh_interval ??
|
|
13
|
-
|
|
16
|
+
const seconds = Number(config.refresh_interval ?? DEFAULT_REFRESH_INTERVAL_SECONDS);
|
|
17
|
+
const safeSeconds = Number.isFinite(seconds) && seconds > 0 ? seconds : DEFAULT_REFRESH_INTERVAL_SECONDS;
|
|
18
|
+
return safeSeconds * 1000;
|
|
14
19
|
}
|
|
15
20
|
export function isDeviceEnabled(config, device) {
|
|
16
21
|
const devices = configuredDevices(config);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "Homebridge LG ThinQ 2",
|
|
3
3
|
"name": "homebridge-lg-thinq-2",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.6",
|
|
5
5
|
"description": "Community-maintained continuation of homebridge-lg-thinq: a Homebridge plugin for controlling/monitoring LG ThinQ devices via the LG ThinQ platform.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"type": "module",
|
|
@@ -80,15 +80,17 @@
|
|
|
80
80
|
"axios-retry": "^4.5.0",
|
|
81
81
|
"commander": "^14.0.3",
|
|
82
82
|
"luxon": "^3.7.2",
|
|
83
|
-
"node-forge": "^1.4.
|
|
83
|
+
"node-forge": "^1.4.3",
|
|
84
84
|
"node-persist": "^4.0.4",
|
|
85
|
-
"qs": "^6.
|
|
85
|
+
"qs": "^6.17.1"
|
|
86
86
|
},
|
|
87
87
|
"overrides": {
|
|
88
|
-
"glob": "^
|
|
88
|
+
"glob": "^14.0.6",
|
|
89
89
|
"help-me": {
|
|
90
|
-
"glob": "^
|
|
90
|
+
"glob": "^14.0.6"
|
|
91
91
|
},
|
|
92
|
-
"node-persist": "^4.0.4"
|
|
92
|
+
"node-persist": "^4.0.4",
|
|
93
|
+
"brace-expansion": "^5.0.13",
|
|
94
|
+
"ws": "^8.23.0"
|
|
93
95
|
}
|
|
94
96
|
}
|