iobroker.mg-saic 0.2.0 → 0.3.0
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/README.md +7 -7
- package/build/command-feedback.js +104 -0
- package/build/command-feedback.js.map +7 -0
- package/build/main.js +161 -0
- package/build/main.js.map +2 -2
- package/build/runtime-translations.js +78 -0
- package/build/runtime-translations.js.map +2 -2
- package/io-package.json +14 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ For manufacturer information, see [MG Motor](https://www.mgmotor.eu/) and [SAIC
|
|
|
28
28
|
2. Select the account region, login type (email or phone number), and the matching custom Login/Password credential from the credential store. The credential's login must be the iSmart email address or phone number; the password is stored centrally. For phone login, also enter the phone country calling code in the adapter settings.
|
|
29
29
|
3. Set the status polling interval to 60 seconds or more. The default is 1800 seconds.
|
|
30
30
|
4. Save the settings and start the instance. Vehicles available to the account appear under `vehicles.<VIN>`.
|
|
31
|
-
Existing vehicle object IDs are reused if the cloud API changes the VIN casing. Device labels use the localized generic vehicle name; the VIN, brand, model, and other available vehicle metadata are provided as read-only states.
|
|
31
|
+
Existing vehicle object IDs are reused if the cloud API changes the VIN casing. Device labels use the localized generic vehicle name; the VIN, brand, model, and other available vehicle metadata are provided as read-only states. The read-only text state `vehicles.<VIN>.commands.lastCommand` reports the SAIC API's response to the most recent command or action. The matching boolean state `vehicles.<VIN>.commands.lastCommandSucceeded` is `true` when the API accepts the request and returns a successful result; it is `false` while a request is in progress or after an API failure. The last result is retained across adapter restarts. This reflects SAIC's API response and does not independently verify that the vehicle physically completed the action. If the adapter stops before recording a response, startup marks the request as interrupted with an unknown outcome and sets `lastCommandSucceeded` to `false`.
|
|
32
32
|
|
|
33
33
|
The adapter does not import previously saved native login or password values. On startup it clears those deprecated fields; configure a central Login/Password credential before the adapter can connect.
|
|
34
34
|
|
|
@@ -36,12 +36,13 @@ The adapter does not import previously saved native login or password values. On
|
|
|
36
36
|
|
|
37
37
|
- Connects ioBroker to the iSmart cloud service and retrieves vehicle status.
|
|
38
38
|
- Provides remote controls for supported vehicle functions.
|
|
39
|
+
- Reports whether the SAIC API accepted remote commands, settings actions, and seat-heating changes and returned a successful result. Each vehicle's read-only `commands.lastCommand` text state describes the API response, while `commands.lastCommandSucceeded` is `true` on API success and `false` while the request is pending or after failure, or when an interrupted request has an unknown outcome. This is confirmation from SAIC's API and does not independently verify physical completion by the vehicle.
|
|
39
40
|
- Supports climate, heating, and charging features where available for the vehicle.
|
|
40
41
|
- Omits unrecognized free-form charging text while retaining numeric measurements and validated charging-point identifiers.
|
|
41
42
|
|
|
42
43
|
## Installation
|
|
43
44
|
|
|
44
|
-
The adapter is published on npm and available from ioBroker's
|
|
45
|
+
The adapter is published on npm and available from ioBroker's Stable adapter repository.
|
|
45
46
|
|
|
46
47
|
## Support
|
|
47
48
|
|
|
@@ -51,6 +52,10 @@ The adapter is published on npm and available from ioBroker's Latest adapter rep
|
|
|
51
52
|
|
|
52
53
|
## Changelog
|
|
53
54
|
|
|
55
|
+
### 0.3.0 (2026-11-28)
|
|
56
|
+
|
|
57
|
+
- (Voodoo2man) Reported SAIC API acceptance and success results for commands through text and boolean feedback states.
|
|
58
|
+
|
|
54
59
|
### 0.2.0 (2026-11-28)
|
|
55
60
|
|
|
56
61
|
- (Voodoo2man) Moved iSmart credentials to ioBroker's credential store; existing users must create a new Login/Password credential and re-enter their login details.
|
|
@@ -69,11 +74,6 @@ The adapter is published on npm and available from ioBroker's Latest adapter rep
|
|
|
69
74
|
- (Voodoo2man) Replaced untrusted cloud error text with English code-based diagnostics and standardized the product title as MG/SAIC across locales.
|
|
70
75
|
- (Voodoo2man) Reused dynamic charging datapoints across field-name casing changes and normalized known status fields.
|
|
71
76
|
|
|
72
|
-
### 0.1.1 (2026-11-07)
|
|
73
|
-
|
|
74
|
-
- (Voodoo2man) Lowered the minimum Node.js requirement to 22.22.2.
|
|
75
|
-
- (Voodoo2man) Improved charging datapoint labels and units, enforced safe polling interval limits, and added manufacturer references.
|
|
76
|
-
|
|
77
77
|
Older changelog entries are available in [CHANGELOG_OLD.md](CHANGELOG_OLD.md).
|
|
78
78
|
|
|
79
79
|
## License
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var command_feedback_exports = {};
|
|
20
|
+
__export(command_feedback_exports, {
|
|
21
|
+
CommandFeedbackSequence: () => CommandFeedbackSequence,
|
|
22
|
+
findInProgressCommandFeedback: () => findInProgressCommandFeedback,
|
|
23
|
+
formatCommandFeedback: () => formatCommandFeedback,
|
|
24
|
+
isCommandSuccessful: () => isCommandSuccessful
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(command_feedback_exports);
|
|
27
|
+
var import_runtime_translations = require("./runtime-translations");
|
|
28
|
+
const feedbackTranslationKeys = {
|
|
29
|
+
inProgress: "commandFeedbackInProgress",
|
|
30
|
+
apiConfirmed: "commandFeedbackApiConfirmed",
|
|
31
|
+
failed: "commandFeedbackFailed",
|
|
32
|
+
interrupted: "commandFeedbackInterrupted"
|
|
33
|
+
};
|
|
34
|
+
const commandSucceeded = {
|
|
35
|
+
inProgress: false,
|
|
36
|
+
apiConfirmed: true,
|
|
37
|
+
failed: false,
|
|
38
|
+
interrupted: false
|
|
39
|
+
};
|
|
40
|
+
class CommandFeedbackSequence {
|
|
41
|
+
currentAttemptByVehicle = /* @__PURE__ */ new Map();
|
|
42
|
+
pendingWritesByVehicle = /* @__PURE__ */ new Map();
|
|
43
|
+
/**
|
|
44
|
+
* Starts a new feedback generation for a vehicle.
|
|
45
|
+
*
|
|
46
|
+
* @param vin Vehicle identifier.
|
|
47
|
+
*/
|
|
48
|
+
beginAttempt(vin) {
|
|
49
|
+
var _a;
|
|
50
|
+
const key = vin.toLowerCase();
|
|
51
|
+
const attempt = ((_a = this.currentAttemptByVehicle.get(key)) != null ? _a : 0) + 1;
|
|
52
|
+
this.currentAttemptByVehicle.set(key, attempt);
|
|
53
|
+
return attempt;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Serializes state writes and skips feedback from superseded attempts.
|
|
57
|
+
*
|
|
58
|
+
* @param vin Vehicle identifier.
|
|
59
|
+
* @param attempt Generation returned by {@link beginAttempt}.
|
|
60
|
+
* @param write Asynchronous state-write operation.
|
|
61
|
+
*/
|
|
62
|
+
writeIfCurrent(vin, attempt, write) {
|
|
63
|
+
var _a;
|
|
64
|
+
const key = vin.toLowerCase();
|
|
65
|
+
const previous = (_a = this.pendingWritesByVehicle.get(key)) != null ? _a : Promise.resolve();
|
|
66
|
+
const next = previous.catch(() => void 0).then(async () => {
|
|
67
|
+
if (this.currentAttemptByVehicle.get(key) === attempt) {
|
|
68
|
+
await write();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
this.pendingWritesByVehicle.set(key, next);
|
|
72
|
+
return next;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function isCommandSuccessful(status) {
|
|
76
|
+
return commandSucceeded[status];
|
|
77
|
+
}
|
|
78
|
+
function formatCommandFeedback(commandId, status, language) {
|
|
79
|
+
var _a;
|
|
80
|
+
const selectedLanguage = (_a = import_runtime_translations.supportedLanguages.find((item) => item === language)) != null ? _a : "en";
|
|
81
|
+
const commandName = (0, import_runtime_translations.getRuntimeName)(commandId)[selectedLanguage];
|
|
82
|
+
return (0, import_runtime_translations.getRuntimeName)(feedbackTranslationKeys[status])[selectedLanguage].replace("%s", commandName);
|
|
83
|
+
}
|
|
84
|
+
function findInProgressCommandFeedback(feedbackValue, commandIds) {
|
|
85
|
+
if (typeof feedbackValue !== "string") {
|
|
86
|
+
return void 0;
|
|
87
|
+
}
|
|
88
|
+
for (const commandId of commandIds) {
|
|
89
|
+
if (import_runtime_translations.supportedLanguages.some(
|
|
90
|
+
(language) => formatCommandFeedback(commandId, "inProgress", language) === feedbackValue
|
|
91
|
+
)) {
|
|
92
|
+
return commandId;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
CommandFeedbackSequence,
|
|
100
|
+
findInProgressCommandFeedback,
|
|
101
|
+
formatCommandFeedback,
|
|
102
|
+
isCommandSuccessful
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=command-feedback.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/command-feedback.ts"],
|
|
4
|
+
"sourcesContent": ["import { getRuntimeName, supportedLanguages, type SupportedLanguage } from './runtime-translations';\n\nexport type CommandFeedbackStatus = 'inProgress' | 'apiConfirmed' | 'failed' | 'interrupted';\n\nconst feedbackTranslationKeys: Record<CommandFeedbackStatus, string> = {\n\tinProgress: 'commandFeedbackInProgress',\n\tapiConfirmed: 'commandFeedbackApiConfirmed',\n\tfailed: 'commandFeedbackFailed',\n\tinterrupted: 'commandFeedbackInterrupted',\n};\n\nconst commandSucceeded: Record<CommandFeedbackStatus, boolean> = {\n\tinProgress: false,\n\tapiConfirmed: true,\n\tfailed: false,\n\tinterrupted: false,\n};\n\n/** Tracks and serializes per-vehicle command feedback attempts. */\nexport class CommandFeedbackSequence {\n\tprivate readonly currentAttemptByVehicle = new Map<string, number>();\n\tprivate readonly pendingWritesByVehicle = new Map<string, Promise<void>>();\n\n\t/**\n\t * Starts a new feedback generation for a vehicle.\n\t *\n\t * @param vin Vehicle identifier.\n\t */\n\tpublic beginAttempt(vin: string): number {\n\t\tconst key = vin.toLowerCase();\n\t\tconst attempt = (this.currentAttemptByVehicle.get(key) ?? 0) + 1;\n\t\tthis.currentAttemptByVehicle.set(key, attempt);\n\t\treturn attempt;\n\t}\n\n\t/**\n\t * Serializes state writes and skips feedback from superseded attempts.\n\t *\n\t * @param vin Vehicle identifier.\n\t * @param attempt Generation returned by {@link beginAttempt}.\n\t * @param write Asynchronous state-write operation.\n\t */\n\tpublic writeIfCurrent(vin: string, attempt: number, write: () => Promise<void>): Promise<void> {\n\t\tconst key = vin.toLowerCase();\n\t\tconst previous = this.pendingWritesByVehicle.get(key) ?? Promise.resolve();\n\t\tconst next = previous\n\t\t\t.catch(() => undefined)\n\t\t\t.then(async () => {\n\t\t\t\tif (this.currentAttemptByVehicle.get(key) === attempt) {\n\t\t\t\t\tawait write();\n\t\t\t\t}\n\t\t\t});\n\t\tthis.pendingWritesByVehicle.set(key, next);\n\t\treturn next;\n\t}\n}\n\n/**\n * Returns whether SAIC confirmed the command API action.\n *\n * @param status Feedback status.\n */\nexport function isCommandSuccessful(status: CommandFeedbackStatus): boolean {\n\treturn commandSucceeded[status];\n}\n\n/**\n * Formats command feedback from trusted translation keys, without including API response content.\n *\n * @param commandId Runtime translation key for the command or action.\n * @param status Feedback status.\n * @param language Configured ioBroker language.\n */\nexport function formatCommandFeedback(commandId: string, status: CommandFeedbackStatus, language: string): string {\n\tconst selectedLanguage: SupportedLanguage = supportedLanguages.find(item => item === language) ?? 'en';\n\tconst commandName = getRuntimeName(commandId)[selectedLanguage];\n\treturn getRuntimeName(feedbackTranslationKeys[status])[selectedLanguage].replace('%s', commandName);\n}\n\n/**\n * Finds an unfinished feedback value regardless of the language used when it was written.\n *\n * @param feedbackValue Persisted last-command text.\n * @param commandIds Runtime translation keys that can identify a command attempt.\n */\nexport function findInProgressCommandFeedback(\n\tfeedbackValue: unknown,\n\tcommandIds: readonly string[],\n): string | undefined {\n\tif (typeof feedbackValue !== 'string') {\n\t\treturn undefined;\n\t}\n\tfor (const commandId of commandIds) {\n\t\tif (\n\t\t\tsupportedLanguages.some(\n\t\t\t\tlanguage => formatCommandFeedback(commandId, 'inProgress', language) === feedbackValue,\n\t\t\t)\n\t\t) {\n\t\t\treturn commandId;\n\t\t}\n\t}\n\treturn undefined;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAA2E;AAI3E,MAAM,0BAAiE;AAAA,EACtE,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,aAAa;AACd;AAEA,MAAM,mBAA2D;AAAA,EAChE,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,aAAa;AACd;AAGO,MAAM,wBAAwB;AAAA,EACnB,0BAA0B,oBAAI,IAAoB;AAAA,EAClD,yBAAyB,oBAAI,IAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOlE,aAAa,KAAqB;AA5B1C;AA6BE,UAAM,MAAM,IAAI,YAAY;AAC5B,UAAM,YAAW,UAAK,wBAAwB,IAAI,GAAG,MAApC,YAAyC,KAAK;AAC/D,SAAK,wBAAwB,IAAI,KAAK,OAAO;AAC7C,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,eAAe,KAAa,SAAiB,OAA2C;AA1ChG;AA2CE,UAAM,MAAM,IAAI,YAAY;AAC5B,UAAM,YAAW,UAAK,uBAAuB,IAAI,GAAG,MAAnC,YAAwC,QAAQ,QAAQ;AACzE,UAAM,OAAO,SACX,MAAM,MAAM,MAAS,EACrB,KAAK,YAAY;AACjB,UAAI,KAAK,wBAAwB,IAAI,GAAG,MAAM,SAAS;AACtD,cAAM,MAAM;AAAA,MACb;AAAA,IACD,CAAC;AACF,SAAK,uBAAuB,IAAI,KAAK,IAAI;AACzC,WAAO;AAAA,EACR;AACD;AAOO,SAAS,oBAAoB,QAAwC;AAC3E,SAAO,iBAAiB,MAAM;AAC/B;AASO,SAAS,sBAAsB,WAAmB,QAA+B,UAA0B;AAzElH;AA0EC,QAAM,oBAAsC,oDAAmB,KAAK,UAAQ,SAAS,QAAQ,MAAjD,YAAsD;AAClG,QAAM,kBAAc,4CAAe,SAAS,EAAE,gBAAgB;AAC9D,aAAO,4CAAe,wBAAwB,MAAM,CAAC,EAAE,gBAAgB,EAAE,QAAQ,MAAM,WAAW;AACnG;AAQO,SAAS,8BACf,eACA,YACqB;AACrB,MAAI,OAAO,kBAAkB,UAAU;AACtC,WAAO;AAAA,EACR;AACA,aAAW,aAAa,YAAY;AACnC,QACC,+CAAmB;AAAA,MAClB,cAAY,sBAAsB,WAAW,cAAc,QAAQ,MAAM;AAAA,IAC1E,GACC;AACD,aAAO;AAAA,IACR;AAAA,EACD;AACA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/main.js
CHANGED
|
@@ -35,6 +35,7 @@ var import_refresh_poll_timer = require("./refresh-poll-timer");
|
|
|
35
35
|
var import_pending_setting_edits = require("./pending-setting-edits");
|
|
36
36
|
var import_status_metadata = require("./status-metadata");
|
|
37
37
|
var import_runtime_translations = require("./runtime-translations");
|
|
38
|
+
var import_command_feedback = require("./command-feedback");
|
|
38
39
|
var import_vehicle_object_ids = require("./vehicle-object-ids");
|
|
39
40
|
const chargingGroups = [
|
|
40
41
|
{ source: "chrgMgmtData", id: "session", name: "chargingManagement" },
|
|
@@ -111,6 +112,16 @@ const settingInputsByAction = {
|
|
|
111
112
|
chargingScheduleApply: ["chargingScheduleStart", "chargingScheduleEnd", "chargingScheduleMode"],
|
|
112
113
|
batteryHeatingScheduleApply: ["batteryHeatingScheduleEnabled", "batteryHeatingScheduleStart"]
|
|
113
114
|
};
|
|
115
|
+
const commandFeedbackCommandIds = [
|
|
116
|
+
...vehicleCommands.map(({ id }) => id),
|
|
117
|
+
...settingActions.map(({ id }) => id),
|
|
118
|
+
"driverSeatHeatLevel",
|
|
119
|
+
"passengerSeatHeatLevel",
|
|
120
|
+
...["Off", "Low", "Medium", "High"].flatMap((level) => [
|
|
121
|
+
`driverSeatHeat${level}`,
|
|
122
|
+
`passengerSeatHeat${level}`
|
|
123
|
+
])
|
|
124
|
+
];
|
|
114
125
|
const EXPOSE_SOURCE_STATUS_DATAPOINTS = false;
|
|
115
126
|
const PENDING_SETTING_EDITS_FILE = "pending-setting-edits.json";
|
|
116
127
|
class MgSaic extends utils.Adapter {
|
|
@@ -145,14 +156,24 @@ class MgSaic extends utils.Adapter {
|
|
|
145
156
|
lastStatusTimes = /* @__PURE__ */ new Map();
|
|
146
157
|
lastCanonicalStatusTimes = /* @__PURE__ */ new Map();
|
|
147
158
|
vehicleCommandsInProgress = /* @__PURE__ */ new Set();
|
|
159
|
+
commandFeedbackSequence = new import_command_feedback.CommandFeedbackSequence();
|
|
148
160
|
pendingSettingEdits = /* @__PURE__ */ new Map();
|
|
149
161
|
pendingSettingEditsWrite = Promise.resolve();
|
|
150
162
|
settingEditSequence = 0;
|
|
163
|
+
runtimeLanguage = "en";
|
|
151
164
|
async onReady() {
|
|
152
165
|
var _a, _b, _c;
|
|
153
166
|
if (this.stopping) {
|
|
154
167
|
return;
|
|
155
168
|
}
|
|
169
|
+
await this.loadRuntimeLanguage();
|
|
170
|
+
if (this.stopping) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
await this.recoverInterruptedCommandFeedback();
|
|
174
|
+
if (this.stopping) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
156
177
|
const config = this.config;
|
|
157
178
|
await this.extendObjectAsync("info", { common: { name: (0, import_runtime_translations.getRuntimeName)("info") } });
|
|
158
179
|
await this.extendObjectAsync("info.backend", { common: { name: (0, import_runtime_translations.getRuntimeName)("backend") } });
|
|
@@ -577,6 +598,18 @@ class MgSaic extends utils.Adapter {
|
|
|
577
598
|
);
|
|
578
599
|
}
|
|
579
600
|
}
|
|
601
|
+
async loadRuntimeLanguage() {
|
|
602
|
+
var _a;
|
|
603
|
+
try {
|
|
604
|
+
const systemConfig = await this.getForeignObjectAsync("system.config");
|
|
605
|
+
const language = (_a = systemConfig == null ? void 0 : systemConfig.common) == null ? void 0 : _a.language;
|
|
606
|
+
if (typeof language === "string") {
|
|
607
|
+
this.runtimeLanguage = language;
|
|
608
|
+
}
|
|
609
|
+
} catch {
|
|
610
|
+
this.runtimeLanguage = "en";
|
|
611
|
+
}
|
|
612
|
+
}
|
|
580
613
|
onStateChange(id, state) {
|
|
581
614
|
if (this.stopping) {
|
|
582
615
|
return;
|
|
@@ -736,19 +769,94 @@ class MgSaic extends utils.Adapter {
|
|
|
736
769
|
vehicleCommandStatePath(vin, id) {
|
|
737
770
|
return vehicleCommandPath(this.getVehicleObjectId(vin), id);
|
|
738
771
|
}
|
|
772
|
+
async writeCommandFeedbackStates(commandsPath, text, succeeded) {
|
|
773
|
+
const writes = await Promise.allSettled([
|
|
774
|
+
Promise.resolve().then(() => this.setStateAsync(`${commandsPath}.lastCommand`, { val: text, ack: true })),
|
|
775
|
+
Promise.resolve().then(
|
|
776
|
+
() => this.setStateAsync(`${commandsPath}.lastCommandSucceeded`, { val: succeeded, ack: true })
|
|
777
|
+
)
|
|
778
|
+
]);
|
|
779
|
+
const failedWrite = writes.find((write) => write.status === "rejected");
|
|
780
|
+
if ((failedWrite == null ? void 0 : failedWrite.status) === "rejected") {
|
|
781
|
+
throw failedWrite.reason;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
async recoverInterruptedCommandFeedback() {
|
|
785
|
+
const namespacePrefix = `${this.namespace}.`;
|
|
786
|
+
try {
|
|
787
|
+
const objects = await this.getObjectListAsync({
|
|
788
|
+
startkey: `${namespacePrefix}vehicles.`,
|
|
789
|
+
endkey: `${namespacePrefix}vehicles.\u9999`
|
|
790
|
+
});
|
|
791
|
+
for (const row of objects.rows) {
|
|
792
|
+
if (this.stopping) {
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
if (row.value.type !== "state" || !row.id.endsWith(".commands.lastCommand")) {
|
|
796
|
+
continue;
|
|
797
|
+
}
|
|
798
|
+
const stateId = row.id.slice(namespacePrefix.length);
|
|
799
|
+
try {
|
|
800
|
+
const state = await this.getStateAsync(stateId);
|
|
801
|
+
const commandId = (0, import_command_feedback.findInProgressCommandFeedback)(state == null ? void 0 : state.val, commandFeedbackCommandIds);
|
|
802
|
+
if (!commandId) {
|
|
803
|
+
continue;
|
|
804
|
+
}
|
|
805
|
+
const commandsPath = stateId.slice(0, -".lastCommand".length);
|
|
806
|
+
await this.writeCommandFeedbackStates(
|
|
807
|
+
commandsPath,
|
|
808
|
+
(0, import_command_feedback.formatCommandFeedback)(commandId, "interrupted", this.runtimeLanguage),
|
|
809
|
+
false
|
|
810
|
+
);
|
|
811
|
+
} catch (error) {
|
|
812
|
+
const details = error instanceof Error ? error.message : "Unknown state error";
|
|
813
|
+
this.log.warn(`Could not recover interrupted command feedback for ${stateId}: ${details}`);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
} catch (error) {
|
|
817
|
+
const details = error instanceof Error ? error.message : "Unknown object-list error";
|
|
818
|
+
this.log.warn(`Could not scan for interrupted command feedback: ${details}`);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
async setLastCommandFeedback(vin, commandId, status, attempt) {
|
|
822
|
+
const commandsPath = `vehicles.${this.getVehicleObjectId(vin)}.commands`;
|
|
823
|
+
try {
|
|
824
|
+
await this.commandFeedbackSequence.writeIfCurrent(vin, attempt, async () => {
|
|
825
|
+
if (this.stopping) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
await this.writeCommandFeedbackStates(
|
|
829
|
+
commandsPath,
|
|
830
|
+
(0, import_command_feedback.formatCommandFeedback)(commandId, status, this.runtimeLanguage),
|
|
831
|
+
(0, import_command_feedback.isCommandSuccessful)(status)
|
|
832
|
+
);
|
|
833
|
+
});
|
|
834
|
+
} catch {
|
|
835
|
+
this.log.warn("Could not update last API command feedback");
|
|
836
|
+
}
|
|
837
|
+
}
|
|
739
838
|
async executeSeatHeating(vin, seat, value) {
|
|
740
839
|
const stateId = this.vehicleCommandStatePath(vin, `${seat}SeatHeatLevel`);
|
|
840
|
+
const commandId = `${seat}SeatHeatLevel`;
|
|
841
|
+
const attempt = this.commandFeedbackSequence.beginAttempt(vin);
|
|
741
842
|
if (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > 3) {
|
|
843
|
+
const feedbackUpdate = this.setLastCommandFeedback(vin, commandId, "failed", attempt);
|
|
742
844
|
await this.setStateAsync(stateId, { ack: true });
|
|
845
|
+
await feedbackUpdate;
|
|
743
846
|
this.log.warn(`Ignored ${seat} seat heating level for ${vin}: expected an integer from 0 to 3`);
|
|
744
847
|
return;
|
|
745
848
|
}
|
|
746
849
|
if (this.vehicleCommandsInProgress.has(vin)) {
|
|
850
|
+
const feedbackUpdate = this.setLastCommandFeedback(vin, commandId, "failed", attempt);
|
|
747
851
|
await this.setStateAsync(stateId, { ack: true });
|
|
852
|
+
await feedbackUpdate;
|
|
748
853
|
this.log.warn(`Ignored ${seat} seat heating for ${vin}: another vehicle command is still running`);
|
|
749
854
|
return;
|
|
750
855
|
}
|
|
856
|
+
const levelCommandId = `${seat}SeatHeat${["Off", "Low", "Medium", "High"][value]}`;
|
|
751
857
|
this.vehicleCommandsInProgress.add(vin);
|
|
858
|
+
await this.setLastCommandFeedback(vin, levelCommandId, "inProgress", attempt);
|
|
859
|
+
let apiAccepted = false;
|
|
752
860
|
try {
|
|
753
861
|
if (!this.client || !this.loginOptions) {
|
|
754
862
|
throw new Error("SAIC client is not initialized");
|
|
@@ -764,10 +872,15 @@ class MgSaic extends utils.Adapter {
|
|
|
764
872
|
value,
|
|
765
873
|
this.abortController.signal
|
|
766
874
|
);
|
|
875
|
+
apiAccepted = true;
|
|
876
|
+
await this.setLastCommandFeedback(vin, levelCommandId, "apiConfirmed", attempt);
|
|
767
877
|
await this.setStateAsync(stateId, { val: value, ack: true });
|
|
768
878
|
this.log.info(`SAIC ${seat} seat heating level ${value} completed for ${vin}`);
|
|
769
879
|
} catch (error) {
|
|
770
880
|
if (!this.stopping) {
|
|
881
|
+
if (!apiAccepted) {
|
|
882
|
+
await this.setLastCommandFeedback(vin, levelCommandId, "failed", attempt);
|
|
883
|
+
}
|
|
771
884
|
await this.setStateAsync(stateId, { val: value, ack: true });
|
|
772
885
|
const details = error instanceof Error ? error.message : "Unknown command error";
|
|
773
886
|
this.log.warn(`SAIC ${seat} seat heating failed for ${vin}: ${details}`);
|
|
@@ -781,14 +894,18 @@ class MgSaic extends utils.Adapter {
|
|
|
781
894
|
const editVersions = new Map(
|
|
782
895
|
settingInputsByAction[action].map((settingId) => this.vehicleCommandStatePath(vin, settingId)).filter((settingId) => this.pendingSettingEdits.has(settingId)).map((settingId) => [settingId, this.pendingSettingEdits.get(settingId)])
|
|
783
896
|
);
|
|
897
|
+
const attempt = this.commandFeedbackSequence.beginAttempt(vin);
|
|
784
898
|
if (this.vehicleCommandsInProgress.has(vin)) {
|
|
899
|
+
const feedbackUpdate = this.setLastCommandFeedback(vin, action, "failed", attempt);
|
|
785
900
|
await this.setStateAsync(stateId, { val: false, ack: true });
|
|
901
|
+
await feedbackUpdate;
|
|
786
902
|
this.log.warn(`Ignored ${action} for ${vin}: another vehicle command is still running`);
|
|
787
903
|
return;
|
|
788
904
|
}
|
|
789
905
|
this.vehicleCommandsInProgress.add(vin);
|
|
790
906
|
try {
|
|
791
907
|
await this.setStateAsync(stateId, { val: false, ack: true });
|
|
908
|
+
await this.setLastCommandFeedback(vin, action, "inProgress", attempt);
|
|
792
909
|
if (!this.client || !this.loginOptions) {
|
|
793
910
|
throw new Error("SAIC client is not initialized");
|
|
794
911
|
}
|
|
@@ -803,6 +920,7 @@ class MgSaic extends utils.Adapter {
|
|
|
803
920
|
setting,
|
|
804
921
|
this.abortController.signal
|
|
805
922
|
);
|
|
923
|
+
await this.setLastCommandFeedback(vin, action, "apiConfirmed", attempt);
|
|
806
924
|
const clearedEdits = [];
|
|
807
925
|
for (const [settingId, version] of editVersions) {
|
|
808
926
|
if (this.pendingSettingEdits.get(settingId) === version) {
|
|
@@ -826,6 +944,7 @@ class MgSaic extends utils.Adapter {
|
|
|
826
944
|
this.log.info(`SAIC ${action} completed for ${vin}`);
|
|
827
945
|
} catch (error) {
|
|
828
946
|
if (!this.stopping) {
|
|
947
|
+
await this.setLastCommandFeedback(vin, action, "failed", attempt);
|
|
829
948
|
const details = error instanceof Error ? error.message : "Unknown settings error";
|
|
830
949
|
this.log.warn(`SAIC ${action} failed for ${vin}: ${details}`);
|
|
831
950
|
}
|
|
@@ -882,14 +1001,18 @@ class MgSaic extends utils.Adapter {
|
|
|
882
1001
|
}
|
|
883
1002
|
async executeVehicleCommand(vin, command) {
|
|
884
1003
|
const stateId = this.vehicleCommandStatePath(vin, command);
|
|
1004
|
+
const attempt = this.commandFeedbackSequence.beginAttempt(vin);
|
|
885
1005
|
if (this.vehicleCommandsInProgress.has(vin)) {
|
|
1006
|
+
const feedbackUpdate = this.setLastCommandFeedback(vin, command, "failed", attempt);
|
|
886
1007
|
await this.setStateAsync(stateId, { val: false, ack: true });
|
|
1008
|
+
await feedbackUpdate;
|
|
887
1009
|
this.log.warn(`Ignored ${command} command for ${vin}: another vehicle command is still running`);
|
|
888
1010
|
return;
|
|
889
1011
|
}
|
|
890
1012
|
this.vehicleCommandsInProgress.add(vin);
|
|
891
1013
|
try {
|
|
892
1014
|
await this.setStateAsync(stateId, { val: false, ack: true });
|
|
1015
|
+
await this.setLastCommandFeedback(vin, command, "inProgress", attempt);
|
|
893
1016
|
if (!this.client || !this.loginOptions) {
|
|
894
1017
|
throw new Error("SAIC client is not initialized");
|
|
895
1018
|
}
|
|
@@ -903,9 +1026,11 @@ class MgSaic extends utils.Adapter {
|
|
|
903
1026
|
command,
|
|
904
1027
|
this.abortController.signal
|
|
905
1028
|
);
|
|
1029
|
+
await this.setLastCommandFeedback(vin, command, "apiConfirmed", attempt);
|
|
906
1030
|
this.log.info(`SAIC ${command} command completed for ${vin}`);
|
|
907
1031
|
} catch (error) {
|
|
908
1032
|
if (!this.stopping) {
|
|
1033
|
+
await this.setLastCommandFeedback(vin, command, "failed", attempt);
|
|
909
1034
|
const details = error instanceof Error ? error.message : "Unknown command error";
|
|
910
1035
|
this.log.warn(`SAIC ${command} command failed for ${vin}: ${details}`);
|
|
911
1036
|
}
|
|
@@ -1273,6 +1398,42 @@ class MgSaic extends utils.Adapter {
|
|
|
1273
1398
|
});
|
|
1274
1399
|
await this.extendObjectAsync(groupId, { common: { name: groupName } });
|
|
1275
1400
|
}
|
|
1401
|
+
const lastCommandId = `${commandsId}.lastCommand`;
|
|
1402
|
+
const lastCommandCommon = {
|
|
1403
|
+
name: (0, import_runtime_translations.getRuntimeName)("lastCommand"),
|
|
1404
|
+
type: "string",
|
|
1405
|
+
role: "text",
|
|
1406
|
+
read: true,
|
|
1407
|
+
write: false
|
|
1408
|
+
};
|
|
1409
|
+
await this.setObjectNotExistsAsync(lastCommandId, {
|
|
1410
|
+
type: "state",
|
|
1411
|
+
common: lastCommandCommon,
|
|
1412
|
+
native: {}
|
|
1413
|
+
});
|
|
1414
|
+
await this.extendObjectAsync(lastCommandId, { common: lastCommandCommon });
|
|
1415
|
+
const lastCommandState = await this.getStateAsync(lastCommandId);
|
|
1416
|
+
if (!lastCommandState || lastCommandState.val === null) {
|
|
1417
|
+
await this.setStateAsync(lastCommandId, { val: "", ack: true });
|
|
1418
|
+
}
|
|
1419
|
+
const lastCommandSucceededId = `${commandsId}.lastCommandSucceeded`;
|
|
1420
|
+
const lastCommandSucceededCommon = {
|
|
1421
|
+
name: (0, import_runtime_translations.getRuntimeName)("lastCommandSucceeded"),
|
|
1422
|
+
type: "boolean",
|
|
1423
|
+
role: "indicator",
|
|
1424
|
+
read: true,
|
|
1425
|
+
write: false
|
|
1426
|
+
};
|
|
1427
|
+
await this.setObjectNotExistsAsync(lastCommandSucceededId, {
|
|
1428
|
+
type: "state",
|
|
1429
|
+
common: lastCommandSucceededCommon,
|
|
1430
|
+
native: {}
|
|
1431
|
+
});
|
|
1432
|
+
await this.extendObjectAsync(lastCommandSucceededId, { common: lastCommandSucceededCommon });
|
|
1433
|
+
const lastCommandSucceededState = await this.getStateAsync(lastCommandSucceededId);
|
|
1434
|
+
if (!lastCommandSucceededState || typeof lastCommandSucceededState.val !== "boolean") {
|
|
1435
|
+
await this.setStateAsync(lastCommandSucceededId, { val: false, ack: true });
|
|
1436
|
+
}
|
|
1276
1437
|
for (const command of vehicleCommands) {
|
|
1277
1438
|
const commandId = this.vehicleCommandStatePath(vehicle.vin, command.id);
|
|
1278
1439
|
await this.setObjectNotExistsAsync(commandId, {
|