@zwave-js/nvmedit 14.1.0 → 14.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/build/cjs/convert.js +39 -35
- package/build/cjs/convert.js.map +3 -3
- package/build/cjs/index_browser.d.ts +1 -0
- package/build/cjs/index_browser.js +17 -2
- package/build/cjs/index_browser.js.map +2 -2
- package/build/cjs/lib/nvm3/files/ApplicationRFConfigFile.js +6 -5
- package/build/cjs/lib/nvm3/files/ApplicationRFConfigFile.js.map +3 -3
- package/build/cjs/lib/nvm3/files/NVMFile.js +2 -2
- package/build/cjs/lib/nvm3/files/NVMFile.js.map +2 -2
- package/build/esm/convert.d.ts.map +1 -1
- package/build/esm/convert.js +32 -28
- package/build/esm/convert.js.map +1 -1
- package/build/esm/index_browser.d.ts +1 -0
- package/build/esm/index_browser.d.ts.map +1 -1
- package/build/esm/index_browser.js +4 -0
- package/build/esm/index_browser.js.map +1 -1
- package/build/esm/lib/nvm3/files/ApplicationRFConfigFile.d.ts.map +1 -1
- package/build/esm/lib/nvm3/files/ApplicationRFConfigFile.js +6 -5
- package/build/esm/lib/nvm3/files/ApplicationRFConfigFile.js.map +1 -1
- package/build/esm/lib/nvm3/files/NVMFile.js +1 -1
- package/build/esm/lib/nvm3/files/NVMFile.js.map +1 -1
- package/package.json +4 -4
package/build/cjs/convert.js
CHANGED
|
@@ -39,10 +39,14 @@ __export(convert_exports, {
|
|
|
39
39
|
nvmToJSON: () => nvmToJSON
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(convert_exports);
|
|
42
|
+
var import_error = require("@zwave-js/core/error");
|
|
42
43
|
var import_safe = require("@zwave-js/core/safe");
|
|
43
44
|
var import_safe2 = require("@zwave-js/shared/safe");
|
|
44
45
|
var import_typeguards = require("alcalzone-shared/typeguards");
|
|
45
|
-
var
|
|
46
|
+
var import_gte = __toESM(require("semver/functions/gte.js"), 1);
|
|
47
|
+
var import_lt = __toESM(require("semver/functions/lt.js"), 1);
|
|
48
|
+
var import_lte = __toESM(require("semver/functions/lte.js"), 1);
|
|
49
|
+
var import_parse = __toESM(require("semver/functions/parse.js"), 1);
|
|
46
50
|
var import_consts = require("./consts.js");
|
|
47
51
|
var import_NVM3 = require("./lib/NVM3.js");
|
|
48
52
|
var import_NVM500 = require("./lib/NVM500.js");
|
|
@@ -125,7 +129,7 @@ function nvmObjectsToJSON(objects) {
|
|
|
125
129
|
const ret2 = getObject(id);
|
|
126
130
|
if (ret2)
|
|
127
131
|
return ret2;
|
|
128
|
-
throw new
|
|
132
|
+
throw new import_error.ZWaveError(`Object${typeof id === "number" ? ` ${(0, import_safe2.num2hex)(id)} (${id})` : ""} not found!`, import_error.ZWaveErrorCodes.NVM_ObjectNotFound);
|
|
129
133
|
};
|
|
130
134
|
const getFileOrThrow = (id, fileVersion) => {
|
|
131
135
|
const obj = getObjectOrThrow(id);
|
|
@@ -141,7 +145,7 @@ function nvmObjectsToJSON(objects) {
|
|
|
141
145
|
const protocolFileFormat = protocolVersionFile.format;
|
|
142
146
|
const protocolVersion = `${protocolVersionFile.major}.${protocolVersionFile.minor}.${protocolVersionFile.patch}`;
|
|
143
147
|
if (protocolFileFormat > import_consts.MAX_PROTOCOL_FILE_FORMAT) {
|
|
144
|
-
throw new
|
|
148
|
+
throw new import_error.ZWaveError(`Unsupported protocol file format: ${protocolFileFormat}`, import_error.ZWaveErrorCodes.NVM_NotSupported, { protocolFileFormat });
|
|
145
149
|
}
|
|
146
150
|
const nodeIds = getFileOrThrow(import_files.ProtocolNodeListFileID, protocolVersion).nodeIds;
|
|
147
151
|
const appRouteLock = new Set(getFileOrThrow(import_files.ProtocolAppRouteLockNodeMaskFileID, protocolVersion).nodeIds);
|
|
@@ -226,7 +230,7 @@ function nvmObjectsToJSON(objects) {
|
|
|
226
230
|
const applicationVersionFile800 = getFile(import_files.ApplicationVersionFile800ID, "7.0.0");
|
|
227
231
|
const applicationVersionFile = applicationVersionFile700 ?? applicationVersionFile800;
|
|
228
232
|
if (!applicationVersionFile) {
|
|
229
|
-
throw new
|
|
233
|
+
throw new import_error.ZWaveError("ApplicationVersionFile not found!", import_error.ZWaveErrorCodes.NVM_ObjectNotFound);
|
|
230
234
|
}
|
|
231
235
|
const applicationVersion = `${applicationVersionFile.major}.${applicationVersionFile.minor}.${applicationVersionFile.patch}`;
|
|
232
236
|
const rfConfigFile = getFile(import_files.ApplicationRFConfigFileID, applicationVersion);
|
|
@@ -406,7 +410,7 @@ async function nvmToJSON(buffer, debugLogs = false) {
|
|
|
406
410
|
type: "protocolFileFormat"
|
|
407
411
|
}, true);
|
|
408
412
|
if (protocolFileFormat > import_consts.MAX_PROTOCOL_FILE_FORMAT) {
|
|
409
|
-
throw new
|
|
413
|
+
throw new import_error.ZWaveError(`Unsupported protocol file format: ${protocolFileFormat}`, import_error.ZWaveErrorCodes.NVM_NotSupported, { protocolFileFormat });
|
|
410
414
|
}
|
|
411
415
|
const protocolVersion = await adapter.get({
|
|
412
416
|
domain: "controller",
|
|
@@ -761,9 +765,9 @@ async function nvm500ToJSON(buffer) {
|
|
|
761
765
|
};
|
|
762
766
|
}
|
|
763
767
|
async function jsonToNVM(json, targetSDKVersion) {
|
|
764
|
-
const parsedVersion =
|
|
768
|
+
const parsedVersion = (0, import_parse.default)(targetSDKVersion);
|
|
765
769
|
if (!parsedVersion) {
|
|
766
|
-
throw new
|
|
770
|
+
throw new import_error.ZWaveError(`Invalid SDK version: ${targetSDKVersion}`, import_error.ZWaveErrorCodes.Argument_Invalid);
|
|
767
771
|
}
|
|
768
772
|
const sharedFileSystem = json.meta?.sharedFileSystem;
|
|
769
773
|
const nvmSize = sharedFileSystem ? import_consts2.ZWAVE_SHARED_NVM_SIZE : import_consts2.ZWAVE_APPLICATION_NVM_SIZE + import_consts2.ZWAVE_PROTOCOL_NVM_SIZE;
|
|
@@ -779,28 +783,28 @@ async function jsonToNVM(json, targetSDKVersion) {
|
|
|
779
783
|
let targetProtocolVersion;
|
|
780
784
|
let targetProtocolFormat;
|
|
781
785
|
const HIGHEST_SUPPORTED_SDK_VERSION = "7.21.0";
|
|
782
|
-
if (
|
|
783
|
-
targetApplicationVersion =
|
|
786
|
+
if ((0, import_lte.default)(targetSDKVersion, HIGHEST_SUPPORTED_SDK_VERSION)) {
|
|
787
|
+
targetApplicationVersion = (0, import_parse.default)(targetSDKVersion);
|
|
784
788
|
} else {
|
|
785
|
-
targetApplicationVersion =
|
|
789
|
+
targetApplicationVersion = (0, import_parse.default)(HIGHEST_SUPPORTED_SDK_VERSION);
|
|
786
790
|
}
|
|
787
|
-
if (
|
|
788
|
-
targetProtocolVersion =
|
|
791
|
+
if ((0, import_gte.default)(targetSDKVersion, "7.19.0")) {
|
|
792
|
+
targetProtocolVersion = (0, import_parse.default)("7.19.0");
|
|
789
793
|
targetProtocolFormat = 5;
|
|
790
|
-
} else if (
|
|
791
|
-
targetProtocolVersion =
|
|
794
|
+
} else if ((0, import_gte.default)(targetSDKVersion, "7.17.0")) {
|
|
795
|
+
targetProtocolVersion = (0, import_parse.default)("7.17.0");
|
|
792
796
|
targetProtocolFormat = 4;
|
|
793
|
-
} else if (
|
|
794
|
-
targetProtocolVersion =
|
|
797
|
+
} else if ((0, import_gte.default)(targetSDKVersion, "7.15.3")) {
|
|
798
|
+
targetProtocolVersion = (0, import_parse.default)("7.15.3");
|
|
795
799
|
targetProtocolFormat = 3;
|
|
796
|
-
} else if (
|
|
797
|
-
targetProtocolVersion =
|
|
800
|
+
} else if ((0, import_gte.default)(targetSDKVersion, "7.12.0")) {
|
|
801
|
+
targetProtocolVersion = (0, import_parse.default)("7.12.0");
|
|
798
802
|
targetProtocolFormat = 2;
|
|
799
|
-
} else if (
|
|
800
|
-
targetProtocolVersion =
|
|
803
|
+
} else if ((0, import_gte.default)(targetSDKVersion, "7.11.0")) {
|
|
804
|
+
targetProtocolVersion = (0, import_parse.default)("7.11.0");
|
|
801
805
|
targetProtocolFormat = 1;
|
|
802
806
|
} else {
|
|
803
|
-
targetProtocolVersion =
|
|
807
|
+
targetProtocolVersion = (0, import_parse.default)("7.0.0");
|
|
804
808
|
targetProtocolFormat = 0;
|
|
805
809
|
}
|
|
806
810
|
const target = (0, import_safe2.cloneDeep)(json);
|
|
@@ -858,11 +862,11 @@ async function jsonToNVM(json, targetSDKVersion) {
|
|
|
858
862
|
maxTXPower: null,
|
|
859
863
|
nodeIdType: null
|
|
860
864
|
};
|
|
861
|
-
if (
|
|
865
|
+
if ((0, import_gte.default)(targetSDKVersion, "7.15.3")) {
|
|
862
866
|
target.controller.rfConfig.enablePTI ??= 0;
|
|
863
867
|
target.controller.rfConfig.maxTXPower ??= 14;
|
|
864
868
|
}
|
|
865
|
-
if (
|
|
869
|
+
if ((0, import_gte.default)(targetSDKVersion, "7.21.0")) {
|
|
866
870
|
target.controller.rfConfig.nodeIdType ??= import_safe.NodeIDType.Short;
|
|
867
871
|
}
|
|
868
872
|
const applRFConfigFile = new import_files.ApplicationRFConfigFile({
|
|
@@ -953,7 +957,7 @@ async function jsonToNVM(json, targetSDKVersion) {
|
|
|
953
957
|
async function jsonToNVM500(json, protocolVersion) {
|
|
954
958
|
const impl = import_impls.nvm500Impls.find((p) => p.protocolVersions.includes(protocolVersion) && p.name.toLowerCase().startsWith(json.meta.library));
|
|
955
959
|
if (!impl) {
|
|
956
|
-
throw new
|
|
960
|
+
throw new import_error.ZWaveError(`Did not find a matching implementation for protocol version ${protocolVersion} and library ${json.meta.library}. To convert 500-series NVMs, both the source and the target controller must be using Z-Wave SDK 6.61 or higher.`, import_error.ZWaveErrorCodes.NVM_NotSupported);
|
|
957
961
|
}
|
|
958
962
|
const { layout, nvmSize } = (0, import_shared.resolveLayout)(impl.layout);
|
|
959
963
|
const ret = new Uint8Array(nvmSize);
|
|
@@ -1064,7 +1068,7 @@ function json500To700(json, truncateApplicationData) {
|
|
|
1064
1068
|
raw = raw.subarray(start, end + 1);
|
|
1065
1069
|
if (raw.length > 512) {
|
|
1066
1070
|
if (!truncateApplicationData) {
|
|
1067
|
-
throw new
|
|
1071
|
+
throw new import_error.ZWaveError("Invalid NVM JSON: Application data would be truncated! Set truncateApplicationData to true to allow this.", import_error.ZWaveErrorCodes.NVM_InvalidJSON);
|
|
1068
1072
|
}
|
|
1069
1073
|
raw = raw.subarray(0, 512);
|
|
1070
1074
|
}
|
|
@@ -1191,12 +1195,12 @@ async function migrateNVM(sourceNVM, targetNVM) {
|
|
|
1191
1195
|
};
|
|
1192
1196
|
sourceProtocolFileFormat = source.json.format;
|
|
1193
1197
|
} catch (e) {
|
|
1194
|
-
if ((0,
|
|
1198
|
+
if ((0, import_error.isZWaveError)(e) && e.code === import_error.ZWaveErrorCodes.NVM_InvalidFormat) {
|
|
1195
1199
|
source = {
|
|
1196
1200
|
type: 500,
|
|
1197
1201
|
json: await nvm500ToJSON(sourceNVM)
|
|
1198
1202
|
};
|
|
1199
|
-
} else if ((0,
|
|
1203
|
+
} else if ((0, import_error.isZWaveError)(e) && e.code === import_error.ZWaveErrorCodes.NVM_NotSupported && (0, import_typeguards.isObject)(e.context) && typeof e.context.protocolFileFormat === "number") {
|
|
1200
1204
|
source = { type: "unknown" };
|
|
1201
1205
|
sourceProtocolFileFormat = e.context.protocolFileFormat;
|
|
1202
1206
|
} else {
|
|
@@ -1210,12 +1214,12 @@ async function migrateNVM(sourceNVM, targetNVM) {
|
|
|
1210
1214
|
};
|
|
1211
1215
|
targetProtocolFileFormat = target.json.format;
|
|
1212
1216
|
} catch (e) {
|
|
1213
|
-
if ((0,
|
|
1217
|
+
if ((0, import_error.isZWaveError)(e) && e.code === import_error.ZWaveErrorCodes.NVM_InvalidFormat) {
|
|
1214
1218
|
target = {
|
|
1215
1219
|
type: 500,
|
|
1216
1220
|
json: await nvm500ToJSON(targetNVM)
|
|
1217
1221
|
};
|
|
1218
|
-
} else if ((0,
|
|
1222
|
+
} else if ((0, import_error.isZWaveError)(e) && e.code === import_error.ZWaveErrorCodes.NVM_NotSupported && source.type === 700 && (0, import_typeguards.isObject)(e.context) && typeof e.context.protocolFileFormat === "number") {
|
|
1219
1223
|
target = { type: "unknown" };
|
|
1220
1224
|
targetProtocolFileFormat = e.context.protocolFileFormat;
|
|
1221
1225
|
} else {
|
|
@@ -1229,19 +1233,19 @@ async function migrateNVM(sourceNVM, targetNVM) {
|
|
|
1229
1233
|
const targetProtocolVersion = target.json.controller.protocolVersion;
|
|
1230
1234
|
const sourceApplicationVersion = source.json.controller.applicationVersion;
|
|
1231
1235
|
const targetApplicationVersion = target.json.controller.applicationVersion;
|
|
1232
|
-
if (
|
|
1236
|
+
if ((0, import_gte.default)(targetProtocolVersion, "7.16.0") && (0, import_gte.default)(targetProtocolVersion, sourceProtocolVersion) && (0, import_gte.default)(targetApplicationVersion, targetProtocolVersion) && (0, import_gte.default)(sourceApplicationVersion, sourceProtocolVersion) && (0, import_lt.default)(sourceApplicationVersion, "255.0.0") && (0, import_lt.default)(targetApplicationVersion, "255.0.0") && !hasShiftedAppVersion800File(source.json)) {
|
|
1233
1237
|
return sourceNVM;
|
|
1234
1238
|
}
|
|
1235
1239
|
} else if (source.type === "unknown" && target.type !== "unknown") {
|
|
1236
|
-
throw new
|
|
1240
|
+
throw new import_error.ZWaveError(`The source NVM has an unsupported format, which cannot be restored on a ${target.type}-series NVM!`, import_error.ZWaveErrorCodes.NVM_NotSupported);
|
|
1237
1241
|
} else if (source.type !== "unknown" && target.type === "unknown") {
|
|
1238
|
-
throw new
|
|
1242
|
+
throw new import_error.ZWaveError(`The target NVM has an unsupported format, cannot restore ${source.type}-series NVM onto it!`, import_error.ZWaveErrorCodes.NVM_NotSupported);
|
|
1239
1243
|
} else if (source.type === "unknown" && target.type === "unknown") {
|
|
1240
1244
|
return sourceNVM;
|
|
1241
1245
|
}
|
|
1242
1246
|
source = source;
|
|
1243
1247
|
target = target;
|
|
1244
|
-
if (target.type === 700 &&
|
|
1248
|
+
if (target.type === 700 && (0, import_gte.default)(target.json.controller.applicationVersion, "255.0.0")) {
|
|
1245
1249
|
target.json.controller.applicationVersion = target.json.controller.protocolVersion;
|
|
1246
1250
|
}
|
|
1247
1251
|
source.json.controller.applicationVersion = target.json.controller.applicationVersion;
|
|
@@ -1278,10 +1282,10 @@ async function migrateNVM(sourceNVM, targetNVM) {
|
|
|
1278
1282
|
function hasShiftedAppVersion800File(json) {
|
|
1279
1283
|
if (!json.meta.sharedFileSystem)
|
|
1280
1284
|
return false;
|
|
1281
|
-
const protocolVersion =
|
|
1285
|
+
const protocolVersion = (0, import_parse.default)(json.controller.protocolVersion);
|
|
1282
1286
|
if (!protocolVersion)
|
|
1283
1287
|
return false;
|
|
1284
|
-
const applicationVersion =
|
|
1288
|
+
const applicationVersion = (0, import_parse.default)(json.controller.applicationVersion);
|
|
1285
1289
|
if (!applicationVersion)
|
|
1286
1290
|
return false;
|
|
1287
1291
|
if (json.applicationFileFormat !== protocolVersion.major)
|