@zwave-js/config 15.16.0 → 15.17.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/JsonTemplate.js +2 -2
- package/build/cjs/JsonTemplate.js.map +2 -2
- package/build/cjs/Manufacturers.js +1 -1
- package/build/cjs/Manufacturers.js.map +2 -2
- package/build/cjs/_version.d.ts +1 -1
- package/build/cjs/_version.js +1 -1
- package/build/cjs/_version.js.map +1 -1
- package/build/cjs/devices/DeviceConfig.js +3 -3
- package/build/cjs/devices/DeviceConfig.js.map +2 -2
- package/build/cjs/devices/DeviceConfig.unit._test.js.map +1 -1
- package/build/cjs/devices/ParamInformation.js +1 -1
- package/build/cjs/devices/ParamInformation.js.map +2 -2
- package/build/cjs/index.js.map +2 -2
- package/build/esm/JsonTemplate.js +2 -2
- package/build/esm/JsonTemplate.js.map +1 -1
- package/build/esm/Manufacturers.js +1 -1
- package/build/esm/Manufacturers.js.map +1 -1
- package/build/esm/_version.d.ts +1 -1
- package/build/esm/_version.js +1 -1
- package/build/esm/devices/DeviceConfig.d.ts.map +1 -1
- package/build/esm/devices/DeviceConfig.js +4 -3
- package/build/esm/devices/DeviceConfig.js.map +1 -1
- package/build/esm/devices/DeviceConfig.unit._test.js +1 -0
- package/build/esm/devices/DeviceConfig.unit._test.js.map +1 -1
- package/build/esm/devices/ParamInformation.d.ts.map +1 -1
- package/build/esm/devices/ParamInformation.js +1 -2
- package/build/esm/devices/ParamInformation.js.map +1 -1
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +0 -1
- package/build/esm/index.js.map +1 -1
- package/config/devices/0x0090/918.json +4 -0
- package/config/devices/0x0148/cometz_700.json +1 -1
- package/config/devices/0x021d/{ddl240x.json → ddl240x_15hzw.json} +1 -2
- package/config/devices/0x021d/ddl240x_1hzw.json +115 -0
- package/config/devices/0x0460/qlsh-001P10.json +119 -0
- package/config/devices/0x0460/qnpl-0A112.json +4 -0
- package/config/devices/0x0460/qnsw-001P16.json +15 -0
- package/config/devices/0x0460/qnsw-001X16.json +10 -0
- package/config/devices/0x0460/templates/wave_template.json +70 -0
- package/config/devices/0x0460/{qnsw-002P16.json → wave_2pm.json} +22 -1
- package/package.json +6 -6
|
@@ -39,7 +39,7 @@ var import_typeguards = require("alcalzone-shared/typeguards");
|
|
|
39
39
|
var import_json5 = __toESM(require("json5"), 1);
|
|
40
40
|
var import_pathe = __toESM(require("pathe"), 1);
|
|
41
41
|
const IMPORT_KEY = "$import";
|
|
42
|
-
const importSpecifierRegex = /^(?<filename>(?:~\/)?[\w\d
|
|
42
|
+
const importSpecifierRegex = /^(?<filename>(?:~\/)?[\w\d/\\._-]+\.json)?(?:#(?<selector>[\w\d/._-]+(?:\[0x[0-9a-fA-F]+\])?))?$/i;
|
|
43
43
|
const templateCache = /* @__PURE__ */ new Map();
|
|
44
44
|
function clearTemplateCache() {
|
|
45
45
|
templateCache.clear();
|
|
@@ -98,7 +98,7 @@ function select(obj, selector) {
|
|
|
98
98
|
}
|
|
99
99
|
__name(select, "select");
|
|
100
100
|
function getImportStack(visited, selector) {
|
|
101
|
-
const source = [...visited, selector ? `#${selector}` : void 0].
|
|
101
|
+
const source = [...visited, selector ? `#${selector}` : void 0].toReversed().filter((s) => !!s);
|
|
102
102
|
if (source.length > 0) {
|
|
103
103
|
return `
|
|
104
104
|
Import stack: ${source.map((s) => `
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/JsonTemplate.ts"],
|
|
4
|
-
"sourcesContent": ["import { ZWaveError, ZWaveErrorCodes } from \"@zwave-js/core\";\nimport { getErrorMessage, pathExists, readTextFile } from \"@zwave-js/shared\";\nimport type { ReadFile, ReadFileSystemInfo } from \"@zwave-js/shared/bindings\";\nimport { isArray, isObject } from \"alcalzone-shared/typeguards\";\nimport JSON5 from \"json5\";\nimport path from \"pathe\";\n\nconst IMPORT_KEY = \"$import\";\nconst importSpecifierRegex =\n\t/^(?<filename>(?:~\\/)?[\\w\\d\\/\\\\\\._-]+\\.json)?(?:#(?<selector>[\\w\\d\\/\\._-]+(?:\\[0x[0-9a-fA-F]+\\])?))?$/i;\n\ntype FileCache = Map<string, Record<string, unknown>>;\n\n// The template cache is used to speed up cases where the same files get parsed multiple times,\n// e.g. during config file linting. It should be cleared whenever the files need to be loaded fresh\n// from disk, like when creating an index\nconst templateCache: FileCache = new Map();\nexport function clearTemplateCache(): void {\n\ttemplateCache.clear();\n}\n\n/** Parses a JSON file with $import keys and replaces them with the selected objects */\nexport async function readJsonWithTemplate(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tfilename: string,\n\trootDirs?: string | string[],\n): Promise<Record<string, unknown>> {\n\tif (!(await pathExists(fs, filename))) {\n\t\tthrow new ZWaveError(\n\t\t\t`Could not open config file ${filename}: not found!`,\n\t\t\tZWaveErrorCodes.Config_NotFound,\n\t\t);\n\t}\n\n\tif (typeof rootDirs === \"string\") rootDirs = [rootDirs];\n\n\t// Try to use the cached versions of the template files to speed up the loading\n\tconst fileCache = new Map(templateCache);\n\tconst ret = await readJsonWithTemplateInternal(\n\t\tfs,\n\t\tfilename,\n\t\tundefined,\n\t\t[],\n\t\tfileCache,\n\t\trootDirs,\n\t);\n\n\t// Only remember the cached templates, not the individual files to save RAM\n\tfor (const [filename, cached] of fileCache) {\n\t\tif (/[\\\\/]templates[\\\\/]/.test(filename)) {\n\t\t\ttemplateCache.set(filename, cached);\n\t\t}\n\t}\n\n\treturn ret;\n}\n\nfunction assertImportSpecifier(\n\tval: unknown,\n\tsource?: string,\n): asserts val is string {\n\tif (typeof val !== \"string\") {\n\t\tthrow new ZWaveError(\n\t\t\t`Invalid import specifier ${String(val)}!${\n\t\t\t\tsource != undefined ? ` Source: ${source}` : \"\"\n\t\t\t}`,\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n\tif (!importSpecifierRegex.test(val)) {\n\t\tthrow new ZWaveError(\n\t\t\t`Import specifier \"${val}\" is invalid!${\n\t\t\t\tsource != undefined ? ` Source: ${source}` : \"\"\n\t\t\t}`,\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n}\n\nfunction getImportSpecifier(filename: string, selector?: string): string {\n\tlet ret = filename;\n\tif (selector) ret += `#${selector}`;\n\treturn ret;\n}\n\nfunction select(\n\tobj: Record<string, unknown>,\n\tselector: string,\n): Record<string, unknown> {\n\tlet ret: Record<string, unknown> = obj;\n\tconst selectorParts = selector.split(\"/\").filter((s) => !!s);\n\tfor (const part of selectorParts) {\n\t\t// Special case for paramInformation selectors to select params by #\n\t\tif (isArray(ret)) {\n\t\t\tconst item = (ret as any).find(\n\t\t\t\t(r: any) => isObject(r) && \"#\" in r && r[\"#\"] === part,\n\t\t\t);\n\t\t\tif (item != undefined) {\n\t\t\t\t// Don't copy the param number\n\t\t\t\tconst { [\"#\"]: _, ...rest } = item;\n\t\t\t\tret = rest;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\t// By default select the object property\n\t\tret = (ret as any)[part];\n\t}\n\tif (!isObject(ret)) {\n\t\tthrow new ZWaveError(\n\t\t\t`The import target \"${selector}\" is not an object!`,\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n\treturn ret;\n}\n\nfunction getImportStack(\n\tvisited: string[],\n\tselector: string | undefined,\n): string {\n\tconst source = [...visited, selector ? `#${selector}` : undefined]\n\t\t.reverse()\n\t\t.filter((s) => !!s) as string[];\n\tif (source.length > 0) {\n\t\treturn `\\nImport stack: ${source.map((s) => `\\n in ${s}`).join(\"\")}`;\n\t}\n\treturn \"\";\n}\n\nasync function readJsonWithTemplateInternal(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tfilename: string,\n\tselector: string | undefined,\n\tvisited: string[],\n\tfileCache: FileCache,\n\trootDirs?: string[],\n): Promise<Record<string, unknown>> {\n\tfilename = path.normalize(filename);\n\n\t// If we're limited by one or more root directories, make sure the file is inside one of those\n\tif (rootDirs) {\n\t\tconst outsideAllRootDirs = rootDirs.every((rootDir) => {\n\t\t\tconst relativeToRoot = path.relative(rootDir, filename);\n\t\t\treturn relativeToRoot.startsWith(\"..\");\n\t\t});\n\n\t\tif (outsideAllRootDirs) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Tried to import config file \"${filename}\" from outside all root directories: ${\n\t\t\t\t\trootDirs\n\t\t\t\t\t\t.map((d) => `\\n\u00B7 ${d}`)\n\t\t\t\t\t\t.join(\"\")\n\t\t\t\t}\n${getImportStack(visited, selector)}`,\n\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst specifier = getImportSpecifier(filename, selector);\n\tif (visited.includes(specifier)) {\n\t\tconst msg = `Circular $import in config files: ${\n\t\t\t[\n\t\t\t\t...visited,\n\t\t\t\tspecifier,\n\t\t\t].join(\" -> \")\n\t\t}\\n`;\n\t\t// process.stderr.write(msg + \"\\n\");\n\t\tthrow new ZWaveError(msg, ZWaveErrorCodes.Config_CircularImport);\n\t}\n\n\tlet json: Record<string, unknown>;\n\tif (fileCache.has(filename)) {\n\t\tjson = fileCache.get(filename)!;\n\t} else {\n\t\ttry {\n\t\t\tconst fileContent = await readTextFile(fs, filename, \"utf8\");\n\t\t\tjson = JSON5.parse(fileContent);\n\t\t\tfileCache.set(filename, json);\n\t\t} catch (e) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Could not parse config file ${filename}: ${\n\t\t\t\t\tgetErrorMessage(\n\t\t\t\t\t\te,\n\t\t\t\t\t)\n\t\t\t\t}${getImportStack(visited, selector)}`,\n\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t);\n\t\t}\n\t}\n\t// Resolve the JSON imports for (a subset) of the file and return the compound file\n\treturn resolveJsonImports(\n\t\tfs,\n\t\tselector ? select(json, selector) : json,\n\t\tfilename,\n\t\t[...visited, specifier],\n\t\tfileCache,\n\t\trootDirs,\n\t);\n}\n\n/** Replaces all `$import` properties in a JSON object with object spreads of the referenced file/property */\nasync function resolveJsonImports(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tjson: Record<string, unknown>,\n\tfilename: string,\n\tvisited: string[],\n\tfileCache: FileCache,\n\trootDirs?: string[],\n): Promise<Record<string, unknown>> {\n\tconst ret: Record<string, unknown> = {};\n\t// Loop through all properties and copy them to the resulting object\n\tfor (const [prop, val] of Object.entries(json)) {\n\t\tif (prop === IMPORT_KEY) {\n\t\t\t// This is an import statement. Make sure we're working with a string\n\t\t\tassertImportSpecifier(val, visited.join(\" -> \"));\n\t\t\tconst { filename: importFilename, selector } = importSpecifierRegex\n\t\t\t\t.exec(val)!.groups!;\n\n\t\t\t// Resolve the correct import path\n\t\t\tlet newFilename: string | undefined;\n\t\t\tif (importFilename) {\n\t\t\t\tif (importFilename.startsWith(\"~/\")) {\n\t\t\t\t\t// This is a special import specifier that is relative to the root directory\n\t\t\t\t\t// Try to find at least one root directory that contains the referenced file\n\t\t\t\t\tif (rootDirs) {\n\t\t\t\t\t\tfor (const rootDir of rootDirs) {\n\t\t\t\t\t\t\tnewFilename = path.join(\n\t\t\t\t\t\t\t\trootDir,\n\t\t\t\t\t\t\t\timportFilename.slice(2),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (await pathExists(fs, newFilename)) {\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Try the next\n\t\t\t\t\t\t\t\tnewFilename = undefined!;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!newFilename) {\n\t\t\t\t\t\t\tthrow new ZWaveError(\n\t\t\t\t\t\t\t\t`Could not find the referenced file ${\n\t\t\t\t\t\t\t\t\timportFilename.slice(\n\t\t\t\t\t\t\t\t\t\t2,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t} in any of the root directories: ${\n\t\t\t\t\t\t\t\t\trootDirs\n\t\t\t\t\t\t\t\t\t\t.map((d) => `\\n\u00B7 ${d}`)\n\t\t\t\t\t\t\t\t\t\t.join(\"\")\n\t\t\t\t\t\t\t\t}\\n${\n\t\t\t\t\t\t\t\t\tgetImportStack(\n\t\t\t\t\t\t\t\t\t\tvisited,\n\t\t\t\t\t\t\t\t\t\tselector,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}`,\n\t\t\t\t\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new ZWaveError(\n\t\t\t\t\t\t\t`An $import specifier cannot start with ~/ when no root directory is defined!${\n\t\t\t\t\t\t\t\tgetImportStack(\n\t\t\t\t\t\t\t\t\tvisited,\n\t\t\t\t\t\t\t\t\tselector,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}`,\n\t\t\t\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnewFilename = path.join(\n\t\t\t\t\t\tpath.dirname(filename),\n\t\t\t\t\t\timportFilename,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnewFilename = filename;\n\t\t\t}\n\n\t\t\t// const importFilename = path.join(path.dirname(filename), val);\n\t\t\tconst imported = await readJsonWithTemplateInternal(\n\t\t\t\tfs,\n\t\t\t\tnewFilename,\n\t\t\t\tselector,\n\t\t\t\tvisited,\n\t\t\t\tfileCache,\n\t\t\t\trootDirs,\n\t\t\t);\n\t\t\tObject.assign(ret, imported);\n\t\t} else if (isObject(val)) {\n\t\t\t// We're looking at an object, recurse into it\n\t\t\tret[prop] = await resolveJsonImports(\n\t\t\t\tfs,\n\t\t\t\tval,\n\t\t\t\tfilename,\n\t\t\t\tvisited,\n\t\t\t\tfileCache,\n\t\t\t\trootDirs,\n\t\t\t);\n\t\t} else if (isArray(val)) {\n\t\t\t// We're looking at an array, check if there are objects we need to recurse into\n\t\t\tconst vals: unknown[] = [];\n\t\t\tfor (const v of val) {\n\t\t\t\tif (isObject(v)) {\n\t\t\t\t\tvals.push(\n\t\t\t\t\t\tawait resolveJsonImports(\n\t\t\t\t\t\t\tfs,\n\t\t\t\t\t\t\tv,\n\t\t\t\t\t\t\tfilename,\n\t\t\t\t\t\t\tvisited,\n\t\t\t\t\t\t\tfileCache,\n\t\t\t\t\t\t\trootDirs,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tvals.push(v);\n\t\t\t\t}\n\t\t\t}\n\t\t\tret[prop] = vals;\n\t\t} else {\n\t\t\tret[prop] = val;\n\t\t}\n\t}\n\treturn ret;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAAA,kBAA4C;AAC5C,oBAA0D;AAE1D,wBAAkC;AAClC,mBAAkB;AAClB,mBAAiB;AAEjB,MAAM,aAAa;AACnB,MAAM,uBACL;AAOD,MAAM,gBAA2B,oBAAI,IAAG;AAClC,SAAU,qBAAkB;AACjC,gBAAc,MAAK;AACpB;AAFgB;AAKhB,eAAsB,qBACrB,IACA,UACA,UAA4B;AAE5B,MAAI,CAAE,UAAM,0BAAW,IAAI,QAAQ,GAAI;AACtC,UAAM,IAAI,uBACT,8BAA8B,QAAQ,gBACtC,4BAAgB,eAAe;EAEjC;AAEA,MAAI,OAAO,aAAa;AAAU,eAAW,CAAC,QAAQ;AAGtD,QAAM,YAAY,IAAI,IAAI,aAAa;AACvC,QAAM,MAAM,MAAM,6BACjB,IACA,UACA,QACA,CAAA,GACA,WACA,QAAQ;AAIT,aAAW,CAACA,WAAU,MAAM,KAAK,WAAW;AAC3C,QAAI,sBAAsB,KAAKA,SAAQ,GAAG;AACzC,oBAAc,IAAIA,WAAU,MAAM;IACnC;EACD;AAEA,SAAO;AACR;AAjCsB;AAmCtB,SAAS,sBACR,KACA,QAAe;AAEf,MAAI,OAAO,QAAQ,UAAU;AAC5B,UAAM,IAAI,uBACT,4BAA4B,OAAO,GAAG,CAAC,IACtC,UAAU,SAAY,YAAY,MAAM,KAAK,EAC9C,IACA,4BAAgB,cAAc;EAEhC;AACA,MAAI,CAAC,qBAAqB,KAAK,GAAG,GAAG;AACpC,UAAM,IAAI,uBACT,qBAAqB,GAAG,gBACvB,UAAU,SAAY,YAAY,MAAM,KAAK,EAC9C,IACA,4BAAgB,cAAc;EAEhC;AACD;AApBS;AAsBT,SAAS,mBAAmB,UAAkB,UAAiB;AAC9D,MAAI,MAAM;AACV,MAAI;AAAU,WAAO,IAAI,QAAQ;AACjC,SAAO;AACR;AAJS;AAMT,SAAS,OACR,KACA,UAAgB;AAEhB,MAAI,MAA+B;AACnC,QAAM,gBAAgB,SAAS,MAAM,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AAC3D,aAAW,QAAQ,eAAe;AAEjC,YAAI,2BAAQ,GAAG,GAAG;AACjB,YAAM,OAAQ,IAAY,KACzB,CAAC,UAAW,4BAAS,CAAC,KAAK,OAAO,KAAK,EAAE,GAAG,MAAM,IAAI;AAEvD,UAAI,QAAQ,QAAW;AAEtB,cAAM,EAAE,CAAC,GAAG,GAAG,GAAG,GAAG,KAAI,IAAK;AAC9B,cAAM;AACN;MACD;IACD;AAEA,UAAO,IAAY,IAAI;EACxB;AACA,MAAI,KAAC,4BAAS,GAAG,GAAG;AACnB,UAAM,IAAI,uBACT,sBAAsB,QAAQ,uBAC9B,4BAAgB,cAAc;EAEhC;AACA,SAAO;AACR;AA7BS;AA+BT,SAAS,eACR,SACA,UAA4B;AAE5B,QAAM,SAAS,CAAC,GAAG,SAAS,WAAW,IAAI,QAAQ,KAAK,MAAS,EAC/D,
|
|
4
|
+
"sourcesContent": ["import { ZWaveError, ZWaveErrorCodes } from \"@zwave-js/core\";\nimport { getErrorMessage, pathExists, readTextFile } from \"@zwave-js/shared\";\nimport type { ReadFile, ReadFileSystemInfo } from \"@zwave-js/shared/bindings\";\nimport { isArray, isObject } from \"alcalzone-shared/typeguards\";\nimport JSON5 from \"json5\";\nimport path from \"pathe\";\n\nconst IMPORT_KEY = \"$import\";\nconst importSpecifierRegex =\n\t/^(?<filename>(?:~\\/)?[\\w\\d/\\\\._-]+\\.json)?(?:#(?<selector>[\\w\\d/._-]+(?:\\[0x[0-9a-fA-F]+\\])?))?$/i;\n\ntype FileCache = Map<string, Record<string, unknown>>;\n\n// The template cache is used to speed up cases where the same files get parsed multiple times,\n// e.g. during config file linting. It should be cleared whenever the files need to be loaded fresh\n// from disk, like when creating an index\nconst templateCache: FileCache = new Map();\nexport function clearTemplateCache(): void {\n\ttemplateCache.clear();\n}\n\n/** Parses a JSON file with $import keys and replaces them with the selected objects */\nexport async function readJsonWithTemplate(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tfilename: string,\n\trootDirs?: string | string[],\n): Promise<Record<string, unknown>> {\n\tif (!(await pathExists(fs, filename))) {\n\t\tthrow new ZWaveError(\n\t\t\t`Could not open config file ${filename}: not found!`,\n\t\t\tZWaveErrorCodes.Config_NotFound,\n\t\t);\n\t}\n\n\tif (typeof rootDirs === \"string\") rootDirs = [rootDirs];\n\n\t// Try to use the cached versions of the template files to speed up the loading\n\tconst fileCache = new Map(templateCache);\n\tconst ret = await readJsonWithTemplateInternal(\n\t\tfs,\n\t\tfilename,\n\t\tundefined,\n\t\t[],\n\t\tfileCache,\n\t\trootDirs,\n\t);\n\n\t// Only remember the cached templates, not the individual files to save RAM\n\tfor (const [filename, cached] of fileCache) {\n\t\tif (/[\\\\/]templates[\\\\/]/.test(filename)) {\n\t\t\ttemplateCache.set(filename, cached);\n\t\t}\n\t}\n\n\treturn ret;\n}\n\nfunction assertImportSpecifier(\n\tval: unknown,\n\tsource?: string,\n): asserts val is string {\n\tif (typeof val !== \"string\") {\n\t\tthrow new ZWaveError(\n\t\t\t`Invalid import specifier ${String(val)}!${\n\t\t\t\tsource != undefined ? ` Source: ${source}` : \"\"\n\t\t\t}`,\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n\tif (!importSpecifierRegex.test(val)) {\n\t\tthrow new ZWaveError(\n\t\t\t`Import specifier \"${val}\" is invalid!${\n\t\t\t\tsource != undefined ? ` Source: ${source}` : \"\"\n\t\t\t}`,\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n}\n\nfunction getImportSpecifier(filename: string, selector?: string): string {\n\tlet ret = filename;\n\tif (selector) ret += `#${selector}`;\n\treturn ret;\n}\n\nfunction select(\n\tobj: Record<string, unknown>,\n\tselector: string,\n): Record<string, unknown> {\n\tlet ret: Record<string, unknown> = obj;\n\tconst selectorParts = selector.split(\"/\").filter((s) => !!s);\n\tfor (const part of selectorParts) {\n\t\t// Special case for paramInformation selectors to select params by #\n\t\tif (isArray(ret)) {\n\t\t\tconst item = (ret as any).find(\n\t\t\t\t(r: any) => isObject(r) && \"#\" in r && r[\"#\"] === part,\n\t\t\t);\n\t\t\tif (item != undefined) {\n\t\t\t\t// Don't copy the param number\n\t\t\t\tconst { [\"#\"]: _, ...rest } = item;\n\t\t\t\tret = rest;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\t// By default select the object property\n\t\tret = (ret as any)[part];\n\t}\n\tif (!isObject(ret)) {\n\t\tthrow new ZWaveError(\n\t\t\t`The import target \"${selector}\" is not an object!`,\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n\treturn ret;\n}\n\nfunction getImportStack(\n\tvisited: string[],\n\tselector: string | undefined,\n): string {\n\tconst source = [...visited, selector ? `#${selector}` : undefined]\n\t\t.toReversed()\n\t\t.filter((s) => !!s) as string[];\n\tif (source.length > 0) {\n\t\treturn `\\nImport stack: ${source.map((s) => `\\n in ${s}`).join(\"\")}`;\n\t}\n\treturn \"\";\n}\n\nasync function readJsonWithTemplateInternal(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tfilename: string,\n\tselector: string | undefined,\n\tvisited: string[],\n\tfileCache: FileCache,\n\trootDirs?: string[],\n): Promise<Record<string, unknown>> {\n\tfilename = path.normalize(filename);\n\n\t// If we're limited by one or more root directories, make sure the file is inside one of those\n\tif (rootDirs) {\n\t\tconst outsideAllRootDirs = rootDirs.every((rootDir) => {\n\t\t\tconst relativeToRoot = path.relative(rootDir, filename);\n\t\t\treturn relativeToRoot.startsWith(\"..\");\n\t\t});\n\n\t\tif (outsideAllRootDirs) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Tried to import config file \"${filename}\" from outside all root directories: ${\n\t\t\t\t\trootDirs\n\t\t\t\t\t\t.map((d) => `\\n\u00B7 ${d}`)\n\t\t\t\t\t\t.join(\"\")\n\t\t\t\t}\n${getImportStack(visited, selector)}`,\n\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst specifier = getImportSpecifier(filename, selector);\n\tif (visited.includes(specifier)) {\n\t\tconst msg = `Circular $import in config files: ${\n\t\t\t[\n\t\t\t\t...visited,\n\t\t\t\tspecifier,\n\t\t\t].join(\" -> \")\n\t\t}\\n`;\n\t\t// process.stderr.write(msg + \"\\n\");\n\t\tthrow new ZWaveError(msg, ZWaveErrorCodes.Config_CircularImport);\n\t}\n\n\tlet json: Record<string, unknown>;\n\tif (fileCache.has(filename)) {\n\t\tjson = fileCache.get(filename)!;\n\t} else {\n\t\ttry {\n\t\t\tconst fileContent = await readTextFile(fs, filename, \"utf8\");\n\t\t\tjson = JSON5.parse(fileContent);\n\t\t\tfileCache.set(filename, json);\n\t\t} catch (e) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Could not parse config file ${filename}: ${\n\t\t\t\t\tgetErrorMessage(\n\t\t\t\t\t\te,\n\t\t\t\t\t)\n\t\t\t\t}${getImportStack(visited, selector)}`,\n\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t);\n\t\t}\n\t}\n\t// Resolve the JSON imports for (a subset) of the file and return the compound file\n\treturn resolveJsonImports(\n\t\tfs,\n\t\tselector ? select(json, selector) : json,\n\t\tfilename,\n\t\t[...visited, specifier],\n\t\tfileCache,\n\t\trootDirs,\n\t);\n}\n\n/** Replaces all `$import` properties in a JSON object with object spreads of the referenced file/property */\nasync function resolveJsonImports(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tjson: Record<string, unknown>,\n\tfilename: string,\n\tvisited: string[],\n\tfileCache: FileCache,\n\trootDirs?: string[],\n): Promise<Record<string, unknown>> {\n\tconst ret: Record<string, unknown> = {};\n\t// Loop through all properties and copy them to the resulting object\n\tfor (const [prop, val] of Object.entries(json)) {\n\t\tif (prop === IMPORT_KEY) {\n\t\t\t// This is an import statement. Make sure we're working with a string\n\t\t\tassertImportSpecifier(val, visited.join(\" -> \"));\n\t\t\tconst { filename: importFilename, selector } = importSpecifierRegex\n\t\t\t\t.exec(val)!.groups!;\n\n\t\t\t// Resolve the correct import path\n\t\t\tlet newFilename: string | undefined;\n\t\t\tif (importFilename) {\n\t\t\t\tif (importFilename.startsWith(\"~/\")) {\n\t\t\t\t\t// This is a special import specifier that is relative to the root directory\n\t\t\t\t\t// Try to find at least one root directory that contains the referenced file\n\t\t\t\t\tif (rootDirs) {\n\t\t\t\t\t\tfor (const rootDir of rootDirs) {\n\t\t\t\t\t\t\tnewFilename = path.join(\n\t\t\t\t\t\t\t\trootDir,\n\t\t\t\t\t\t\t\timportFilename.slice(2),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (await pathExists(fs, newFilename)) {\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Try the next\n\t\t\t\t\t\t\t\tnewFilename = undefined!;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!newFilename) {\n\t\t\t\t\t\t\tthrow new ZWaveError(\n\t\t\t\t\t\t\t\t`Could not find the referenced file ${\n\t\t\t\t\t\t\t\t\timportFilename.slice(\n\t\t\t\t\t\t\t\t\t\t2,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t} in any of the root directories: ${\n\t\t\t\t\t\t\t\t\trootDirs\n\t\t\t\t\t\t\t\t\t\t.map((d) => `\\n\u00B7 ${d}`)\n\t\t\t\t\t\t\t\t\t\t.join(\"\")\n\t\t\t\t\t\t\t\t}\\n${\n\t\t\t\t\t\t\t\t\tgetImportStack(\n\t\t\t\t\t\t\t\t\t\tvisited,\n\t\t\t\t\t\t\t\t\t\tselector,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}`,\n\t\t\t\t\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new ZWaveError(\n\t\t\t\t\t\t\t`An $import specifier cannot start with ~/ when no root directory is defined!${\n\t\t\t\t\t\t\t\tgetImportStack(\n\t\t\t\t\t\t\t\t\tvisited,\n\t\t\t\t\t\t\t\t\tselector,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}`,\n\t\t\t\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnewFilename = path.join(\n\t\t\t\t\t\tpath.dirname(filename),\n\t\t\t\t\t\timportFilename,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnewFilename = filename;\n\t\t\t}\n\n\t\t\t// const importFilename = path.join(path.dirname(filename), val);\n\t\t\tconst imported = await readJsonWithTemplateInternal(\n\t\t\t\tfs,\n\t\t\t\tnewFilename,\n\t\t\t\tselector,\n\t\t\t\tvisited,\n\t\t\t\tfileCache,\n\t\t\t\trootDirs,\n\t\t\t);\n\t\t\tObject.assign(ret, imported);\n\t\t} else if (isObject(val)) {\n\t\t\t// We're looking at an object, recurse into it\n\t\t\tret[prop] = await resolveJsonImports(\n\t\t\t\tfs,\n\t\t\t\tval,\n\t\t\t\tfilename,\n\t\t\t\tvisited,\n\t\t\t\tfileCache,\n\t\t\t\trootDirs,\n\t\t\t);\n\t\t} else if (isArray(val)) {\n\t\t\t// We're looking at an array, check if there are objects we need to recurse into\n\t\t\tconst vals: unknown[] = [];\n\t\t\tfor (const v of val) {\n\t\t\t\tif (isObject(v)) {\n\t\t\t\t\tvals.push(\n\t\t\t\t\t\tawait resolveJsonImports(\n\t\t\t\t\t\t\tfs,\n\t\t\t\t\t\t\tv,\n\t\t\t\t\t\t\tfilename,\n\t\t\t\t\t\t\tvisited,\n\t\t\t\t\t\t\tfileCache,\n\t\t\t\t\t\t\trootDirs,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tvals.push(v);\n\t\t\t\t}\n\t\t\t}\n\t\t\tret[prop] = vals;\n\t\t} else {\n\t\t\tret[prop] = val;\n\t\t}\n\t}\n\treturn ret;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAAA,kBAA4C;AAC5C,oBAA0D;AAE1D,wBAAkC;AAClC,mBAAkB;AAClB,mBAAiB;AAEjB,MAAM,aAAa;AACnB,MAAM,uBACL;AAOD,MAAM,gBAA2B,oBAAI,IAAG;AAClC,SAAU,qBAAkB;AACjC,gBAAc,MAAK;AACpB;AAFgB;AAKhB,eAAsB,qBACrB,IACA,UACA,UAA4B;AAE5B,MAAI,CAAE,UAAM,0BAAW,IAAI,QAAQ,GAAI;AACtC,UAAM,IAAI,uBACT,8BAA8B,QAAQ,gBACtC,4BAAgB,eAAe;EAEjC;AAEA,MAAI,OAAO,aAAa;AAAU,eAAW,CAAC,QAAQ;AAGtD,QAAM,YAAY,IAAI,IAAI,aAAa;AACvC,QAAM,MAAM,MAAM,6BACjB,IACA,UACA,QACA,CAAA,GACA,WACA,QAAQ;AAIT,aAAW,CAACA,WAAU,MAAM,KAAK,WAAW;AAC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AQ;IAEV,eAAW,2BAAQ,GAAG,GAAG;AAExB,YAAM,OAAkB,CAAA;AACxB,iBAAW,KAAK,KAAK;AACpB,gBAAI,4BAAS,CAAC,GAAG;AAChB,eAAK,KACJ,MAAM,mBACL,IACA,GACA,UACA,SACA,WACA,QAAQ,CACR;QAEH,OAAO;AACN,eAAK,KAAK,CAAC;QACZ;MACD;AACA,UAAI,IAAI,IAAI;IACb,OAAO;AACN,UAAI,IAAI,IAAI;IACb;EACD;AACA,SAAO;AACR;AA1He;",
|
|
6
6
|
"names": ["filename", "path", "JSON5"]
|
|
7
7
|
}
|
|
@@ -74,7 +74,7 @@ async function loadManufacturersInternal(fs, externalConfigDir) {
|
|
|
74
74
|
__name(loadManufacturersInternal, "loadManufacturersInternal");
|
|
75
75
|
async function saveManufacturersInternal(fs, manufacturers) {
|
|
76
76
|
const data = {};
|
|
77
|
-
const orderedMap = new Map([...manufacturers].
|
|
77
|
+
const orderedMap = new Map([...manufacturers].toSorted((a, b) => a[0] > b[0] ? 1 : -1));
|
|
78
78
|
for (const [id, name] of orderedMap) {
|
|
79
79
|
data[(0, import_shared.formatId)(id)] = name;
|
|
80
80
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Manufacturers.ts"],
|
|
4
|
-
"sourcesContent": ["import { configDir } from \"#config_dir\";\nimport { ZWaveError, ZWaveErrorCodes, isZWaveError } from \"@zwave-js/core\";\nimport {\n\tformatId,\n\tpathExists,\n\treadTextFile,\n\tstringify,\n\twriteTextFile,\n} from \"@zwave-js/shared\";\nimport type {\n\tReadFile,\n\tReadFileSystemInfo,\n\tWriteFile,\n} from \"@zwave-js/shared/bindings\";\nimport { isObject } from \"alcalzone-shared/typeguards\";\nimport JSON5 from \"json5\";\nimport path from \"pathe\";\nimport { hexKeyRegex4Digits, throwInvalidConfig } from \"./utils_safe.js\";\n\nexport type ManufacturersMap = Map<number, string>;\n\n/** @internal */\nexport async function loadManufacturersInternal(\n\tfs: ReadFileSystemInfo & ReadFile,\n\texternalConfigDir?: string,\n): Promise<ManufacturersMap> {\n\tconst configPath = path.join(\n\t\texternalConfigDir || configDir,\n\t\t\"manufacturers.json\",\n\t);\n\n\tif (!(await pathExists(fs, configPath))) {\n\t\tthrow new ZWaveError(\n\t\t\t\"The manufacturer config file does not exist!\",\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n\ttry {\n\t\tconst fileContents = await readTextFile(fs, configPath, \"utf8\");\n\t\tconst definition = JSON5.parse(fileContents);\n\t\tif (!isObject(definition)) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"manufacturers\",\n\t\t\t\t`the database is not an object!`,\n\t\t\t);\n\t\t}\n\n\t\tconst manufacturers = new Map();\n\t\tfor (const [id, name] of Object.entries(definition)) {\n\t\t\tif (!hexKeyRegex4Digits.test(id)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"manufacturers\",\n\t\t\t\t\t`found invalid key ${id} at the root level. Manufacturer IDs must be hexadecimal lowercase.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (typeof name !== \"string\") {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"manufacturers\",\n\t\t\t\t\t`Key ${id} has a non-string manufacturer name`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst idNum = parseInt(id.slice(2), 16);\n\t\t\tmanufacturers.set(idNum, name);\n\t\t}\n\n\t\treturn manufacturers;\n\t} catch (e) {\n\t\tif (isZWaveError(e) || ((e as any).code === \"ENOENT\")) {\n\t\t\tthrow e;\n\t\t} else {\n\t\t\tthrowInvalidConfig(\"manufacturers\");\n\t\t}\n\t}\n}\n\n/**\n * Write current manufacturers map to json\n */\nexport async function saveManufacturersInternal(\n\tfs: WriteFile,\n\tmanufacturers: ManufacturersMap,\n): Promise<void> {\n\tconst data: Record<string, string> = {};\n\n\tconst orderedMap = new Map(\n\t\t[...manufacturers].
|
|
5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veError } from \"@zwave-js/core\";\nimport {\n\tformatId,\n\tpathExists,\n\treadTextFile,\n\tstringify,\n\twriteTextFile,\n} from \"@zwave-js/shared\";\nimport type {\n\tReadFile,\n\tReadFileSystemInfo,\n\tWriteFile,\n} from \"@zwave-js/shared/bindings\";\nimport { isObject } from \"alcalzone-shared/typeguards\";\nimport JSON5 from \"json5\";\nimport path from \"pathe\";\nimport { hexKeyRegex4Digits, throwInvalidConfig } from \"./utils_safe.js\";\n\nexport type ManufacturersMap = Map<number, string>;\n\n/** @internal */\nexport async function loadManufacturersInternal(\n\tfs: ReadFileSystemInfo & ReadFile,\n\texternalConfigDir?: string,\n): Promise<ManufacturersMap> {\n\tconst configPath = path.join(\n\t\texternalConfigDir || configDir,\n\t\t\"manufacturers.json\",\n\t);\n\n\tif (!(await pathExists(fs, configPath))) {\n\t\tthrow new ZWaveError(\n\t\t\t\"The manufacturer config file does not exist!\",\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n\ttry {\n\t\tconst fileContents = await readTextFile(fs, configPath, \"utf8\");\n\t\tconst definition = JSON5.parse(fileContents);\n\t\tif (!isObject(definition)) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"manufacturers\",\n\t\t\t\t`the database is not an object!`,\n\t\t\t);\n\t\t}\n\n\t\tconst manufacturers = new Map();\n\t\tfor (const [id, name] of Object.entries(definition)) {\n\t\t\tif (!hexKeyRegex4Digits.test(id)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"manufacturers\",\n\t\t\t\t\t`found invalid key ${id} at the root level. Manufacturer IDs must be hexadecimal lowercase.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (typeof name !== \"string\") {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"manufacturers\",\n\t\t\t\t\t`Key ${id} has a non-string manufacturer name`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst idNum = parseInt(id.slice(2), 16);\n\t\t\tmanufacturers.set(idNum, name);\n\t\t}\n\n\t\treturn manufacturers;\n\t} catch (e) {\n\t\tif (isZWaveError(e) || ((e as any).code === \"ENOENT\")) {\n\t\t\tthrow e;\n\t\t} else {\n\t\t\tthrowInvalidConfig(\"manufacturers\");\n\t\t}\n\t}\n}\n\n/**\n * Write current manufacturers map to json\n */\nexport async function saveManufacturersInternal(\n\tfs: WriteFile,\n\tmanufacturers: ManufacturersMap,\n): Promise<void> {\n\tconst data: Record<string, string> = {};\n\n\tconst orderedMap = new Map(\n\t\t[...manufacturers].toSorted((a, b) => (a[0] > b[0] ? 1 : -1)),\n\t);\n\n\tfor (const [id, name] of orderedMap) {\n\t\tdata[formatId(id)] = name;\n\t}\n\n\tconst configPath = path.join(configDir, \"manufacturers.json\");\n\tawait writeTextFile(fs, configPath, stringify(data, \"\\t\") + \"\\n\");\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAAA,wBAA0B;AAC1B,kBAA0D;AAC1D,oBAMO;AAMP,wBAAyB;AACzB,mBAAkB;AAClB,mBAAiB;AACjB,wBAAuD;AAKvD,eAAsB,0BACrB,IACA,mBAA0B;AAE1B,QAAM,aAAa,aAAAA,QAAK,KACvB,qBAAqB,6BACrB,oBAAoB;AAGrB,MAAI,CAAE,UAAM,0BAAW,IAAI,UAAU,GAAI;AACxC,UAAM,IAAI,uBACT,gDACA,4BAAgB,cAAc;EAEhC;AACA,MAAI;AACH,UAAM,eAAe,UAAM,4BAAa,IAAI,YAAY,MAAM;AAC9D,UAAM,aAAa,aAAAC,QAAM,MAAM,YAAY;AAC3C,QAAI,KAAC,4BAAS,UAAU,GAAG;AAC1B,gDACC,iBACA,gCAAgC;IAElC;AAEA,UAAM,gBAAgB,oBAAI,IAAG;AAC7B,eAAW,CAAC,IAAI,IAAI,KAAK,OAAO,QAAQ,UAAU,GAAG;AACpD,UAAI,CAAC,qCAAmB,KAAK,EAAE,GAAG;AACjC,kDACC,iBACA,qBAAqB,EAAE,qEAAqE;MAE9F;AACA,UAAI,OAAO,SAAS,UAAU;AAC7B,kDACC,iBACA,OAAO,EAAE,qCAAqC;MAEhD;AACA,YAAM,QAAQ,SAAS,GAAG,MAAM,CAAC,GAAG,EAAE;AACtC,oBAAc,IAAI,OAAO,IAAI;IAC9B;AAEA,WAAO;EACR,SAAS,GAAG;AACX,YAAI,0BAAa,CAAC,KAAO,EAAU,SAAS,UAAW;AACtD,YAAM;IACP,OAAO;AACN,gDAAmB,eAAe;IACnC;EACD;AACD;AAnDsB;AAwDtB,eAAsB,0BACrB,IACA,eAA+B;AAE/B,QAAM,OAA+B,CAAA;AAErC,QAAM,aAAa,IAAI,IACtB,CAAC,GAAG,aAAa,EAAE,SAAS,CAAC,GAAG,MAAO,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,EAAG,CAAC;AAG9D,aAAW,CAAC,IAAI,IAAI,KAAK,YAAY;AACpC,aAAK,wBAAS,EAAE,CAAC,IAAI;EACtB;AAEA,QAAM,aAAa,aAAAD,QAAK,KAAK,6BAAW,oBAAoB;AAC5D,YAAM,6BAAc,IAAI,gBAAY,yBAAU,MAAM,GAAI,IAAI,IAAI;AACjE;AAhBsB;",
|
|
6
6
|
"names": ["path", "JSON5"]
|
|
7
7
|
}
|
package/build/cjs/_version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "15.
|
|
1
|
+
export declare const PACKAGE_VERSION = "15.17.0";
|
|
2
2
|
//# sourceMappingURL=_version.d.ts.map
|
package/build/cjs/_version.js
CHANGED
|
@@ -21,7 +21,7 @@ __export(version_exports, {
|
|
|
21
21
|
PACKAGE_VERSION: () => PACKAGE_VERSION
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(version_exports);
|
|
24
|
-
const PACKAGE_VERSION = "15.
|
|
24
|
+
const PACKAGE_VERSION = "15.17.0";
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
27
|
PACKAGE_VERSION
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/_version.ts"],
|
|
4
|
-
"sourcesContent": ["// This file is auto-generated by the codegen maintenance script\nexport const PACKAGE_VERSION = \"15.
|
|
4
|
+
"sourcesContent": ["// This file is auto-generated by the codegen maintenance script\nexport const PACKAGE_VERSION = \"15.17.0\";\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;AACO,MAAM,kBAAkB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -469,7 +469,7 @@ class DeviceConfig {
|
|
|
469
469
|
};
|
|
470
470
|
const sortObject = /* @__PURE__ */ __name((obj) => {
|
|
471
471
|
const ret = {};
|
|
472
|
-
for (const key of Object.keys(obj).
|
|
472
|
+
for (const key of Object.keys(obj).toSorted()) {
|
|
473
473
|
ret[key] = obj[key];
|
|
474
474
|
}
|
|
475
475
|
return ret;
|
|
@@ -490,7 +490,7 @@ class DeviceConfig {
|
|
|
490
490
|
if (!map || !map.size)
|
|
491
491
|
return;
|
|
492
492
|
const getParamKey = /* @__PURE__ */ __name((param) => `${param.parameterNumber}${param.valueBitMask ? `[${(0, import_shared.num2hex)(param.valueBitMask)}]` : ""}`, "getParamKey");
|
|
493
|
-
target.paramInformation = [...map.values()].
|
|
493
|
+
target.paramInformation = [...map.values()].toSorted((a, b) => getParamKey(a).localeCompare(getParamKey(b))).map((p) => (0, import_shared.cloneDeep)(p));
|
|
494
494
|
}, "cloneParamInformationMap");
|
|
495
495
|
{
|
|
496
496
|
let ep0 = {};
|
|
@@ -545,7 +545,7 @@ class DeviceConfig {
|
|
|
545
545
|
c.removeCCs = Object.fromEntries(this.compat.removeCCs);
|
|
546
546
|
}
|
|
547
547
|
if (this.compat.treatSetAsReport) {
|
|
548
|
-
c.treatSetAsReport = [...this.compat.treatSetAsReport].
|
|
548
|
+
c.treatSetAsReport = [...this.compat.treatSetAsReport].toSorted();
|
|
549
549
|
}
|
|
550
550
|
c = sortObject(c);
|
|
551
551
|
if (Object.keys(c).length > 0) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/devices/DeviceConfig.ts"],
|
|
4
|
-
"sourcesContent": ["import { configDir } from \"#config_dir\";\nimport {\n\tZWaveError,\n\tZWaveErrorCodes,\n\tdeflateSync,\n\tdigest,\n} from \"@zwave-js/core\";\nimport {\n\tBytes,\n\ttype BytesView,\n\ttype JSONObject,\n\tcloneDeep,\n\tenumFilesRecursive,\n\tformatId,\n\tgetenv,\n\tnum2hex,\n\tpadVersion,\n\tpathExists,\n\tpick,\n\treadTextFile,\n\tstringify,\n\twriteTextFile,\n} from \"@zwave-js/shared\";\nimport type {\n\tReadFile,\n\tReadFileSystemInfo,\n\tWriteFile,\n} from \"@zwave-js/shared/bindings\";\nimport { isArray, isObject } from \"alcalzone-shared/typeguards\";\nimport JSON5 from \"json5\";\nimport path from \"pathe\";\nimport semverGt from \"semver/functions/gt.js\";\nimport { clearTemplateCache, readJsonWithTemplate } from \"../JsonTemplate.js\";\nimport type { ConfigLogger } from \"../Logger.js\";\nimport { hexKeyRegex4Digits, throwInvalidConfig } from \"../utils_safe.js\";\nimport {\n\ttype AssociationConfig,\n\tConditionalAssociationConfig,\n} from \"./AssociationConfig.js\";\nimport { type CompatConfig, ConditionalCompatConfig } from \"./CompatConfig.js\";\nimport { evaluateDeep, validateCondition } from \"./ConditionalItem.js\";\nimport {\n\ttype ConditionalPrimitive,\n\tparseConditionalPrimitive,\n} from \"./ConditionalPrimitive.js\";\nimport {\n\tConditionalDeviceMetadata,\n\ttype DeviceMetadata,\n} from \"./DeviceMetadata.js\";\nimport {\n\tConditionalEndpointConfig,\n\ttype EndpointConfig,\n} from \"./EndpointConfig.js\";\nimport {\n\ttype ConditionalParamInfoMap,\n\ttype ParamInfoMap,\n\ttype ParamInformation,\n\tparseConditionalParamInformationMap,\n} from \"./ParamInformation.js\";\nimport { ConditionalSceneConfig, type SceneConfig } from \"./SceneConfig.js\";\nimport type { DeviceID, FirmwareVersionRange } from \"./shared.js\";\n\nexport interface DeviceConfigIndexEntry {\n\tmanufacturerId: string;\n\tproductType: string;\n\tproductId: string;\n\tfirmwareVersion: FirmwareVersionRange;\n\tpreferred?: true;\n\trootDir?: string;\n\tfilename: string;\n}\n\nexport interface FulltextDeviceConfigIndexEntry {\n\tmanufacturerId: string;\n\tmanufacturer: string;\n\tlabel: string;\n\tdescription: string;\n\tproductType: string;\n\tproductId: string;\n\tfirmwareVersion: FirmwareVersionRange;\n\tpreferred?: true;\n\trootDir?: string;\n\tfilename: string;\n}\n\nexport const embeddedDevicesDir = path.join(configDir, \"devices\");\nconst fulltextIndexPath = path.join(embeddedDevicesDir, \"fulltext_index.json\");\n\nexport function getDevicesPaths(configDir: string): {\n\tdevicesDir: string;\n\tindexPath: string;\n} {\n\tconst devicesDir = path.join(configDir, \"devices\");\n\tconst indexPath = path.join(devicesDir, \"index.json\");\n\treturn { devicesDir, indexPath };\n}\n\nexport type DeviceConfigIndex = DeviceConfigIndexEntry[];\nexport type FulltextDeviceConfigIndex = FulltextDeviceConfigIndexEntry[];\n\nasync function hasChangedDeviceFiles(\n\tfs: ReadFileSystemInfo,\n\tdevicesRoot: string,\n\tdir: string,\n\tlastChange: Date,\n): Promise<boolean> {\n\t// Check if there are any files BUT index.json that were changed\n\t// or directories that were modified\n\tconst filesAndDirs = await fs.readDir(dir);\n\tfor (const f of filesAndDirs) {\n\t\tconst fullPath = path.join(dir, f);\n\n\t\tconst stat = await fs.stat(fullPath);\n\t\tif (\n\t\t\t(dir !== devicesRoot || f !== \"index.json\")\n\t\t\t&& (stat.isFile() || stat.isDirectory())\n\t\t\t&& stat.mtime > lastChange\n\t\t) {\n\t\t\treturn true;\n\t\t} else if (stat.isDirectory()) {\n\t\t\t// we need to go deeper!\n\t\t\tif (\n\t\t\t\tawait hasChangedDeviceFiles(\n\t\t\t\t\tfs,\n\t\t\t\t\tdevicesRoot,\n\t\t\t\t\tfullPath,\n\t\t\t\t\tlastChange,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Read all device config files from a given directory and return them as index entries.\n * Does not update the index itself.\n */\nasync function generateIndex<T extends Record<string, unknown>>(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tdevicesDir: string,\n\tisEmbedded: boolean,\n\textractIndexEntries: (config: DeviceConfig) => T[],\n\tlogger?: ConfigLogger,\n): Promise<(T & { filename: string; rootDir?: string })[]> {\n\tconst index: (T & { filename: string; rootDir?: string })[] = [];\n\n\tclearTemplateCache();\n\tconst configFiles = await enumFilesRecursive(\n\t\tfs,\n\t\tdevicesDir,\n\t\t(file) =>\n\t\t\tfile.endsWith(\".json\")\n\t\t\t&& !file.endsWith(\"index.json\")\n\t\t\t&& !file.includes(\"/templates/\")\n\t\t\t&& !file.includes(\"\\\\templates\\\\\"),\n\t);\n\n\t// Add the embedded devices dir as a fallback if necessary\n\tconst fallbackDirs = devicesDir !== embeddedDevicesDir\n\t\t? [embeddedDevicesDir]\n\t\t: undefined;\n\n\tfor (const file of configFiles) {\n\t\tconst relativePath = path\n\t\t\t.relative(devicesDir, file)\n\t\t\t.replaceAll(\"\\\\\", \"/\");\n\t\t// Try parsing the file\n\t\ttry {\n\t\t\tconst config = await DeviceConfig.from(\n\t\t\t\tfs,\n\t\t\t\tfile,\n\t\t\t\tisEmbedded,\n\t\t\t\t{\n\t\t\t\t\trootDir: devicesDir,\n\t\t\t\t\tfallbackDirs,\n\t\t\t\t\trelative: true,\n\t\t\t\t},\n\t\t\t);\n\t\t\t// Add the file to the index\n\t\t\tindex.push(\n\t\t\t\t...extractIndexEntries(config).map((entry) => {\n\t\t\t\t\tconst ret: T & { filename: string; rootDir?: string } = {\n\t\t\t\t\t\t...entry,\n\t\t\t\t\t\tfilename: relativePath,\n\t\t\t\t\t};\n\t\t\t\t\t// Only add the root dir to the index if necessary\n\t\t\t\t\tif (devicesDir !== embeddedDevicesDir) {\n\t\t\t\t\t\tret.rootDir = devicesDir;\n\t\t\t\t\t}\n\t\t\t\t\treturn ret;\n\t\t\t\t}),\n\t\t\t);\n\t\t} catch (e) {\n\t\t\tconst message = `Error parsing config file ${relativePath}: ${\n\t\t\t\t(e as Error).message\n\t\t\t}`;\n\t\t\t// Crash hard during tests, just print an error when in production systems.\n\t\t\t// A user could have changed a config file\n\t\t\tif (process.env.NODE_ENV === \"test\" || !!getenv(\"CI\")) {\n\t\t\t\tthrow new ZWaveError(message, ZWaveErrorCodes.Config_Invalid);\n\t\t\t} else {\n\t\t\t\tlogger?.print(message, \"error\");\n\t\t\t}\n\t\t}\n\t}\n\n\treturn index;\n}\n\nasync function loadDeviceIndexShared<T extends Record<string, unknown>>(\n\tfs: ReadFileSystemInfo & ReadFile & WriteFile,\n\tdevicesDir: string,\n\tindexPath: string,\n\textractIndexEntries: (config: DeviceConfig) => T[],\n\tlogger?: ConfigLogger,\n): Promise<(T & { filename: string })[]> {\n\t// The index file needs to be regenerated if it does not exist\n\tlet needsUpdate = !(await pathExists(fs, indexPath));\n\tlet index: (T & { filename: string })[] | undefined;\n\tlet mtimeIndex: Date | undefined;\n\t// ...or if cannot be parsed\n\tif (!needsUpdate) {\n\t\ttry {\n\t\t\tconst fileContents = await readTextFile(fs, indexPath, \"utf8\");\n\t\t\tindex = JSON5.parse(fileContents);\n\t\t\tmtimeIndex = (await fs.stat(indexPath)).mtime;\n\t\t} catch {\n\t\t\tlogger?.print(\n\t\t\t\t\"Error while parsing index file - regenerating...\",\n\t\t\t\t\"warn\",\n\t\t\t);\n\t\t\tneedsUpdate = true;\n\t\t} finally {\n\t\t\tif (!index) {\n\t\t\t\tlogger?.print(\n\t\t\t\t\t\"Index file was malformed - regenerating...\",\n\t\t\t\t\t\"warn\",\n\t\t\t\t);\n\t\t\t\tneedsUpdate = true;\n\t\t\t}\n\t\t}\n\t}\n\n\t// ...or if there were any changes in the file system\n\tif (!needsUpdate) {\n\t\tneedsUpdate = await hasChangedDeviceFiles(\n\t\t\tfs,\n\t\t\tdevicesDir,\n\t\t\tdevicesDir,\n\t\t\tmtimeIndex!,\n\t\t);\n\t\tif (needsUpdate) {\n\t\t\tlogger?.print(\n\t\t\t\t\"Device configuration files on disk changed - regenerating index...\",\n\t\t\t\t\"verbose\",\n\t\t\t);\n\t\t}\n\t}\n\n\tif (needsUpdate) {\n\t\t// Read all files from disk and generate an index\n\t\tindex = await generateIndex(\n\t\t\tfs,\n\t\t\tdevicesDir,\n\t\t\ttrue,\n\t\t\textractIndexEntries,\n\t\t\tlogger,\n\t\t);\n\t\t// Save the index to disk\n\t\ttry {\n\t\t\tawait writeTextFile(\n\t\t\t\tfs,\n\t\t\t\tpath.join(indexPath),\n\t\t\t\t`// This file is auto-generated. DO NOT edit it by hand if you don't know what you're doing!\"\n${stringify(index, \"\\t\")}\n`,\n\t\t\t\t\"utf8\",\n\t\t\t);\n\t\t\tlogger?.print(\"Device index regenerated\", \"verbose\");\n\t\t} catch (e) {\n\t\t\tlogger?.print(\n\t\t\t\t`Writing the device index to disk failed: ${\n\t\t\t\t\t(e as Error).message\n\t\t\t\t}`,\n\t\t\t\t\"error\",\n\t\t\t);\n\t\t}\n\t}\n\n\treturn index!;\n}\n\n/**\n * @internal\n * Loads the index file to quickly access the device configs.\n * Transparently handles updating the index if necessary\n */\nexport async function generatePriorityDeviceIndex(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tdeviceConfigPriorityDir: string,\n\tlogger?: ConfigLogger,\n): Promise<DeviceConfigIndex> {\n\treturn (\n\t\tawait generateIndex(\n\t\t\tfs,\n\t\t\tdeviceConfigPriorityDir,\n\t\t\tfalse,\n\t\t\t(config) =>\n\t\t\t\tconfig.devices.map((dev) => ({\n\t\t\t\t\tmanufacturerId: formatId(\n\t\t\t\t\t\tconfig.manufacturerId.toString(16),\n\t\t\t\t\t),\n\t\t\t\t\tmanufacturer: config.manufacturer,\n\t\t\t\t\tlabel: config.label,\n\t\t\t\t\tproductType: formatId(dev.productType),\n\t\t\t\t\tproductId: formatId(dev.productId),\n\t\t\t\t\tfirmwareVersion: config.firmwareVersion,\n\t\t\t\t\t...(config.preferred ? { preferred: true as const } : {}),\n\t\t\t\t\trootDir: deviceConfigPriorityDir,\n\t\t\t\t})),\n\t\t\tlogger,\n\t\t)\n\t).map(({ filename, ...entry }) => ({\n\t\t...entry,\n\t\t// The generated index makes the filenames relative to the given directory\n\t\t// but we need them to be absolute\n\t\tfilename: path.join(deviceConfigPriorityDir, filename),\n\t}));\n}\n\n/**\n * @internal\n * Loads the index file to quickly access the device configs.\n * Transparently handles updating the index if necessary\n */\nexport async function loadDeviceIndexInternal(\n\tfs: ReadFileSystemInfo & ReadFile & WriteFile,\n\tlogger?: ConfigLogger,\n\texternalConfigDir?: string,\n): Promise<DeviceConfigIndex> {\n\tconst { devicesDir, indexPath } = getDevicesPaths(\n\t\texternalConfigDir || configDir,\n\t);\n\n\treturn loadDeviceIndexShared(\n\t\tfs,\n\t\tdevicesDir,\n\t\tindexPath,\n\t\t(config) =>\n\t\t\tconfig.devices.map((dev) => ({\n\t\t\t\tmanufacturerId: formatId(config.manufacturerId.toString(16)),\n\t\t\t\tmanufacturer: config.manufacturer,\n\t\t\t\tlabel: config.label,\n\t\t\t\tproductType: formatId(dev.productType),\n\t\t\t\tproductId: formatId(dev.productId),\n\t\t\t\tfirmwareVersion: config.firmwareVersion,\n\t\t\t\t...(config.preferred ? { preferred: true as const } : {}),\n\t\t\t})),\n\t\tlogger,\n\t);\n}\n\n/**\n * @internal\n * Loads the full text index file to quickly search the device configs.\n * Transparently handles updating the index if necessary\n */\nexport async function loadFulltextDeviceIndexInternal(\n\tfs: ReadFileSystemInfo & ReadFile & WriteFile,\n\tlogger?: ConfigLogger,\n): Promise<FulltextDeviceConfigIndex> {\n\t// This method is not meant to operate with the external device index!\n\treturn loadDeviceIndexShared(\n\t\tfs,\n\t\tembeddedDevicesDir,\n\t\tfulltextIndexPath,\n\t\t(config) =>\n\t\t\tconfig.devices.map((dev) => ({\n\t\t\t\tmanufacturerId: formatId(config.manufacturerId.toString(16)),\n\t\t\t\tmanufacturer: config.manufacturer,\n\t\t\t\tlabel: config.label,\n\t\t\t\tdescription: config.description,\n\t\t\t\tproductType: formatId(dev.productType),\n\t\t\t\tproductId: formatId(dev.productId),\n\t\t\t\tfirmwareVersion: config.firmwareVersion,\n\t\t\t\t...(config.preferred ? { preferred: true as const } : {}),\n\t\t\t\trootDir: embeddedDevicesDir,\n\t\t\t})),\n\t\tlogger,\n\t);\n}\n\nfunction isHexKeyWith4Digits(val: any): val is string {\n\treturn typeof val === \"string\" && hexKeyRegex4Digits.test(val);\n}\n\nconst firmwareVersionRegex = /^\\d{1,3}\\.\\d{1,3}(\\.\\d{1,3})?$/;\nfunction isFirmwareVersion(val: any): val is string {\n\treturn (\n\t\ttypeof val === \"string\"\n\t\t&& firmwareVersionRegex.test(val)\n\t\t&& val\n\t\t\t.split(\".\")\n\t\t\t.map((str) => parseInt(str, 10))\n\t\t\t.every((num) => num >= 0 && num <= 255)\n\t);\n}\n\nconst deflateDict = Bytes.from(\n\t// Substrings appearing in the device config files in descending order of frequency\n\t// except for very short ones like 0, 1, ...\n\t// WARNING: THIS MUST NOT BE CHANGED! Doing so breaks decompressing stored hashes.\n\t[\n\t\t`\"parameterNumber\":`,\n\t\t`255`,\n\t\t`\"value\":`,\n\t\t`\"defaultValue\":`,\n\t\t`\"valueSize\":`,\n\t\t`\"maxValue\":`,\n\t\t`\"minValue\":`,\n\t\t`\"options\":`,\n\t\t`true`,\n\t\t`false`,\n\t\t`\"allowManualEntry\":`,\n\t\t`\"maxNodes\":`,\n\t\t`100`,\n\t\t`\"unsigned\":`,\n\t\t`\"paramInformation\":`,\n\t\t`\"isLifeline\":`,\n\t\t`\"seconds\"`,\n\t\t`99`,\n\t\t`127`,\n\t\t`\"%\"`,\n\t\t`65535`,\n\t\t`32767`,\n\t\t`\"minutes\"`,\n\t\t`\"endpoints\":`,\n\t\t`\"hours\"`,\n\t\t`\"multiChannel\":`,\n\t]\n\t\t.join(\"\"),\n\t\"utf8\",\n);\n\n/** This class represents a device config entry whose conditional settings have not been evaluated yet */\nexport class ConditionalDeviceConfig {\n\tpublic static async from(\n\t\tfs: ReadFileSystemInfo & ReadFile,\n\t\tfilename: string,\n\t\tisEmbedded: boolean,\n\t\toptions: {\n\t\t\trootDir: string;\n\t\t\tfallbackDirs?: string[];\n\t\t\trelative?: boolean;\n\t\t},\n\t): Promise<ConditionalDeviceConfig> {\n\t\tconst { relative, rootDir } = options;\n\n\t\tconst relativePath = relative\n\t\t\t? path.relative(rootDir, filename).replaceAll(\"\\\\\", \"/\")\n\t\t\t: filename;\n\t\tconst json = await readJsonWithTemplate(\n\t\t\tfs,\n\t\t\tfilename,\n\t\t\t[\n\t\t\t\toptions.rootDir,\n\t\t\t\t...(options.fallbackDirs ?? []),\n\t\t\t],\n\t\t);\n\t\treturn new ConditionalDeviceConfig(relativePath, isEmbedded, json);\n\t}\n\n\tpublic constructor(\n\t\tfilename: string,\n\t\tisEmbedded: boolean,\n\t\tdefinition: JSONObject,\n\t) {\n\t\tthis.filename = filename;\n\t\tthis.isEmbedded = isEmbedded;\n\n\t\tif (!isHexKeyWith4Digits(definition.manufacturerId)) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t`device`,\n\t\t\t\t`packages/config/config/devices/${filename}:\nmanufacturer id must be a lowercase hexadecimal number with 4 digits`,\n\t\t\t);\n\t\t}\n\t\tthis.manufacturerId = parseInt(definition.manufacturerId, 16);\n\n\t\tfor (const prop of [\"manufacturer\", \"label\", \"description\"] as const) {\n\t\t\tthis[prop] = parseConditionalPrimitive(\n\t\t\t\tfilename,\n\t\t\t\t\"string\",\n\t\t\t\tprop,\n\t\t\t\tdefinition[prop],\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\t!isArray(definition.devices)\n\t\t\t|| !(definition.devices as any[]).every(\n\t\t\t\t(dev: unknown) =>\n\t\t\t\t\tisObject(dev)\n\t\t\t\t\t&& isHexKeyWith4Digits(dev.productType)\n\t\t\t\t\t&& isHexKeyWith4Digits(dev.productId),\n\t\t\t)\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t`device`,\n\t\t\t\t`packages/config/config/devices/${filename}:\ndevices is malformed (not an object or type/id that is not a lowercase 4-digit hex key)`,\n\t\t\t);\n\t\t}\n\t\tthis.devices = (definition.devices as any[]).map(\n\t\t\t({ productType, productId }) => ({\n\t\t\t\tproductType: parseInt(productType, 16),\n\t\t\t\tproductId: parseInt(productId, 16),\n\t\t\t}),\n\t\t);\n\n\t\tif (\n\t\t\t!isObject(definition.firmwareVersion)\n\t\t\t|| !isFirmwareVersion(definition.firmwareVersion.min)\n\t\t\t|| !isFirmwareVersion(definition.firmwareVersion.max)\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t`device`,\n\t\t\t\t`packages/config/config/devices/${filename}:\nfirmwareVersion is malformed or invalid. Must be x.y or x.y.z where x, y, and z are integers between 0 and 255`,\n\t\t\t);\n\t\t} else {\n\t\t\tconst { min, max } = definition.firmwareVersion;\n\t\t\tif (semverGt(padVersion(min), padVersion(max))) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\nfirmwareVersion.min ${min} must not be greater than firmwareVersion.max ${max}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.firmwareVersion = { min, max };\n\t\t}\n\n\t\tif (\n\t\t\tdefinition.preferred != undefined\n\t\t\t&& definition.preferred !== true\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t`device`,\n\t\t\t\t`packages/config/config/devices/${filename}:\npreferred must be true or omitted`,\n\t\t\t);\n\t\t}\n\t\tthis.preferred = !!definition.preferred;\n\n\t\tif (definition.endpoints != undefined) {\n\t\t\tconst endpoints = new Map<number, ConditionalEndpointConfig>();\n\t\t\tif (!isObject(definition.endpoints)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\nendpoints is not an object`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (const [key, ep] of Object.entries(definition.endpoints)) {\n\t\t\t\tif (!/^\\d+$/.test(key)) {\n\t\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\t`device`,\n\t\t\t\t\t\t`packages/config/config/devices/${filename}:\nfound non-numeric endpoint index \"${key}\" in endpoints`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst epIndex = parseInt(key, 10);\n\t\t\t\tendpoints.set(\n\t\t\t\t\tepIndex,\n\t\t\t\t\tnew ConditionalEndpointConfig(this, epIndex, ep as any),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.endpoints = endpoints;\n\t\t}\n\n\t\tif (definition.associations != undefined) {\n\t\t\tconst associations = new Map<\n\t\t\t\tnumber,\n\t\t\t\tConditionalAssociationConfig\n\t\t\t>();\n\t\t\tif (!isObject(definition.associations)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\nassociations is not an object`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (\n\t\t\t\tconst [key, assocDefinition] of Object.entries(\n\t\t\t\t\tdefinition.associations,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tif (!/^[1-9][0-9]*$/.test(key)) {\n\t\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\t`device`,\n\t\t\t\t\t\t`packages/config/config/devices/${filename}:\nfound non-numeric group id \"${key}\" in associations`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst keyNum = parseInt(key, 10);\n\t\t\t\tassociations.set(\n\t\t\t\t\tkeyNum,\n\t\t\t\t\tnew ConditionalAssociationConfig(\n\t\t\t\t\t\tfilename,\n\t\t\t\t\t\tkeyNum,\n\t\t\t\t\t\tassocDefinition as any,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.associations = associations;\n\t\t}\n\n\t\tif (definition.paramInformation != undefined) {\n\t\t\tthis.paramInformation = parseConditionalParamInformationMap(\n\t\t\t\tdefinition,\n\t\t\t\tthis,\n\t\t\t);\n\t\t}\n\n\t\tif (definition.proprietary != undefined) {\n\t\t\tif (!isObject(definition.proprietary)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\nproprietary is not an object`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.proprietary = definition.proprietary;\n\t\t}\n\n\t\tif (definition.compat != undefined) {\n\t\t\tif (\n\t\t\t\tisArray(definition.compat)\n\t\t\t\t&& definition.compat.every((item: any) => isObject(item))\n\t\t\t) {\n\t\t\t\t// Make sure all conditions are valid\n\t\t\t\tfor (const entry of definition.compat) {\n\t\t\t\t\tvalidateCondition(\n\t\t\t\t\t\tfilename,\n\t\t\t\t\t\tentry,\n\t\t\t\t\t\t`At least one entry of compat contains an`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tthis.compat = definition.compat.map(\n\t\t\t\t\t(item: any) => new ConditionalCompatConfig(filename, item),\n\t\t\t\t);\n\t\t\t} else if (isObject(definition.compat)) {\n\t\t\t\tthis.compat = new ConditionalCompatConfig(\n\t\t\t\t\tfilename,\n\t\t\t\t\tdefinition.compat,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\ncompat must be an object or any array of conditional objects`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (definition.metadata != undefined) {\n\t\t\tif (!isObject(definition.metadata)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\nmetadata is not an object`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.metadata = new ConditionalDeviceMetadata(\n\t\t\t\tfilename,\n\t\t\t\tdefinition.metadata,\n\t\t\t);\n\t\t}\n\n\t\tif (definition.scenes != undefined) {\n\t\t\tconst scenes = new Map<\n\t\t\t\tnumber,\n\t\t\t\tConditionalSceneConfig\n\t\t\t>();\n\t\t\tif (!isObject(definition.scenes)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\nscenes is not an object`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (\n\t\t\t\tconst [key, sceneDefinition] of Object.entries(\n\t\t\t\t\tdefinition.scenes,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tif (!/^[1-9][0-9]*$/.test(key)) {\n\t\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\t`device`,\n\t\t\t\t\t\t`packages/config/config/devices/${filename}:\ninvalid scene id \"${key}\" in scenes - must be a positive integer (1-255)`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst keyNum = parseInt(key, 10);\n\t\t\t\tif (keyNum < 1 || keyNum > 255) {\n\t\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\t`device`,\n\t\t\t\t\t\t`packages/config/config/devices/${filename}:\nscene number ${keyNum} must be between 1 and 255`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tscenes.set(\n\t\t\t\t\tkeyNum,\n\t\t\t\t\tnew ConditionalSceneConfig(\n\t\t\t\t\t\tfilename,\n\t\t\t\t\t\tkeyNum,\n\t\t\t\t\t\tsceneDefinition as any,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.scenes = scenes;\n\t\t}\n\t}\n\n\tpublic readonly filename: string;\n\n\tpublic readonly manufacturer!: ConditionalPrimitive<string>;\n\tpublic readonly manufacturerId: number;\n\tpublic readonly label!: ConditionalPrimitive<string>;\n\tpublic readonly description!: ConditionalPrimitive<string>;\n\tpublic readonly devices: readonly {\n\t\tproductType: number;\n\t\tproductId: number;\n\t}[];\n\tpublic readonly firmwareVersion: FirmwareVersionRange;\n\t/** Mark this configuration as preferred over other config files with an overlapping firmware range */\n\tpublic readonly preferred: boolean;\n\tpublic readonly endpoints?: ReadonlyMap<number, ConditionalEndpointConfig>;\n\tpublic readonly associations?: ReadonlyMap<\n\t\tnumber,\n\t\tConditionalAssociationConfig\n\t>;\n\tpublic readonly scenes?: ReadonlyMap<number, ConditionalSceneConfig>;\n\tpublic readonly paramInformation?: ConditionalParamInfoMap;\n\t/**\n\t * Contains manufacturer-specific support information for the\n\t * ManufacturerProprietary CC\n\t */\n\tpublic readonly proprietary?: Record<string, unknown>;\n\t/** Contains compatibility options */\n\tpublic readonly compat?:\n\t\t| ConditionalCompatConfig\n\t\t| ConditionalCompatConfig[];\n\t/** Contains instructions and other metadata for the device */\n\tpublic readonly metadata?: ConditionalDeviceMetadata;\n\n\t/** Whether this is an embedded configuration or not */\n\tpublic readonly isEmbedded: boolean;\n\n\tpublic evaluate(deviceId?: DeviceID): DeviceConfig {\n\t\treturn new DeviceConfig(\n\t\t\tthis.filename,\n\t\t\tthis.isEmbedded,\n\t\t\tevaluateDeep(this.manufacturer, deviceId),\n\t\t\tthis.manufacturerId,\n\t\t\tevaluateDeep(this.label, deviceId),\n\t\t\tevaluateDeep(this.description, deviceId),\n\t\t\tthis.devices,\n\t\t\tthis.firmwareVersion,\n\t\t\tthis.preferred,\n\t\t\tevaluateDeep(this.endpoints, deviceId),\n\t\t\tevaluateDeep(this.associations, deviceId),\n\t\t\tevaluateDeep(this.scenes, deviceId),\n\t\t\tevaluateDeep(this.paramInformation, deviceId),\n\t\t\tthis.proprietary,\n\t\t\tevaluateDeep(this.compat, deviceId),\n\t\t\tevaluateDeep(this.metadata, deviceId),\n\t\t);\n\t}\n}\n\nexport class DeviceConfig {\n\tpublic static async from(\n\t\tfs: ReadFileSystemInfo & ReadFile,\n\t\tfilename: string,\n\t\tisEmbedded: boolean,\n\t\toptions: {\n\t\t\trootDir: string;\n\t\t\tfallbackDirs?: string[];\n\t\t\trelative?: boolean;\n\t\t\tdeviceId?: DeviceID;\n\t\t},\n\t): Promise<DeviceConfig> {\n\t\tconst ret = await ConditionalDeviceConfig.from(\n\t\t\tfs,\n\t\t\tfilename,\n\t\t\tisEmbedded,\n\t\t\toptions,\n\t\t);\n\t\treturn ret.evaluate(options.deviceId);\n\t}\n\n\tpublic constructor(\n\t\tfilename: string,\n\t\tisEmbedded: boolean,\n\t\tmanufacturer: string,\n\t\tmanufacturerId: number,\n\t\tlabel: string,\n\t\tdescription: string,\n\t\tdevices: readonly {\n\t\t\tproductType: number;\n\t\t\tproductId: number;\n\t\t}[],\n\t\tfirmwareVersion: FirmwareVersionRange,\n\t\tpreferred: boolean,\n\t\tendpoints?: ReadonlyMap<number, EndpointConfig>,\n\t\tassociations?: ReadonlyMap<number, AssociationConfig>,\n\t\tscenes?: ReadonlyMap<number, SceneConfig>,\n\t\tparamInformation?: ParamInfoMap,\n\t\tproprietary?: Record<string, unknown>,\n\t\tcompat?: CompatConfig,\n\t\tmetadata?: DeviceMetadata,\n\t) {\n\t\tthis.filename = filename;\n\t\tthis.isEmbedded = isEmbedded;\n\t\tthis.manufacturer = manufacturer;\n\t\tthis.manufacturerId = manufacturerId;\n\t\tthis.label = label;\n\t\tthis.description = description;\n\t\tthis.devices = devices;\n\t\tthis.firmwareVersion = firmwareVersion;\n\t\tthis.preferred = preferred;\n\t\tthis.endpoints = endpoints;\n\t\tthis.associations = associations;\n\t\tthis.scenes = scenes;\n\t\tthis.paramInformation = paramInformation;\n\t\tthis.proprietary = proprietary;\n\t\tthis.compat = compat;\n\t\tthis.metadata = metadata;\n\t}\n\n\tpublic readonly filename: string;\n\t/** Whether this is an embedded configuration or not */\n\tpublic readonly isEmbedded: boolean;\n\tpublic readonly manufacturer: string;\n\tpublic readonly manufacturerId: number;\n\tpublic readonly label: string;\n\tpublic readonly description: string;\n\tpublic readonly devices: readonly {\n\t\tproductType: number;\n\t\tproductId: number;\n\t}[];\n\tpublic readonly firmwareVersion: FirmwareVersionRange;\n\t/** Mark this configuration as preferred over other config files with an overlapping firmware range */\n\tpublic readonly preferred: boolean;\n\tpublic readonly endpoints?: ReadonlyMap<number, EndpointConfig>;\n\tpublic readonly associations?: ReadonlyMap<number, AssociationConfig>;\n\tpublic readonly scenes?: ReadonlyMap<number, SceneConfig>;\n\tpublic readonly paramInformation?: ParamInfoMap;\n\t/**\n\t * Contains manufacturer-specific support information for the\n\t * ManufacturerProprietary CC\n\t */\n\tpublic readonly proprietary?: Record<string, unknown>;\n\t/** Contains compatibility options */\n\tpublic readonly compat?: CompatConfig;\n\t/** Contains instructions and other metadata for the device */\n\tpublic readonly metadata?: DeviceMetadata;\n\n\t/** Returns the association config for a given endpoint */\n\tpublic getAssociationConfigForEndpoint(\n\t\tendpointIndex: number,\n\t\tgroup: number,\n\t): AssociationConfig | undefined {\n\t\tif (endpointIndex === 0) {\n\t\t\t// The root endpoint's associations may be configured separately or as part of \"endpoints\"\n\t\t\treturn (\n\t\t\t\tthis.associations?.get(group)\n\t\t\t\t\t?? this.endpoints?.get(0)?.associations?.get(group)\n\t\t\t);\n\t\t} else {\n\t\t\t// The other endpoints can only have a configuration as part of \"endpoints\"\n\t\t\treturn this.endpoints?.get(endpointIndex)?.associations?.get(group);\n\t\t}\n\t}\n\n\tprivate getHashable(version: 0 | 1 | 2): Record<string, any> {\n\t\t// We only need to compare the information that is persisted elsewhere:\n\t\t// - config parameters\n\t\t// - functional association settings\n\t\t// - CC-related compat flags\n\n\t\tlet hashable: Record<string, any> = {\n\t\t\t// endpoints: {\n\t\t\t// \tassociations: {},\n\t\t\t// \tparamInformation: []\n\t\t\t// },\n\t\t\t// proprietary: {},\n\t\t\t// compat: {},\n\t\t};\n\n\t\tconst sortObject = (obj: Record<string, any>) => {\n\t\t\tconst ret: Record<string, any> = {};\n\t\t\tfor (const key of Object.keys(obj).sort()) {\n\t\t\t\tret[key] = obj[key];\n\t\t\t}\n\t\t\treturn ret;\n\t\t};\n\n\t\tconst cloneAssociationConfig = (a: AssociationConfig) => {\n\t\t\treturn sortObject(\n\t\t\t\tpick(a, [\"maxNodes\", \"multiChannel\", \"isLifeline\"]),\n\t\t\t);\n\t\t};\n\t\tconst cloneAssociationMap = (\n\t\t\ttarget: Record<string, any>,\n\t\t\tmap: ReadonlyMap<number, AssociationConfig> | undefined,\n\t\t) => {\n\t\t\tif (!map || !map.size) return;\n\t\t\ttarget.associations = {};\n\t\t\tfor (const [key, value] of map) {\n\t\t\t\ttarget.associations[key] = cloneAssociationConfig(value);\n\t\t\t}\n\t\t\ttarget.associations = sortObject(target.associations);\n\t\t};\n\n\t\tconst cloneParamInformationMap = (\n\t\t\ttarget: Record<string, any>,\n\t\t\tmap: ParamInfoMap | undefined,\n\t\t) => {\n\t\t\tif (!map || !map.size) return;\n\t\t\tconst getParamKey = (param: ParamInformation) =>\n\t\t\t\t`${param.parameterNumber}${\n\t\t\t\t\tparam.valueBitMask ? `[${num2hex(param.valueBitMask)}]` : \"\"\n\t\t\t\t}`;\n\t\t\ttarget.paramInformation = [...map.values()]\n\t\t\t\t.sort((a, b) => getParamKey(a).localeCompare(getParamKey(b)))\n\t\t\t\t.map((p) => cloneDeep(p));\n\t\t};\n\n\t\t// Clone associations and param information on the root (ep 0) and endpoints\n\t\t{\n\t\t\tlet ep0: Record<string, any> = {};\n\t\t\tcloneAssociationMap(ep0, this.associations);\n\t\t\tcloneParamInformationMap(ep0, this.paramInformation);\n\t\t\tep0 = sortObject(ep0);\n\n\t\t\tif (Object.keys(ep0).length > 0) {\n\t\t\t\thashable.endpoints ??= {};\n\t\t\t\thashable.endpoints[0] = ep0;\n\t\t\t}\n\t\t}\n\n\t\tif (this.endpoints) {\n\t\t\tfor (const [index, endpoint] of this.endpoints) {\n\t\t\t\tlet ep: Record<string, any> = {};\n\n\t\t\t\tcloneAssociationMap(ep, endpoint.associations);\n\t\t\t\tcloneParamInformationMap(ep, endpoint.paramInformation);\n\n\t\t\t\tep = sortObject(ep);\n\n\t\t\t\tif (Object.keys(ep).length > 0) {\n\t\t\t\t\thashable.endpoints ??= {};\n\t\t\t\t\thashable.endpoints[index] = ep;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Clone proprietary config\n\t\tif (this.proprietary && Object.keys(this.proprietary).length > 0) {\n\t\t\thashable.proprietary = sortObject({ ...this.proprietary });\n\t\t}\n\n\t\t// Clone relevant compat flags\n\t\tif (this.compat) {\n\t\t\tlet c: Record<string, any> = {};\n\n\t\t\t// Copy some simple flags over\n\t\t\tfor (\n\t\t\t\tconst prop of [\n\t\t\t\t\t\"forceSceneControllerGroupCount\",\n\t\t\t\t\t\"mapRootReportsToEndpoint\",\n\t\t\t\t\t\"mapBasicSet\",\n\t\t\t\t\t\"preserveRootApplicationCCValueIDs\",\n\t\t\t\t\t\"preserveEndpoints\",\n\t\t\t\t\t\"removeEndpoints\",\n\t\t\t\t\t\"treatMultilevelSwitchSetAsEvent\",\n\t\t\t\t] as const\n\t\t\t) {\n\t\t\t\tif (this.compat[prop] != undefined) {\n\t\t\t\t\tc[prop] = this.compat[prop];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Copy other, more complex flags\n\t\t\tif (this.compat.overrideQueries) {\n\t\t\t\tc.overrideQueries = Object.fromEntries(\n\t\t\t\t\tthis.compat.overrideQueries[\"overrides\"],\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (this.compat.addCCs) {\n\t\t\t\tc.addCCs = Object.fromEntries(\n\t\t\t\t\t[...this.compat.addCCs].map(([ccId, def]) => [\n\t\t\t\t\t\tccId,\n\t\t\t\t\t\tObject.fromEntries(def.endpoints),\n\t\t\t\t\t]),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (this.compat.removeCCs) {\n\t\t\t\tc.removeCCs = Object.fromEntries(this.compat.removeCCs);\n\t\t\t}\n\t\t\tif (this.compat.treatSetAsReport) {\n\t\t\t\tc.treatSetAsReport = [...this.compat.treatSetAsReport].sort();\n\t\t\t}\n\n\t\t\tc = sortObject(c);\n\t\t\tif (Object.keys(c).length > 0) {\n\t\t\t\thashable.compat = c;\n\t\t\t}\n\t\t}\n\n\t\tif (version > 1) {\n\t\t\t// From version 2 and on, we ignore labels and descriptions, and load them dynamically\n\t\t\tfor (\n\t\t\t\tconst ep of Object.values<Record<string, any>>(\n\t\t\t\t\thashable.endpoints ?? {},\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tfor (const param of ep.paramInformation ?? []) {\n\t\t\t\t\tdelete param.label;\n\t\t\t\t\tdelete param.description;\n\t\t\t\t\tfor (const opt of param.options ?? []) {\n\t\t\t\t\t\tdelete opt.label;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\thashable = sortObject(hashable);\n\t\treturn hashable;\n\t}\n\n\t/**\n\t * Returns a hash code that can be used to check whether a device config has changed enough to require a re-interview.\n\t */\n\tpublic async getHash(\n\t\tversion: 0 | 1 | 2 = DeviceConfig.maxHashVersion,\n\t): Promise<BytesView> {\n\t\t// Figure out what to hash\n\t\tconst hashable = this.getHashable(version);\n\n\t\t// And create a \"hash\" from it. Older versions used a non-cryptographic hash,\n\t\t// newer versions compress a subset of the config file.\n\t\tlet hash: BytesView;\n\t\tif (version === 0) {\n\t\t\tconst buffer = Bytes.from(JSON.stringify(hashable), \"utf8\");\n\t\t\treturn await digest(\"md5\", buffer);\n\t\t} else if (version === 1) {\n\t\t\tconst buffer = Bytes.from(JSON.stringify(hashable), \"utf8\");\n\t\t\treturn await digest(\"sha-256\", buffer);\n\t\t} else {\n\t\t\thash = deflateSync(\n\t\t\t\tBytes.from(JSON.stringify(hashable), \"utf8\"),\n\t\t\t\t// Try to make the hash as small as possible\n\t\t\t\t{ level: 9, dictionary: deflateDict },\n\t\t\t);\n\t\t}\n\n\t\t// Version the hash from v2 onwards, so we can change the format in the future\n\t\tconst prefixBytes = Bytes.from(`$v${version}$`, \"utf8\");\n\t\treturn Bytes.concat([prefixBytes, hash]);\n\t}\n\n\tpublic static get maxHashVersion(): 2 {\n\t\treturn 2;\n\t}\n\n\tpublic static areHashesEqual(hash: BytesView, other: BytesView): boolean {\n\t\tconst parsedHash = parseHash(hash);\n\t\tconst parsedOther = parseHash(other);\n\t\t// If one of the hashes could not be parsed, they are not equal\n\t\tif (!parsedHash || !parsedOther) return false;\n\n\t\t// For legacy hashes, we only compare the hash data. We already make sure during\n\t\t// parsing of the cache files that we only need to compare hashes of the same version,\n\t\t// so simply comparing the contents is sufficient.\n\t\tif (parsedHash.version < 2 && parsedOther.version < 2) {\n\t\t\treturn Bytes.view(parsedHash.hashData).equals(parsedOther.hashData);\n\t\t}\n\t\t// We take care during loading to downlevel the current config hash to legacy versions if needed.\n\t\t// If we end up with just one legacy hash here, something went wrong. Just bail in that case.\n\t\tif (parsedHash.version < 2 || parsedOther.version < 2) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// This is a versioned hash. If both versions are equal, it's simple - just compare the hash data\n\t\tif (parsedHash.version === parsedOther.version) {\n\t\t\treturn Bytes.view(parsedHash.hashData).equals(parsedOther.hashData);\n\t\t}\n\n\t\t// For different versions, we have to do some case by case checks. For example, a newer hash version\n\t\t// might remove or add data into the hashable, so we cannot simply convert between versions easily.\n\t\t// Implement when that is actually needed.\n\t\treturn false;\n\t}\n}\n\nfunction parseHash(hash: BytesView): {\n\tversion: number;\n\thashData: BytesView;\n} | undefined {\n\tconst hashString = Bytes.view(hash).toString(\"utf8\");\n\tconst versionMatch = hashString.match(/^\\$v(\\d+)\\$/);\n\tif (versionMatch) {\n\t\t// This is a versioned hash\n\t\tconst version = parseInt(versionMatch[1], 10);\n\t\tconst hashData = hash.subarray(\n\t\t\t// The prefix is ASCII, so this is safe to do even in the context of UTF-8\n\t\t\tversionMatch[0].length,\n\t\t);\n\t\treturn {\n\t\t\tversion,\n\t\t\thashData,\n\t\t};\n\t}\n\n\t// This is probably an unversioned legacy hash\n\tswitch (hash.length) {\n\t\tcase 16: // MD5\n\t\t\treturn {\n\t\t\t\tversion: 0,\n\t\t\t\thashData: hash,\n\t\t\t};\n\t\tcase 32: // SHA-256\n\t\t\treturn {\n\t\t\t\tversion: 1,\n\t\t\t\thashData: hash,\n\t\t\t};\n\t\tdefault:\n\t\t\t// This is not a valid hash\n\t\t\treturn undefined;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAAA,wBAA0B;AAC1B,kBAKO;AACP,oBAeO;AAMP,wBAAkC;AAClC,mBAAkB;AAClB,mBAAiB;AACjB,gBAAqB;AACrB,0BAAyD;AAEzD,wBAAuD;AACvD,+BAGO;AACP,0BAA2D;AAC3D,6BAAgD;AAChD,kCAGO;AACP,4BAGO;AACP,4BAGO;AACP,8BAKO;AACP,yBAAyD;AA0BlD,MAAM,qBAAqB,aAAAA,QAAK,KAAK,6BAAW,SAAS;AAChE,MAAM,oBAAoB,aAAAA,QAAK,KAAK,oBAAoB,qBAAqB;AAEvE,SAAU,gBAAgBC,YAAiB;AAIhD,QAAM,aAAa,aAAAD,QAAK,KAAKC,YAAW,SAAS;AACjD,QAAM,YAAY,aAAAD,QAAK,KAAK,YAAY,YAAY;AACpD,SAAO,EAAE,YAAY,UAAS;AAC/B;AAPgB;AAYhB,eAAe,sBACd,IACA,aACA,KACA,YAAgB;AAIhB,QAAM,eAAe,MAAM,GAAG,QAAQ,GAAG;AACzC,aAAW,KAAK,cAAc;AAC7B,UAAM,WAAW,aAAAA,QAAK,KAAK,KAAK,CAAC;AAEjC,UAAM,OAAO,MAAM,GAAG,KAAK,QAAQ;AACnC,SACE,QAAQ,eAAe,MAAM,kBAC1B,KAAK,OAAM,KAAM,KAAK,YAAW,MAClC,KAAK,QAAQ,YACf;AACD,aAAO;IACR,WAAW,KAAK,YAAW,GAAI;AAE9B,UACC,MAAM,sBACL,IAC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EAEO,WAAW,iBAAc;AAC/B,WAAO;EACR;EAEO,OAAO,eAAe,MAAiB,OAAgB;AAC7D,UAAM,aAAa,UAAU,IAAI;AACjC,UAAM,cAAc,UAAU,KAAK;AAEnC,QAAI,CAAC,cAAc,CAAC;AAAa,aAAO;AAKxC,QAAI,WAAW,UAAU,KAAK,YAAY,UAAU,GAAG;AACtD,aAAO,oBAAM,KAAK,WAAW,QAAQ,EAAE,OAAO,YAAY,QAAQ;IACnE;AAGA,QAAI,WAAW,UAAU,KAAK,YAAY,UAAU,GAAG;AACtD,aAAO;IACR;AAGA,QAAI,WAAW,YAAY,YAAY,SAAS;AAC/C,aAAO,oBAAM,KAAK,WAAW,QAAQ,EAAE,OAAO,YAAY,QAAQ;IACnE;AAKA,WAAO;EACR;;AAGD,SAAS,UAAU,MAAe;AAIjC,QAAM,aAAa,oBAAM,KAAK,IAAI,EAAE,SAAS,MAAM;AACnD,QAAM,eAAe,WAAW,MAAM,aAAa;AACnD,MAAI,cAAc;AAEjB,UAAM,UAAU,SAAS,aAAa,CAAC,GAAG,EAAE;AAC5C,UAAM,WAAW,KAAK;;MAErB,aAAa,CAAC,EAAE;IAAM;AAEvB,WAAO;MACN;MACA;;EAEF;AAGA,UAAQ,KAAK,QAAQ;IACpB,KAAK;AACJ,aAAO;QACN,SAAS;QACT,UAAU;;IAEZ,KAAK;AACJ,aAAO;QACN,SAAS;QACT,UAAU;;IAEZ;AAEC,aAAO;EACT;AACD;AAnCS;",
|
|
4
|
+
"sourcesContent": ["import { configDir } from \"#config_dir\";\nimport {\n\tZWaveError,\n\tZWaveErrorCodes,\n\tdeflateSync,\n\tdigest,\n} from \"@zwave-js/core\";\nimport {\n\tBytes,\n\ttype BytesView,\n\ttype JSONObject,\n\tcloneDeep,\n\tenumFilesRecursive,\n\tformatId,\n\tgetenv,\n\tnum2hex,\n\tpadVersion,\n\tpathExists,\n\tpick,\n\treadTextFile,\n\tstringify,\n\twriteTextFile,\n} from \"@zwave-js/shared\";\nimport type {\n\tReadFile,\n\tReadFileSystemInfo,\n\tWriteFile,\n} from \"@zwave-js/shared/bindings\";\nimport { isArray, isObject } from \"alcalzone-shared/typeguards\";\nimport JSON5 from \"json5\";\nimport path from \"pathe\";\nimport semverGt from \"semver/functions/gt.js\";\nimport { clearTemplateCache, readJsonWithTemplate } from \"../JsonTemplate.js\";\nimport type { ConfigLogger } from \"../Logger.js\";\nimport { hexKeyRegex4Digits, throwInvalidConfig } from \"../utils_safe.js\";\nimport {\n\ttype AssociationConfig,\n\tConditionalAssociationConfig,\n} from \"./AssociationConfig.js\";\nimport { type CompatConfig, ConditionalCompatConfig } from \"./CompatConfig.js\";\nimport { evaluateDeep, validateCondition } from \"./ConditionalItem.js\";\nimport {\n\ttype ConditionalPrimitive,\n\tparseConditionalPrimitive,\n} from \"./ConditionalPrimitive.js\";\nimport {\n\tConditionalDeviceMetadata,\n\ttype DeviceMetadata,\n} from \"./DeviceMetadata.js\";\nimport {\n\tConditionalEndpointConfig,\n\ttype EndpointConfig,\n} from \"./EndpointConfig.js\";\nimport {\n\ttype ConditionalParamInfoMap,\n\ttype ParamInfoMap,\n\ttype ParamInformation,\n\tparseConditionalParamInformationMap,\n} from \"./ParamInformation.js\";\nimport { ConditionalSceneConfig, type SceneConfig } from \"./SceneConfig.js\";\nimport type { DeviceID, FirmwareVersionRange } from \"./shared.js\";\n\nexport interface DeviceConfigIndexEntry {\n\tmanufacturerId: string;\n\tproductType: string;\n\tproductId: string;\n\tfirmwareVersion: FirmwareVersionRange;\n\tpreferred?: true;\n\trootDir?: string;\n\tfilename: string;\n}\n\nexport interface FulltextDeviceConfigIndexEntry {\n\tmanufacturerId: string;\n\tmanufacturer: string;\n\tlabel: string;\n\tdescription: string;\n\tproductType: string;\n\tproductId: string;\n\tfirmwareVersion: FirmwareVersionRange;\n\tpreferred?: true;\n\trootDir?: string;\n\tfilename: string;\n}\n\nexport const embeddedDevicesDir = path.join(configDir, \"devices\");\nconst fulltextIndexPath = path.join(embeddedDevicesDir, \"fulltext_index.json\");\n\nexport function getDevicesPaths(configDir: string): {\n\tdevicesDir: string;\n\tindexPath: string;\n} {\n\tconst devicesDir = path.join(configDir, \"devices\");\n\tconst indexPath = path.join(devicesDir, \"index.json\");\n\treturn { devicesDir, indexPath };\n}\n\nexport type DeviceConfigIndex = DeviceConfigIndexEntry[];\nexport type FulltextDeviceConfigIndex = FulltextDeviceConfigIndexEntry[];\n\nasync function hasChangedDeviceFiles(\n\tfs: ReadFileSystemInfo,\n\tdevicesRoot: string,\n\tdir: string,\n\tlastChange: Date,\n): Promise<boolean> {\n\t// Check if there are any files BUT index.json that were changed\n\t// or directories that were modified\n\tconst filesAndDirs = await fs.readDir(dir);\n\tfor (const f of filesAndDirs) {\n\t\tconst fullPath = path.join(dir, f);\n\n\t\tconst stat = await fs.stat(fullPath);\n\t\tif (\n\t\t\t(dir !== devicesRoot || f !== \"index.json\")\n\t\t\t&& (stat.isFile() || stat.isDirectory())\n\t\t\t&& stat.mtime > lastChange\n\t\t) {\n\t\t\treturn true;\n\t\t} else if (stat.isDirectory()) {\n\t\t\t// we need to go deeper!\n\t\t\tif (\n\t\t\t\tawait hasChangedDeviceFiles(\n\t\t\t\t\tfs,\n\t\t\t\t\tdevicesRoot,\n\t\t\t\t\tfullPath,\n\t\t\t\t\tlastChange,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Read all device config files from a given directory and return them as index entries.\n * Does not update the index itself.\n */\nasync function generateIndex<T extends Record<string, unknown>>(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tdevicesDir: string,\n\tisEmbedded: boolean,\n\textractIndexEntries: (config: DeviceConfig) => T[],\n\tlogger?: ConfigLogger,\n): Promise<(T & { filename: string; rootDir?: string })[]> {\n\tconst index: (T & { filename: string; rootDir?: string })[] = [];\n\n\tclearTemplateCache();\n\tconst configFiles = await enumFilesRecursive(\n\t\tfs,\n\t\tdevicesDir,\n\t\t(file) =>\n\t\t\tfile.endsWith(\".json\")\n\t\t\t&& !file.endsWith(\"index.json\")\n\t\t\t&& !file.includes(\"/templates/\")\n\t\t\t&& !file.includes(\"\\\\templates\\\\\"),\n\t);\n\n\t// Add the embedded devices dir as a fallback if necessary\n\tconst fallbackDirs = devicesDir !== embeddedDevicesDir\n\t\t? [embeddedDevicesDir]\n\t\t: undefined;\n\n\tfor (const file of configFiles) {\n\t\tconst relativePath = path\n\t\t\t.relative(devicesDir, file)\n\t\t\t.replaceAll(\"\\\\\", \"/\");\n\t\t// Try parsing the file\n\t\ttry {\n\t\t\tconst config = await DeviceConfig.from(\n\t\t\t\tfs,\n\t\t\t\tfile,\n\t\t\t\tisEmbedded,\n\t\t\t\t{\n\t\t\t\t\trootDir: devicesDir,\n\t\t\t\t\tfallbackDirs,\n\t\t\t\t\trelative: true,\n\t\t\t\t},\n\t\t\t);\n\t\t\t// Add the file to the index\n\t\t\tindex.push(\n\t\t\t\t...extractIndexEntries(config).map((entry) => {\n\t\t\t\t\tconst ret: T & { filename: string; rootDir?: string } = {\n\t\t\t\t\t\t...entry,\n\t\t\t\t\t\tfilename: relativePath,\n\t\t\t\t\t};\n\t\t\t\t\t// Only add the root dir to the index if necessary\n\t\t\t\t\tif (devicesDir !== embeddedDevicesDir) {\n\t\t\t\t\t\tret.rootDir = devicesDir;\n\t\t\t\t\t}\n\t\t\t\t\treturn ret;\n\t\t\t\t}),\n\t\t\t);\n\t\t} catch (e) {\n\t\t\tconst message = `Error parsing config file ${relativePath}: ${\n\t\t\t\t(e as Error).message\n\t\t\t}`;\n\t\t\t// Crash hard during tests, just print an error when in production systems.\n\t\t\t// A user could have changed a config file\n\t\t\tif (process.env.NODE_ENV === \"test\" || !!getenv(\"CI\")) {\n\t\t\t\tthrow new ZWaveError(message, ZWaveErrorCodes.Config_Invalid);\n\t\t\t} else {\n\t\t\t\tlogger?.print(message, \"error\");\n\t\t\t}\n\t\t}\n\t}\n\n\treturn index;\n}\n\nasync function loadDeviceIndexShared<T extends Record<string, unknown>>(\n\tfs: ReadFileSystemInfo & ReadFile & WriteFile,\n\tdevicesDir: string,\n\tindexPath: string,\n\textractIndexEntries: (config: DeviceConfig) => T[],\n\tlogger?: ConfigLogger,\n): Promise<(T & { filename: string })[]> {\n\t// The index file needs to be regenerated if it does not exist\n\tlet needsUpdate = !(await pathExists(fs, indexPath));\n\tlet index: (T & { filename: string })[] | undefined;\n\tlet mtimeIndex: Date | undefined;\n\t// ...or if cannot be parsed\n\tif (!needsUpdate) {\n\t\ttry {\n\t\t\tconst fileContents = await readTextFile(fs, indexPath, \"utf8\");\n\t\t\tindex = JSON5.parse(fileContents);\n\t\t\tmtimeIndex = (await fs.stat(indexPath)).mtime;\n\t\t} catch {\n\t\t\tlogger?.print(\n\t\t\t\t\"Error while parsing index file - regenerating...\",\n\t\t\t\t\"warn\",\n\t\t\t);\n\t\t\tneedsUpdate = true;\n\t\t} finally {\n\t\t\tif (!index) {\n\t\t\t\tlogger?.print(\n\t\t\t\t\t\"Index file was malformed - regenerating...\",\n\t\t\t\t\t\"warn\",\n\t\t\t\t);\n\t\t\t\tneedsUpdate = true;\n\t\t\t}\n\t\t}\n\t}\n\n\t// ...or if there were any changes in the file system\n\tif (!needsUpdate) {\n\t\tneedsUpdate = await hasChangedDeviceFiles(\n\t\t\tfs,\n\t\t\tdevicesDir,\n\t\t\tdevicesDir,\n\t\t\tmtimeIndex!,\n\t\t);\n\t\tif (needsUpdate) {\n\t\t\tlogger?.print(\n\t\t\t\t\"Device configuration files on disk changed - regenerating index...\",\n\t\t\t\t\"verbose\",\n\t\t\t);\n\t\t}\n\t}\n\n\tif (needsUpdate) {\n\t\t// Read all files from disk and generate an index\n\t\tindex = await generateIndex(\n\t\t\tfs,\n\t\t\tdevicesDir,\n\t\t\ttrue,\n\t\t\textractIndexEntries,\n\t\t\tlogger,\n\t\t);\n\t\t// Save the index to disk\n\t\ttry {\n\t\t\tawait writeTextFile(\n\t\t\t\tfs,\n\t\t\t\tpath.join(indexPath),\n\t\t\t\t`// This file is auto-generated. DO NOT edit it by hand if you don't know what you're doing!\"\n${stringify(index, \"\\t\")}\n`,\n\t\t\t\t\"utf8\",\n\t\t\t);\n\t\t\tlogger?.print(\"Device index regenerated\", \"verbose\");\n\t\t} catch (e) {\n\t\t\tlogger?.print(\n\t\t\t\t`Writing the device index to disk failed: ${\n\t\t\t\t\t(e as Error).message\n\t\t\t\t}`,\n\t\t\t\t\"error\",\n\t\t\t);\n\t\t}\n\t}\n\n\treturn index!;\n}\n\n/**\n * @internal\n * Loads the index file to quickly access the device configs.\n * Transparently handles updating the index if necessary\n */\nexport async function generatePriorityDeviceIndex(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tdeviceConfigPriorityDir: string,\n\tlogger?: ConfigLogger,\n): Promise<DeviceConfigIndex> {\n\treturn (\n\t\tawait generateIndex(\n\t\t\tfs,\n\t\t\tdeviceConfigPriorityDir,\n\t\t\tfalse,\n\t\t\t(config) =>\n\t\t\t\tconfig.devices.map((dev) => ({\n\t\t\t\t\tmanufacturerId: formatId(\n\t\t\t\t\t\tconfig.manufacturerId.toString(16),\n\t\t\t\t\t),\n\t\t\t\t\tmanufacturer: config.manufacturer,\n\t\t\t\t\tlabel: config.label,\n\t\t\t\t\tproductType: formatId(dev.productType),\n\t\t\t\t\tproductId: formatId(dev.productId),\n\t\t\t\t\tfirmwareVersion: config.firmwareVersion,\n\t\t\t\t\t...(config.preferred ? { preferred: true as const } : {}),\n\t\t\t\t\trootDir: deviceConfigPriorityDir,\n\t\t\t\t})),\n\t\t\tlogger,\n\t\t)\n\t).map(({ filename, ...entry }) => ({\n\t\t...entry,\n\t\t// The generated index makes the filenames relative to the given directory\n\t\t// but we need them to be absolute\n\t\tfilename: path.join(deviceConfigPriorityDir, filename),\n\t}));\n}\n\n/**\n * @internal\n * Loads the index file to quickly access the device configs.\n * Transparently handles updating the index if necessary\n */\nexport async function loadDeviceIndexInternal(\n\tfs: ReadFileSystemInfo & ReadFile & WriteFile,\n\tlogger?: ConfigLogger,\n\texternalConfigDir?: string,\n): Promise<DeviceConfigIndex> {\n\tconst { devicesDir, indexPath } = getDevicesPaths(\n\t\texternalConfigDir || configDir,\n\t);\n\n\treturn loadDeviceIndexShared(\n\t\tfs,\n\t\tdevicesDir,\n\t\tindexPath,\n\t\t(config) =>\n\t\t\tconfig.devices.map((dev) => ({\n\t\t\t\tmanufacturerId: formatId(config.manufacturerId.toString(16)),\n\t\t\t\tmanufacturer: config.manufacturer,\n\t\t\t\tlabel: config.label,\n\t\t\t\tproductType: formatId(dev.productType),\n\t\t\t\tproductId: formatId(dev.productId),\n\t\t\t\tfirmwareVersion: config.firmwareVersion,\n\t\t\t\t...(config.preferred ? { preferred: true as const } : {}),\n\t\t\t})),\n\t\tlogger,\n\t);\n}\n\n/**\n * @internal\n * Loads the full text index file to quickly search the device configs.\n * Transparently handles updating the index if necessary\n */\nexport async function loadFulltextDeviceIndexInternal(\n\tfs: ReadFileSystemInfo & ReadFile & WriteFile,\n\tlogger?: ConfigLogger,\n): Promise<FulltextDeviceConfigIndex> {\n\t// This method is not meant to operate with the external device index!\n\treturn loadDeviceIndexShared(\n\t\tfs,\n\t\tembeddedDevicesDir,\n\t\tfulltextIndexPath,\n\t\t(config) =>\n\t\t\tconfig.devices.map((dev) => ({\n\t\t\t\tmanufacturerId: formatId(config.manufacturerId.toString(16)),\n\t\t\t\tmanufacturer: config.manufacturer,\n\t\t\t\tlabel: config.label,\n\t\t\t\tdescription: config.description,\n\t\t\t\tproductType: formatId(dev.productType),\n\t\t\t\tproductId: formatId(dev.productId),\n\t\t\t\tfirmwareVersion: config.firmwareVersion,\n\t\t\t\t...(config.preferred ? { preferred: true as const } : {}),\n\t\t\t\trootDir: embeddedDevicesDir,\n\t\t\t})),\n\t\tlogger,\n\t);\n}\n\nfunction isHexKeyWith4Digits(val: any): val is string {\n\treturn typeof val === \"string\" && hexKeyRegex4Digits.test(val);\n}\n\nconst firmwareVersionRegex = /^\\d{1,3}\\.\\d{1,3}(\\.\\d{1,3})?$/;\nfunction isFirmwareVersion(val: any): val is string {\n\treturn (\n\t\ttypeof val === \"string\"\n\t\t&& firmwareVersionRegex.test(val)\n\t\t&& val\n\t\t\t.split(\".\")\n\t\t\t.map((str) => parseInt(str, 10))\n\t\t\t.every((num) => num >= 0 && num <= 255)\n\t);\n}\n\nconst deflateDict = Bytes.from(\n\t// Substrings appearing in the device config files in descending order of frequency\n\t// except for very short ones like 0, 1, ...\n\t// WARNING: THIS MUST NOT BE CHANGED! Doing so breaks decompressing stored hashes.\n\t[\n\t\t`\"parameterNumber\":`,\n\t\t`255`,\n\t\t`\"value\":`,\n\t\t`\"defaultValue\":`,\n\t\t`\"valueSize\":`,\n\t\t`\"maxValue\":`,\n\t\t`\"minValue\":`,\n\t\t`\"options\":`,\n\t\t`true`,\n\t\t`false`,\n\t\t`\"allowManualEntry\":`,\n\t\t`\"maxNodes\":`,\n\t\t`100`,\n\t\t`\"unsigned\":`,\n\t\t`\"paramInformation\":`,\n\t\t`\"isLifeline\":`,\n\t\t`\"seconds\"`,\n\t\t`99`,\n\t\t`127`,\n\t\t`\"%\"`,\n\t\t`65535`,\n\t\t`32767`,\n\t\t`\"minutes\"`,\n\t\t`\"endpoints\":`,\n\t\t`\"hours\"`,\n\t\t`\"multiChannel\":`,\n\t]\n\t\t.join(\"\"),\n\t\"utf8\",\n);\n\n/** This class represents a device config entry whose conditional settings have not been evaluated yet */\nexport class ConditionalDeviceConfig {\n\tpublic static async from(\n\t\tfs: ReadFileSystemInfo & ReadFile,\n\t\tfilename: string,\n\t\tisEmbedded: boolean,\n\t\toptions: {\n\t\t\trootDir: string;\n\t\t\tfallbackDirs?: string[];\n\t\t\trelative?: boolean;\n\t\t},\n\t): Promise<ConditionalDeviceConfig> {\n\t\tconst { relative, rootDir } = options;\n\n\t\tconst relativePath = relative\n\t\t\t? path.relative(rootDir, filename).replaceAll(\"\\\\\", \"/\")\n\t\t\t: filename;\n\t\tconst json = await readJsonWithTemplate(\n\t\t\tfs,\n\t\t\tfilename,\n\t\t\t[\n\t\t\t\toptions.rootDir,\n\t\t\t\t...(options.fallbackDirs ?? []),\n\t\t\t],\n\t\t);\n\t\treturn new ConditionalDeviceConfig(relativePath, isEmbedded, json);\n\t}\n\n\tpublic constructor(\n\t\tfilename: string,\n\t\tisEmbedded: boolean,\n\t\tdefinition: JSONObject,\n\t) {\n\t\tthis.filename = filename;\n\t\tthis.isEmbedded = isEmbedded;\n\n\t\tif (!isHexKeyWith4Digits(definition.manufacturerId)) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t`device`,\n\t\t\t\t`packages/config/config/devices/${filename}:\nmanufacturer id must be a lowercase hexadecimal number with 4 digits`,\n\t\t\t);\n\t\t}\n\t\tthis.manufacturerId = parseInt(definition.manufacturerId, 16);\n\n\t\tfor (const prop of [\"manufacturer\", \"label\", \"description\"] as const) {\n\t\t\tthis[prop] = parseConditionalPrimitive(\n\t\t\t\tfilename,\n\t\t\t\t\"string\",\n\t\t\t\tprop,\n\t\t\t\tdefinition[prop],\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\t!isArray(definition.devices)\n\t\t\t|| !(definition.devices as any[]).every(\n\t\t\t\t(dev: unknown) =>\n\t\t\t\t\tisObject(dev)\n\t\t\t\t\t&& isHexKeyWith4Digits(dev.productType)\n\t\t\t\t\t&& isHexKeyWith4Digits(dev.productId),\n\t\t\t)\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t`device`,\n\t\t\t\t`packages/config/config/devices/${filename}:\ndevices is malformed (not an object or type/id that is not a lowercase 4-digit hex key)`,\n\t\t\t);\n\t\t}\n\t\tthis.devices = (definition.devices as any[]).map(\n\t\t\t({ productType, productId }) => ({\n\t\t\t\tproductType: parseInt(productType, 16),\n\t\t\t\tproductId: parseInt(productId, 16),\n\t\t\t}),\n\t\t);\n\n\t\tif (\n\t\t\t!isObject(definition.firmwareVersion)\n\t\t\t|| !isFirmwareVersion(definition.firmwareVersion.min)\n\t\t\t|| !isFirmwareVersion(definition.firmwareVersion.max)\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t`device`,\n\t\t\t\t`packages/config/config/devices/${filename}:\nfirmwareVersion is malformed or invalid. Must be x.y or x.y.z where x, y, and z are integers between 0 and 255`,\n\t\t\t);\n\t\t} else {\n\t\t\tconst { min, max } = definition.firmwareVersion;\n\t\t\tif (semverGt(padVersion(min), padVersion(max))) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\nfirmwareVersion.min ${min} must not be greater than firmwareVersion.max ${max}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.firmwareVersion = { min, max };\n\t\t}\n\n\t\tif (\n\t\t\tdefinition.preferred != undefined\n\t\t\t&& definition.preferred !== true\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t`device`,\n\t\t\t\t`packages/config/config/devices/${filename}:\npreferred must be true or omitted`,\n\t\t\t);\n\t\t}\n\t\tthis.preferred = !!definition.preferred;\n\n\t\tif (definition.endpoints != undefined) {\n\t\t\tconst endpoints = new Map<number, ConditionalEndpointConfig>();\n\t\t\tif (!isObject(definition.endpoints)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\nendpoints is not an object`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (const [key, ep] of Object.entries(definition.endpoints)) {\n\t\t\t\tif (!/^\\d+$/.test(key)) {\n\t\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\t`device`,\n\t\t\t\t\t\t`packages/config/config/devices/${filename}:\nfound non-numeric endpoint index \"${key}\" in endpoints`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst epIndex = parseInt(key, 10);\n\t\t\t\tendpoints.set(\n\t\t\t\t\tepIndex,\n\t\t\t\t\tnew ConditionalEndpointConfig(this, epIndex, ep as any),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.endpoints = endpoints;\n\t\t}\n\n\t\tif (definition.associations != undefined) {\n\t\t\tconst associations = new Map<\n\t\t\t\tnumber,\n\t\t\t\tConditionalAssociationConfig\n\t\t\t>();\n\t\t\tif (!isObject(definition.associations)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\nassociations is not an object`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (\n\t\t\t\tconst [key, assocDefinition] of Object.entries(\n\t\t\t\t\tdefinition.associations,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tif (!/^[1-9][0-9]*$/.test(key)) {\n\t\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\t`device`,\n\t\t\t\t\t\t`packages/config/config/devices/${filename}:\nfound non-numeric group id \"${key}\" in associations`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst keyNum = parseInt(key, 10);\n\t\t\t\tassociations.set(\n\t\t\t\t\tkeyNum,\n\t\t\t\t\tnew ConditionalAssociationConfig(\n\t\t\t\t\t\tfilename,\n\t\t\t\t\t\tkeyNum,\n\t\t\t\t\t\tassocDefinition as any,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.associations = associations;\n\t\t}\n\n\t\tif (definition.paramInformation != undefined) {\n\t\t\tthis.paramInformation = parseConditionalParamInformationMap(\n\t\t\t\tdefinition,\n\t\t\t\tthis,\n\t\t\t);\n\t\t}\n\n\t\tif (definition.proprietary != undefined) {\n\t\t\tif (!isObject(definition.proprietary)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\nproprietary is not an object`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.proprietary = definition.proprietary;\n\t\t}\n\n\t\tif (definition.compat != undefined) {\n\t\t\tif (\n\t\t\t\tisArray(definition.compat)\n\t\t\t\t&& definition.compat.every((item: any) => isObject(item))\n\t\t\t) {\n\t\t\t\t// Make sure all conditions are valid\n\t\t\t\tfor (const entry of definition.compat) {\n\t\t\t\t\tvalidateCondition(\n\t\t\t\t\t\tfilename,\n\t\t\t\t\t\tentry,\n\t\t\t\t\t\t`At least one entry of compat contains an`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tthis.compat = definition.compat.map(\n\t\t\t\t\t(item: any) => new ConditionalCompatConfig(filename, item),\n\t\t\t\t);\n\t\t\t} else if (isObject(definition.compat)) {\n\t\t\t\tthis.compat = new ConditionalCompatConfig(\n\t\t\t\t\tfilename,\n\t\t\t\t\tdefinition.compat,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\ncompat must be an object or any array of conditional objects`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (definition.metadata != undefined) {\n\t\t\tif (!isObject(definition.metadata)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\nmetadata is not an object`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.metadata = new ConditionalDeviceMetadata(\n\t\t\t\tfilename,\n\t\t\t\tdefinition.metadata,\n\t\t\t);\n\t\t}\n\n\t\tif (definition.scenes != undefined) {\n\t\t\tconst scenes = new Map<\n\t\t\t\tnumber,\n\t\t\t\tConditionalSceneConfig\n\t\t\t>();\n\t\t\tif (!isObject(definition.scenes)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}:\nscenes is not an object`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (\n\t\t\t\tconst [key, sceneDefinition] of Object.entries(\n\t\t\t\t\tdefinition.scenes,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tif (!/^[1-9][0-9]*$/.test(key)) {\n\t\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\t`device`,\n\t\t\t\t\t\t`packages/config/config/devices/${filename}:\ninvalid scene id \"${key}\" in scenes - must be a positive integer (1-255)`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst keyNum = parseInt(key, 10);\n\t\t\t\tif (keyNum < 1 || keyNum > 255) {\n\t\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\t`device`,\n\t\t\t\t\t\t`packages/config/config/devices/${filename}:\nscene number ${keyNum} must be between 1 and 255`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tscenes.set(\n\t\t\t\t\tkeyNum,\n\t\t\t\t\tnew ConditionalSceneConfig(\n\t\t\t\t\t\tfilename,\n\t\t\t\t\t\tkeyNum,\n\t\t\t\t\t\tsceneDefinition as any,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.scenes = scenes;\n\t\t}\n\t}\n\n\tpublic readonly filename: string;\n\n\tpublic readonly manufacturer!: ConditionalPrimitive<string>;\n\tpublic readonly manufacturerId: number;\n\tpublic readonly label!: ConditionalPrimitive<string>;\n\tpublic readonly description!: ConditionalPrimitive<string>;\n\tpublic readonly devices: readonly {\n\t\tproductType: number;\n\t\tproductId: number;\n\t}[];\n\tpublic readonly firmwareVersion: FirmwareVersionRange;\n\t/** Mark this configuration as preferred over other config files with an overlapping firmware range */\n\tpublic readonly preferred: boolean;\n\tpublic readonly endpoints?: ReadonlyMap<number, ConditionalEndpointConfig>;\n\tpublic readonly associations?: ReadonlyMap<\n\t\tnumber,\n\t\tConditionalAssociationConfig\n\t>;\n\tpublic readonly scenes?: ReadonlyMap<number, ConditionalSceneConfig>;\n\tpublic readonly paramInformation?: ConditionalParamInfoMap;\n\t/**\n\t * Contains manufacturer-specific support information for the\n\t * ManufacturerProprietary CC\n\t */\n\tpublic readonly proprietary?: Record<string, unknown>;\n\t/** Contains compatibility options */\n\tpublic readonly compat?:\n\t\t| ConditionalCompatConfig\n\t\t| ConditionalCompatConfig[];\n\t/** Contains instructions and other metadata for the device */\n\tpublic readonly metadata?: ConditionalDeviceMetadata;\n\n\t/** Whether this is an embedded configuration or not */\n\tpublic readonly isEmbedded: boolean;\n\n\tpublic evaluate(deviceId?: DeviceID): DeviceConfig {\n\t\treturn new DeviceConfig(\n\t\t\tthis.filename,\n\t\t\tthis.isEmbedded,\n\t\t\tevaluateDeep(this.manufacturer, deviceId),\n\t\t\tthis.manufacturerId,\n\t\t\tevaluateDeep(this.label, deviceId),\n\t\t\tevaluateDeep(this.description, deviceId),\n\t\t\tthis.devices,\n\t\t\tthis.firmwareVersion,\n\t\t\tthis.preferred,\n\t\t\tevaluateDeep(this.endpoints, deviceId),\n\t\t\tevaluateDeep(this.associations, deviceId),\n\t\t\tevaluateDeep(this.scenes, deviceId),\n\t\t\tevaluateDeep(this.paramInformation, deviceId),\n\t\t\tthis.proprietary,\n\t\t\tevaluateDeep(this.compat, deviceId),\n\t\t\tevaluateDeep(this.metadata, deviceId),\n\t\t);\n\t}\n}\n\nexport class DeviceConfig {\n\tpublic static async from(\n\t\tfs: ReadFileSystemInfo & ReadFile,\n\t\tfilename: string,\n\t\tisEmbedded: boolean,\n\t\toptions: {\n\t\t\trootDir: string;\n\t\t\tfallbackDirs?: string[];\n\t\t\trelative?: boolean;\n\t\t\tdeviceId?: DeviceID;\n\t\t},\n\t): Promise<DeviceConfig> {\n\t\tconst ret = await ConditionalDeviceConfig.from(\n\t\t\tfs,\n\t\t\tfilename,\n\t\t\tisEmbedded,\n\t\t\toptions,\n\t\t);\n\t\treturn ret.evaluate(options.deviceId);\n\t}\n\n\tpublic constructor(\n\t\tfilename: string,\n\t\tisEmbedded: boolean,\n\t\tmanufacturer: string,\n\t\tmanufacturerId: number,\n\t\tlabel: string,\n\t\tdescription: string,\n\t\tdevices: readonly {\n\t\t\tproductType: number;\n\t\t\tproductId: number;\n\t\t}[],\n\t\tfirmwareVersion: FirmwareVersionRange,\n\t\tpreferred: boolean,\n\t\tendpoints?: ReadonlyMap<number, EndpointConfig>,\n\t\tassociations?: ReadonlyMap<number, AssociationConfig>,\n\t\tscenes?: ReadonlyMap<number, SceneConfig>,\n\t\tparamInformation?: ParamInfoMap,\n\t\tproprietary?: Record<string, unknown>,\n\t\tcompat?: CompatConfig,\n\t\tmetadata?: DeviceMetadata,\n\t) {\n\t\tthis.filename = filename;\n\t\tthis.isEmbedded = isEmbedded;\n\t\tthis.manufacturer = manufacturer;\n\t\tthis.manufacturerId = manufacturerId;\n\t\tthis.label = label;\n\t\tthis.description = description;\n\t\tthis.devices = devices;\n\t\tthis.firmwareVersion = firmwareVersion;\n\t\tthis.preferred = preferred;\n\t\tthis.endpoints = endpoints;\n\t\tthis.associations = associations;\n\t\tthis.scenes = scenes;\n\t\tthis.paramInformation = paramInformation;\n\t\tthis.proprietary = proprietary;\n\t\tthis.compat = compat;\n\t\tthis.metadata = metadata;\n\t}\n\n\tpublic readonly filename: string;\n\t/** Whether this is an embedded configuration or not */\n\tpublic readonly isEmbedded: boolean;\n\tpublic readonly manufacturer: string;\n\tpublic readonly manufacturerId: number;\n\tpublic readonly label: string;\n\tpublic readonly description: string;\n\tpublic readonly devices: readonly {\n\t\tproductType: number;\n\t\tproductId: number;\n\t}[];\n\tpublic readonly firmwareVersion: FirmwareVersionRange;\n\t/** Mark this configuration as preferred over other config files with an overlapping firmware range */\n\tpublic readonly preferred: boolean;\n\tpublic readonly endpoints?: ReadonlyMap<number, EndpointConfig>;\n\tpublic readonly associations?: ReadonlyMap<number, AssociationConfig>;\n\tpublic readonly scenes?: ReadonlyMap<number, SceneConfig>;\n\tpublic readonly paramInformation?: ParamInfoMap;\n\t/**\n\t * Contains manufacturer-specific support information for the\n\t * ManufacturerProprietary CC\n\t */\n\tpublic readonly proprietary?: Record<string, unknown>;\n\t/** Contains compatibility options */\n\tpublic readonly compat?: CompatConfig;\n\t/** Contains instructions and other metadata for the device */\n\tpublic readonly metadata?: DeviceMetadata;\n\n\t/** Returns the association config for a given endpoint */\n\tpublic getAssociationConfigForEndpoint(\n\t\tendpointIndex: number,\n\t\tgroup: number,\n\t): AssociationConfig | undefined {\n\t\tif (endpointIndex === 0) {\n\t\t\t// The root endpoint's associations may be configured separately or as part of \"endpoints\"\n\t\t\treturn (\n\t\t\t\tthis.associations?.get(group)\n\t\t\t\t\t?? this.endpoints?.get(0)?.associations?.get(group)\n\t\t\t);\n\t\t} else {\n\t\t\t// The other endpoints can only have a configuration as part of \"endpoints\"\n\t\t\treturn this.endpoints?.get(endpointIndex)?.associations?.get(group);\n\t\t}\n\t}\n\n\tprivate getHashable(version: 0 | 1 | 2): Record<string, any> {\n\t\t// We only need to compare the information that is persisted elsewhere:\n\t\t// - config parameters\n\t\t// - functional association settings\n\t\t// - CC-related compat flags\n\n\t\tlet hashable: Record<string, any> = {\n\t\t\t// endpoints: {\n\t\t\t// \tassociations: {},\n\t\t\t// \tparamInformation: []\n\t\t\t// },\n\t\t\t// proprietary: {},\n\t\t\t// compat: {},\n\t\t};\n\n\t\tconst sortObject = (obj: Record<string, any>) => {\n\t\t\tconst ret: Record<string, any> = {};\n\t\t\tfor (const key of Object.keys(obj).toSorted()) {\n\t\t\t\tret[key] = obj[key];\n\t\t\t}\n\t\t\treturn ret;\n\t\t};\n\n\t\tconst cloneAssociationConfig = (a: AssociationConfig) => {\n\t\t\treturn sortObject(\n\t\t\t\tpick(a, [\"maxNodes\", \"multiChannel\", \"isLifeline\"]),\n\t\t\t);\n\t\t};\n\t\tconst cloneAssociationMap = (\n\t\t\ttarget: Record<string, any>,\n\t\t\tmap: ReadonlyMap<number, AssociationConfig> | undefined,\n\t\t) => {\n\t\t\tif (!map || !map.size) return;\n\t\t\ttarget.associations = {};\n\t\t\tfor (const [key, value] of map) {\n\t\t\t\ttarget.associations[key] = cloneAssociationConfig(value);\n\t\t\t}\n\t\t\ttarget.associations = sortObject(target.associations);\n\t\t};\n\n\t\tconst cloneParamInformationMap = (\n\t\t\ttarget: Record<string, any>,\n\t\t\tmap: ParamInfoMap | undefined,\n\t\t) => {\n\t\t\tif (!map || !map.size) return;\n\t\t\tconst getParamKey = (param: ParamInformation) =>\n\t\t\t\t`${param.parameterNumber}${\n\t\t\t\t\tparam.valueBitMask ? `[${num2hex(param.valueBitMask)}]` : \"\"\n\t\t\t\t}`;\n\t\t\ttarget.paramInformation = [...map.values()]\n\t\t\t\t.toSorted((a, b) =>\n\t\t\t\t\tgetParamKey(a).localeCompare(getParamKey(b))\n\t\t\t\t)\n\t\t\t\t.map((p) => cloneDeep(p));\n\t\t};\n\n\t\t// Clone associations and param information on the root (ep 0) and endpoints\n\t\t{\n\t\t\tlet ep0: Record<string, any> = {};\n\t\t\tcloneAssociationMap(ep0, this.associations);\n\t\t\tcloneParamInformationMap(ep0, this.paramInformation);\n\t\t\tep0 = sortObject(ep0);\n\n\t\t\tif (Object.keys(ep0).length > 0) {\n\t\t\t\thashable.endpoints ??= {};\n\t\t\t\thashable.endpoints[0] = ep0;\n\t\t\t}\n\t\t}\n\n\t\tif (this.endpoints) {\n\t\t\tfor (const [index, endpoint] of this.endpoints) {\n\t\t\t\tlet ep: Record<string, any> = {};\n\n\t\t\t\tcloneAssociationMap(ep, endpoint.associations);\n\t\t\t\tcloneParamInformationMap(ep, endpoint.paramInformation);\n\n\t\t\t\tep = sortObject(ep);\n\n\t\t\t\tif (Object.keys(ep).length > 0) {\n\t\t\t\t\thashable.endpoints ??= {};\n\t\t\t\t\thashable.endpoints[index] = ep;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Clone proprietary config\n\t\tif (this.proprietary && Object.keys(this.proprietary).length > 0) {\n\t\t\thashable.proprietary = sortObject({ ...this.proprietary });\n\t\t}\n\n\t\t// Clone relevant compat flags\n\t\tif (this.compat) {\n\t\t\tlet c: Record<string, any> = {};\n\n\t\t\t// Copy some simple flags over\n\t\t\tfor (\n\t\t\t\tconst prop of [\n\t\t\t\t\t\"forceSceneControllerGroupCount\",\n\t\t\t\t\t\"mapRootReportsToEndpoint\",\n\t\t\t\t\t\"mapBasicSet\",\n\t\t\t\t\t\"preserveRootApplicationCCValueIDs\",\n\t\t\t\t\t\"preserveEndpoints\",\n\t\t\t\t\t\"removeEndpoints\",\n\t\t\t\t\t\"treatMultilevelSwitchSetAsEvent\",\n\t\t\t\t] as const\n\t\t\t) {\n\t\t\t\tif (this.compat[prop] != undefined) {\n\t\t\t\t\tc[prop] = this.compat[prop];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Copy other, more complex flags\n\t\t\tif (this.compat.overrideQueries) {\n\t\t\t\tc.overrideQueries = Object.fromEntries(\n\t\t\t\t\tthis.compat.overrideQueries[\"overrides\"],\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (this.compat.addCCs) {\n\t\t\t\tc.addCCs = Object.fromEntries(\n\t\t\t\t\t[...this.compat.addCCs].map(([ccId, def]) => [\n\t\t\t\t\t\tccId,\n\t\t\t\t\t\tObject.fromEntries(def.endpoints),\n\t\t\t\t\t]),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (this.compat.removeCCs) {\n\t\t\t\tc.removeCCs = Object.fromEntries(this.compat.removeCCs);\n\t\t\t}\n\t\t\tif (this.compat.treatSetAsReport) {\n\t\t\t\tc.treatSetAsReport = [...this.compat.treatSetAsReport]\n\t\t\t\t\t.toSorted();\n\t\t\t}\n\n\t\t\tc = sortObject(c);\n\t\t\tif (Object.keys(c).length > 0) {\n\t\t\t\thashable.compat = c;\n\t\t\t}\n\t\t}\n\n\t\tif (version > 1) {\n\t\t\t// From version 2 and on, we ignore labels and descriptions, and load them dynamically\n\t\t\tfor (\n\t\t\t\tconst ep of Object.values<Record<string, any>>(\n\t\t\t\t\thashable.endpoints ?? {},\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tfor (const param of ep.paramInformation ?? []) {\n\t\t\t\t\tdelete param.label;\n\t\t\t\t\tdelete param.description;\n\t\t\t\t\tfor (const opt of param.options ?? []) {\n\t\t\t\t\t\tdelete opt.label;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\thashable = sortObject(hashable);\n\t\treturn hashable;\n\t}\n\n\t/**\n\t * Returns a hash code that can be used to check whether a device config has changed enough to require a re-interview.\n\t */\n\tpublic async getHash(\n\t\tversion: 0 | 1 | 2 = DeviceConfig.maxHashVersion,\n\t): Promise<BytesView> {\n\t\t// Figure out what to hash\n\t\tconst hashable = this.getHashable(version);\n\n\t\t// And create a \"hash\" from it. Older versions used a non-cryptographic hash,\n\t\t// newer versions compress a subset of the config file.\n\t\tlet hash: BytesView;\n\t\tif (version === 0) {\n\t\t\tconst buffer = Bytes.from(JSON.stringify(hashable), \"utf8\");\n\t\t\treturn await digest(\"md5\", buffer);\n\t\t} else if (version === 1) {\n\t\t\tconst buffer = Bytes.from(JSON.stringify(hashable), \"utf8\");\n\t\t\treturn await digest(\"sha-256\", buffer);\n\t\t} else {\n\t\t\thash = deflateSync(\n\t\t\t\tBytes.from(JSON.stringify(hashable), \"utf8\"),\n\t\t\t\t// Try to make the hash as small as possible\n\t\t\t\t{ level: 9, dictionary: deflateDict },\n\t\t\t);\n\t\t}\n\n\t\t// Version the hash from v2 onwards, so we can change the format in the future\n\t\tconst prefixBytes = Bytes.from(`$v${version}$`, \"utf8\");\n\t\treturn Bytes.concat([prefixBytes, hash]);\n\t}\n\n\tpublic static get maxHashVersion(): 2 {\n\t\treturn 2;\n\t}\n\n\tpublic static areHashesEqual(hash: BytesView, other: BytesView): boolean {\n\t\tconst parsedHash = parseHash(hash);\n\t\tconst parsedOther = parseHash(other);\n\t\t// If one of the hashes could not be parsed, they are not equal\n\t\tif (!parsedHash || !parsedOther) return false;\n\n\t\t// For legacy hashes, we only compare the hash data. We already make sure during\n\t\t// parsing of the cache files that we only need to compare hashes of the same version,\n\t\t// so simply comparing the contents is sufficient.\n\t\tif (parsedHash.version < 2 && parsedOther.version < 2) {\n\t\t\treturn Bytes.view(parsedHash.hashData).equals(parsedOther.hashData);\n\t\t}\n\t\t// We take care during loading to downlevel the current config hash to legacy versions if needed.\n\t\t// If we end up with just one legacy hash here, something went wrong. Just bail in that case.\n\t\tif (parsedHash.version < 2 || parsedOther.version < 2) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// This is a versioned hash. If both versions are equal, it's simple - just compare the hash data\n\t\tif (parsedHash.version === parsedOther.version) {\n\t\t\treturn Bytes.view(parsedHash.hashData).equals(parsedOther.hashData);\n\t\t}\n\n\t\t// For different versions, we have to do some case by case checks. For example, a newer hash version\n\t\t// might remove or add data into the hashable, so we cannot simply convert between versions easily.\n\t\t// Implement when that is actually needed.\n\t\treturn false;\n\t}\n}\n\nfunction parseHash(hash: BytesView): {\n\tversion: number;\n\thashData: BytesView;\n} | undefined {\n\tconst hashString = Bytes.view(hash).toString(\"utf8\");\n\tconst versionMatch = hashString.match(/^\\$v(\\d+)\\$/);\n\tif (versionMatch) {\n\t\t// This is a versioned hash\n\t\tconst version = parseInt(versionMatch[1], 10);\n\t\tconst hashData = hash.subarray(\n\t\t\t// The prefix is ASCII, so this is safe to do even in the context of UTF-8\n\t\t\tversionMatch[0].length,\n\t\t);\n\t\treturn {\n\t\t\tversion,\n\t\t\thashData,\n\t\t};\n\t}\n\n\t// This is probably an unversioned legacy hash\n\tswitch (hash.length) {\n\t\tcase 16: // MD5\n\t\t\treturn {\n\t\t\t\tversion: 0,\n\t\t\t\thashData: hash,\n\t\t\t};\n\t\tcase 32: // SHA-256\n\t\t\treturn {\n\t\t\t\tversion: 1,\n\t\t\t\thashData: hash,\n\t\t\t};\n\t\tdefault:\n\t\t\t// This is not a valid hash\n\t\t\treturn undefined;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAAA,wBAA0B;AAC1B,kBAKO;AACP,oBAeO;AAMP,wBAAkC;AAClC,mBAAkB;AAClB,mBAAiB;AACjB,gBAAqB;AACrB,0BAAyD;AAEzD,wBAAuD;AACvD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R;;AAGD,SAAS,UAAU,MAAe;AAIjC,QAAM,aAAa,oBAAM,KAAK,IAAI,EAAE,SAAS,MAAM;AACnD,QAAM,eAAe,WAAW,MAAM,aAAa;AACnD,MAAI,cAAc;AAEjB,UAAM,UAAU,SAAS,aAAa,CAAC,GAAG,EAAE;AAC5C,UAAM,WAAW,KAAK;;MAErB,aAAa,CAAC,EAAE;IAAM;AAEvB,WAAO;MACN;MACA;;EAEF;AAGA,UAAQ,KAAK,QAAQ;IACpB,KAAK;AACJ,aAAO;QACN,SAAS;QACT,UAAU;;IAEZ,KAAK;AACJ,aAAO;QACN,SAAS;QACT,UAAU;;IAEZ;AAEC,aAAO;EACT;AACD;AAnCS;",
|
|
6
6
|
"names": ["path", "configDir", "JSON5", "semverGt"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/devices/DeviceConfig.unit._test.ts"],
|
|
4
|
-
"sourcesContent": ["// FIXME: These tests are incompatible with auto-generating the index file\n\n// import fsExtra from \"fs-extra\";\n// import path from \"path\";\n// import { ConfigManager } from \"./ConfigManager\";\n// import { configDir } from \"./utils\";\n\n// jest.mock(\"fs-extra\");\n// const readFileMock = fsExtra.readFile as jest.Mock;\n// const pathExistsMock = fsExtra.pathExists as jest.Mock;\n\n// describe(\"lib/config/Devices\", () => {\n// \tdescribe(\"lookupDevice (with missing index)\", () => {\n// \t\tlet configManager: ConfigManager;\n\n// \t\tbeforeAll(async () => {\n// \t\t\tpathExistsMock.mockClear();\n// \t\t\treadFileMock.mockClear();\n// \t\t\tpathExistsMock.mockResolvedValue(false);\n// \t\t\treadFileMock.mockRejectedValue(new Error(\"File does not exist\"));\n\n// \t\t\tconfigManager = new ConfigManager();\n// \t\t\tawait configManager.loadDeviceIndex();\n// \t\t});\n\n// \t\tit(\"returns undefined instead of throwing\", async () => {\n// \t\t\tawait expect(\n// \t\t\t\tconfigManager.lookupDevice(1, 2, 3),\n// \t\t\t).resolves.toBeUndefined();\n// \t\t\tawait expect(\n// \t\t\t\tconfigManager.lookupDevice(1, 2, 5),\n// \t\t\t).resolves.toBeUndefined();\n// \t\t});\n// \t});\n\n// \tdescribe(\"lookupDevice (with missing file)\", () => {\n// \t\tlet configManager: ConfigManager;\n\n// \t\tbeforeAll(async () => {\n// \t\t\tpathExistsMock.mockClear();\n// \t\t\treadFileMock.mockClear();\n// \t\t\tpathExistsMock.mockResolvedValueOnce(true).mockResolvedValue(false);\n// \t\t\treadFileMock\n// \t\t\t\t.mockResolvedValueOnce(\n// \t\t\t\t\t// Index\n// \t\t\t\t\tJSON.stringify([\n// \t\t\t\t\t\t{\n// \t\t\t\t\t\t\tmanufacturerId: \"0x0abc\",\n// \t\t\t\t\t\t\tproductType: \"0x0001\",\n// \t\t\t\t\t\t\tproductId: \"0x0023\",\n// \t\t\t\t\t\t\tfirmwareVersion: {\n// \t\t\t\t\t\t\t\tmin: \"0.0\",\n// \t\t\t\t\t\t\t\tmax: \"255.255\",\n// \t\t\t\t\t\t\t},\n// \t\t\t\t\t\t\tfilename: \"0x0abc/abcdef.json\",\n// \t\t\t\t\t\t},\n// \t\t\t\t\t]),\n// \t\t\t\t)\n// \t\t\t\t.mockRejectedValue(new Error(\"File does not exist\"));\n\n// \t\t\tconfigManager = new ConfigManager();\n// \t\t\tawait configManager.loadDeviceIndex();\n// \t\t});\n\n// \t\tit(\"returns undefined instead of throwing\", async () => {\n// \t\t\tawait expect(\n// \t\t\t\tconfigManager.lookupDevice(0x0abc, 0x0001, 0x0023),\n// \t\t\t).resolves.toBeUndefined();\n// \t\t});\n// \t});\n\n// \tdescribe(\"lookupManufacturer (with invalid file)\", () => {\n// \t\tlet configManager: ConfigManager;\n\n// \t\tbeforeAll(async () => {\n// \t\t\tpathExistsMock.mockClear();\n// \t\t\treadFileMock.mockClear();\n// \t\t\tpathExistsMock.mockResolvedValue(true);\n// \t\t\treadFileMock\n// \t\t\t\t.mockResolvedValueOnce(\n// \t\t\t\t\t// Index\n// \t\t\t\t\tJSON.stringify([\n// \t\t\t\t\t\t{\n// \t\t\t\t\t\t\tmanufacturerId: \"0x0abc\",\n// \t\t\t\t\t\t\tproductType: \"0x0001\",\n// \t\t\t\t\t\t\tproductId: \"0x0023\",\n// \t\t\t\t\t\t\tfirmwareVersion: {\n// \t\t\t\t\t\t\t\tmin: \"0.0\",\n// \t\t\t\t\t\t\t\tmax: \"255.255\",\n// \t\t\t\t\t\t\t},\n// \t\t\t\t\t\t\tfilename: \"0x0abc/abcdef.json\",\n// \t\t\t\t\t\t},\n// \t\t\t\t\t]),\n// \t\t\t\t)\n// \t\t\t\t.mockResolvedValueOnce(`{`);\n\n// \t\t\tconfigManager = new ConfigManager();\n// \t\t\tawait configManager.loadDeviceIndex();\n// \t\t});\n\n// \t\tit(\"returns undefined instead of throwing\", async () => {\n// \t\t\tawait expect(\n// \t\t\t\tconfigManager.lookupDevice(0x0abc, 0x0001, 0x0023),\n// \t\t\t).resolves.toBeUndefined();\n// \t\t});\n// \t});\n\n// \tdescribe(\"lookupDevice()\", () => {\n// \t\tlet configManager: ConfigManager;\n\n// \t\tbeforeAll(async () => {\n// \t\t\treadFileMock.mockReset();\n// \t\t\treadFileMock.mockResolvedValueOnce(\n// \t\t\t\t// Index\n// \t\t\t\tJSON.stringify([\n// \t\t\t\t\t{\n// \t\t\t\t\t\tmanufacturerId: \"0x0abc\",\n// \t\t\t\t\t\tproductType: \"0x0001\",\n// \t\t\t\t\t\tproductId: \"0x0023\",\n// \t\t\t\t\t\tfirmwareVersion: {\n// \t\t\t\t\t\t\tmin: \"0.0\",\n// \t\t\t\t\t\t\tmax: \"255.255\",\n// \t\t\t\t\t\t},\n// \t\t\t\t\t\tfilename: \"0x0abc/abcdef.json\",\n// \t\t\t\t\t},\n// \t\t\t\t\t{\n// \t\t\t\t\t\tmanufacturerId: \"0x0abc\",\n// \t\t\t\t\t\tproductType: \"0x0001\",\n// \t\t\t\t\t\tproductId: \"0x0034\",\n// \t\t\t\t\t\tfirmwareVersion: {\n// \t\t\t\t\t\t\tmin: \"0.0\",\n// \t\t\t\t\t\t\tmax: \"1.255\",\n// \t\t\t\t\t\t},\n// \t\t\t\t\t\tfilename: \"0x0abc/123456.json\",\n// \t\t\t\t\t},\n// \t\t\t\t\t{\n// \t\t\t\t\t\tmanufacturerId: \"0x0abc\",\n// \t\t\t\t\t\tproductType: \"0x0001\",\n// \t\t\t\t\t\tproductId: \"0x0034\",\n// \t\t\t\t\t\tfirmwareVersion: {\n// \t\t\t\t\t\t\tmin: \"2.0\",\n// \t\t\t\t\t\t\tmax: \"255.255\",\n// \t\t\t\t\t\t},\n// \t\t\t\t\t\tfilename: \"0x0abc/123456-8.json\",\n// \t\t\t\t\t},\n// \t\t\t\t]),\n// \t\t\t);\n// \t\t\tpathExistsMock.mockReset();\n// \t\t\tpathExistsMock.mockResolvedValueOnce(true);\n\n// \t\t\tconfigManager = new ConfigManager();\n// \t\t\tawait configManager.loadDeviceIndex();\n// \t\t});\n\n// \t\tbeforeEach(() => {\n// \t\t\treadFileMock.mockClear();\n// \t\t\tpathExistsMock.mockClear();\n// \t\t});\n\n// \t\tit(\"tests if the corresponding file exists\", async () => {\n// \t\t\tpathExistsMock.mockResolvedValue(false);\n// \t\t\tawait configManager.lookupDevice(0x0abc, 0x0001, 0x0023);\n// \t\t\texpect(pathExistsMock).toBeCalledTimes(1);\n// \t\t\tconst expectedPath = path.join(\n// \t\t\t\tconfigDir,\n// \t\t\t\t\"devices/0x0abc/abcdef.json\",\n// \t\t\t);\n// \t\t\texpect(pathExistsMock.mock.calls[0][0]).toBe(expectedPath);\n// \t\t});\n\n// \t\tit(\"looks up the file with the correct firmware version\", async () => {\n// \t\t\tpathExistsMock.mockResolvedValue(true);\n// \t\t\tawait configManager.lookupDevice(0x0abc, 0x0001, 0x0034, \"2.1\");\n// \t\t\texpect(pathExistsMock).toBeCalledTimes(1);\n// \t\t\tconst expectedPath = path.join(\n// \t\t\t\tconfigDir,\n// \t\t\t\t\"devices/0x0abc/123456-8.json\",\n// \t\t\t);\n// \t\t\texpect(pathExistsMock.mock.calls[0][0]).toBe(expectedPath);\n// \t\t});\n\n// \t\tit(\"returns the contents of a found file, parsed as JSON5\", async () => {\n// \t\t\t// The first attempt at reading the file should succeed\n// \t\t\tpathExistsMock.mockResolvedValue(true);\n// \t\t\t// Return a dummy file that must be parsed as JSON5\n// \t\t\treadFileMock.mockResolvedValue(\n// \t\t\t\t`// This is a minimal valid device config\n// {\n// \t\"manufacturer\": \"Test manufacturer\",\n// \t\"manufacturerId\": \"0x0abc\",\n// \t\"label\": \"LABEL\",\n// \t\"description\": \"desc rip tion\",\n// \t\"devices\": [\n// \t\t{\n// \t\t\t\"productType\": \"0x0001\",\n// \t\t\t\"productId\": \"0x0001\"\n// \t\t}\n// \t],\n// \t\"firmwareVersion\": {\n// \t\t\"min\": \"0.0\",\n// \t\t\"max\": \"255.255\"\n// \t}\n// }`,\n// \t\t\t);\n\n// \t\t\tconst result = await configManager.lookupDevice(\n// \t\t\t\t0x0abc,\n// \t\t\t\t0x0001,\n// \t\t\t\t0x0034,\n// \t\t\t\t\"2.1\",\n// \t\t\t);\n// \t\t\texpect(result).toBeDefined();\n// \t\t\texpect(result!.manufacturer).toBe(\"Test manufacturer\");\n// \t\t});\n\n// \t\tit(\"does not throw if the JSON file is invalid\", async () => {\n// \t\t\t// The first attempt at reading the file should succeed\n// \t\t\tpathExistsMock.mockResolvedValue(true);\n// \t\t\t// Return an invalid JSON file\n// \t\t\treadFileMock.mockResolvedValue(`{\"name\": }`);\n\n// \t\t\t// return undefined instead of throwing\n// \t\t\tawait expect(\n// \t\t\t\tconfigManager.lookupDevice(0x0abc, 0x0001, 0x0034, \"2.1\"),\n// \t\t\t).resolves.toBeUndefined();\n// \t\t});\n// \t});\n// });\n"],
|
|
4
|
+
"sourcesContent": ["// oxlint-disable no-empty-file\n// FIXME: These tests are incompatible with auto-generating the index file\n\n// import fsExtra from \"fs-extra\";\n// import path from \"path\";\n// import { ConfigManager } from \"./ConfigManager\";\n// import { configDir } from \"./utils\";\n\n// jest.mock(\"fs-extra\");\n// const readFileMock = fsExtra.readFile as jest.Mock;\n// const pathExistsMock = fsExtra.pathExists as jest.Mock;\n\n// describe(\"lib/config/Devices\", () => {\n// \tdescribe(\"lookupDevice (with missing index)\", () => {\n// \t\tlet configManager: ConfigManager;\n\n// \t\tbeforeAll(async () => {\n// \t\t\tpathExistsMock.mockClear();\n// \t\t\treadFileMock.mockClear();\n// \t\t\tpathExistsMock.mockResolvedValue(false);\n// \t\t\treadFileMock.mockRejectedValue(new Error(\"File does not exist\"));\n\n// \t\t\tconfigManager = new ConfigManager();\n// \t\t\tawait configManager.loadDeviceIndex();\n// \t\t});\n\n// \t\tit(\"returns undefined instead of throwing\", async () => {\n// \t\t\tawait expect(\n// \t\t\t\tconfigManager.lookupDevice(1, 2, 3),\n// \t\t\t).resolves.toBeUndefined();\n// \t\t\tawait expect(\n// \t\t\t\tconfigManager.lookupDevice(1, 2, 5),\n// \t\t\t).resolves.toBeUndefined();\n// \t\t});\n// \t});\n\n// \tdescribe(\"lookupDevice (with missing file)\", () => {\n// \t\tlet configManager: ConfigManager;\n\n// \t\tbeforeAll(async () => {\n// \t\t\tpathExistsMock.mockClear();\n// \t\t\treadFileMock.mockClear();\n// \t\t\tpathExistsMock.mockResolvedValueOnce(true).mockResolvedValue(false);\n// \t\t\treadFileMock\n// \t\t\t\t.mockResolvedValueOnce(\n// \t\t\t\t\t// Index\n// \t\t\t\t\tJSON.stringify([\n// \t\t\t\t\t\t{\n// \t\t\t\t\t\t\tmanufacturerId: \"0x0abc\",\n// \t\t\t\t\t\t\tproductType: \"0x0001\",\n// \t\t\t\t\t\t\tproductId: \"0x0023\",\n// \t\t\t\t\t\t\tfirmwareVersion: {\n// \t\t\t\t\t\t\t\tmin: \"0.0\",\n// \t\t\t\t\t\t\t\tmax: \"255.255\",\n// \t\t\t\t\t\t\t},\n// \t\t\t\t\t\t\tfilename: \"0x0abc/abcdef.json\",\n// \t\t\t\t\t\t},\n// \t\t\t\t\t]),\n// \t\t\t\t)\n// \t\t\t\t.mockRejectedValue(new Error(\"File does not exist\"));\n\n// \t\t\tconfigManager = new ConfigManager();\n// \t\t\tawait configManager.loadDeviceIndex();\n// \t\t});\n\n// \t\tit(\"returns undefined instead of throwing\", async () => {\n// \t\t\tawait expect(\n// \t\t\t\tconfigManager.lookupDevice(0x0abc, 0x0001, 0x0023),\n// \t\t\t).resolves.toBeUndefined();\n// \t\t});\n// \t});\n\n// \tdescribe(\"lookupManufacturer (with invalid file)\", () => {\n// \t\tlet configManager: ConfigManager;\n\n// \t\tbeforeAll(async () => {\n// \t\t\tpathExistsMock.mockClear();\n// \t\t\treadFileMock.mockClear();\n// \t\t\tpathExistsMock.mockResolvedValue(true);\n// \t\t\treadFileMock\n// \t\t\t\t.mockResolvedValueOnce(\n// \t\t\t\t\t// Index\n// \t\t\t\t\tJSON.stringify([\n// \t\t\t\t\t\t{\n// \t\t\t\t\t\t\tmanufacturerId: \"0x0abc\",\n// \t\t\t\t\t\t\tproductType: \"0x0001\",\n// \t\t\t\t\t\t\tproductId: \"0x0023\",\n// \t\t\t\t\t\t\tfirmwareVersion: {\n// \t\t\t\t\t\t\t\tmin: \"0.0\",\n// \t\t\t\t\t\t\t\tmax: \"255.255\",\n// \t\t\t\t\t\t\t},\n// \t\t\t\t\t\t\tfilename: \"0x0abc/abcdef.json\",\n// \t\t\t\t\t\t},\n// \t\t\t\t\t]),\n// \t\t\t\t)\n// \t\t\t\t.mockResolvedValueOnce(`{`);\n\n// \t\t\tconfigManager = new ConfigManager();\n// \t\t\tawait configManager.loadDeviceIndex();\n// \t\t});\n\n// \t\tit(\"returns undefined instead of throwing\", async () => {\n// \t\t\tawait expect(\n// \t\t\t\tconfigManager.lookupDevice(0x0abc, 0x0001, 0x0023),\n// \t\t\t).resolves.toBeUndefined();\n// \t\t});\n// \t});\n\n// \tdescribe(\"lookupDevice()\", () => {\n// \t\tlet configManager: ConfigManager;\n\n// \t\tbeforeAll(async () => {\n// \t\t\treadFileMock.mockReset();\n// \t\t\treadFileMock.mockResolvedValueOnce(\n// \t\t\t\t// Index\n// \t\t\t\tJSON.stringify([\n// \t\t\t\t\t{\n// \t\t\t\t\t\tmanufacturerId: \"0x0abc\",\n// \t\t\t\t\t\tproductType: \"0x0001\",\n// \t\t\t\t\t\tproductId: \"0x0023\",\n// \t\t\t\t\t\tfirmwareVersion: {\n// \t\t\t\t\t\t\tmin: \"0.0\",\n// \t\t\t\t\t\t\tmax: \"255.255\",\n// \t\t\t\t\t\t},\n// \t\t\t\t\t\tfilename: \"0x0abc/abcdef.json\",\n// \t\t\t\t\t},\n// \t\t\t\t\t{\n// \t\t\t\t\t\tmanufacturerId: \"0x0abc\",\n// \t\t\t\t\t\tproductType: \"0x0001\",\n// \t\t\t\t\t\tproductId: \"0x0034\",\n// \t\t\t\t\t\tfirmwareVersion: {\n// \t\t\t\t\t\t\tmin: \"0.0\",\n// \t\t\t\t\t\t\tmax: \"1.255\",\n// \t\t\t\t\t\t},\n// \t\t\t\t\t\tfilename: \"0x0abc/123456.json\",\n// \t\t\t\t\t},\n// \t\t\t\t\t{\n// \t\t\t\t\t\tmanufacturerId: \"0x0abc\",\n// \t\t\t\t\t\tproductType: \"0x0001\",\n// \t\t\t\t\t\tproductId: \"0x0034\",\n// \t\t\t\t\t\tfirmwareVersion: {\n// \t\t\t\t\t\t\tmin: \"2.0\",\n// \t\t\t\t\t\t\tmax: \"255.255\",\n// \t\t\t\t\t\t},\n// \t\t\t\t\t\tfilename: \"0x0abc/123456-8.json\",\n// \t\t\t\t\t},\n// \t\t\t\t]),\n// \t\t\t);\n// \t\t\tpathExistsMock.mockReset();\n// \t\t\tpathExistsMock.mockResolvedValueOnce(true);\n\n// \t\t\tconfigManager = new ConfigManager();\n// \t\t\tawait configManager.loadDeviceIndex();\n// \t\t});\n\n// \t\tbeforeEach(() => {\n// \t\t\treadFileMock.mockClear();\n// \t\t\tpathExistsMock.mockClear();\n// \t\t});\n\n// \t\tit(\"tests if the corresponding file exists\", async () => {\n// \t\t\tpathExistsMock.mockResolvedValue(false);\n// \t\t\tawait configManager.lookupDevice(0x0abc, 0x0001, 0x0023);\n// \t\t\texpect(pathExistsMock).toBeCalledTimes(1);\n// \t\t\tconst expectedPath = path.join(\n// \t\t\t\tconfigDir,\n// \t\t\t\t\"devices/0x0abc/abcdef.json\",\n// \t\t\t);\n// \t\t\texpect(pathExistsMock.mock.calls[0][0]).toBe(expectedPath);\n// \t\t});\n\n// \t\tit(\"looks up the file with the correct firmware version\", async () => {\n// \t\t\tpathExistsMock.mockResolvedValue(true);\n// \t\t\tawait configManager.lookupDevice(0x0abc, 0x0001, 0x0034, \"2.1\");\n// \t\t\texpect(pathExistsMock).toBeCalledTimes(1);\n// \t\t\tconst expectedPath = path.join(\n// \t\t\t\tconfigDir,\n// \t\t\t\t\"devices/0x0abc/123456-8.json\",\n// \t\t\t);\n// \t\t\texpect(pathExistsMock.mock.calls[0][0]).toBe(expectedPath);\n// \t\t});\n\n// \t\tit(\"returns the contents of a found file, parsed as JSON5\", async () => {\n// \t\t\t// The first attempt at reading the file should succeed\n// \t\t\tpathExistsMock.mockResolvedValue(true);\n// \t\t\t// Return a dummy file that must be parsed as JSON5\n// \t\t\treadFileMock.mockResolvedValue(\n// \t\t\t\t`// This is a minimal valid device config\n// {\n// \t\"manufacturer\": \"Test manufacturer\",\n// \t\"manufacturerId\": \"0x0abc\",\n// \t\"label\": \"LABEL\",\n// \t\"description\": \"desc rip tion\",\n// \t\"devices\": [\n// \t\t{\n// \t\t\t\"productType\": \"0x0001\",\n// \t\t\t\"productId\": \"0x0001\"\n// \t\t}\n// \t],\n// \t\"firmwareVersion\": {\n// \t\t\"min\": \"0.0\",\n// \t\t\"max\": \"255.255\"\n// \t}\n// }`,\n// \t\t\t);\n\n// \t\t\tconst result = await configManager.lookupDevice(\n// \t\t\t\t0x0abc,\n// \t\t\t\t0x0001,\n// \t\t\t\t0x0034,\n// \t\t\t\t\"2.1\",\n// \t\t\t);\n// \t\t\texpect(result).toBeDefined();\n// \t\t\texpect(result!.manufacturer).toBe(\"Test manufacturer\");\n// \t\t});\n\n// \t\tit(\"does not throw if the JSON file is invalid\", async () => {\n// \t\t\t// The first attempt at reading the file should succeed\n// \t\t\tpathExistsMock.mockResolvedValue(true);\n// \t\t\t// Return an invalid JSON file\n// \t\t\treadFileMock.mockResolvedValue(`{\"name\": }`);\n\n// \t\t\t// return undefined instead of throwing\n// \t\t\tawait expect(\n// \t\t\t\tconfigManager.lookupDevice(0x0abc, 0x0001, 0x0034, \"2.1\"),\n// \t\t\t).resolves.toBeUndefined();\n// \t\t});\n// \t});\n// });\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -102,7 +102,7 @@ Parameter #${parameterNumber} has a non-numeric property recommendedValue`);
|
|
|
102
102
|
(0, import_utils_safe.throwInvalidConfig)("devices", `packages/config/config/devices/${parent.filename}:
|
|
103
103
|
Parameter #${parameterNumber}: allowManualEntry must be false or omitted!`);
|
|
104
104
|
}
|
|
105
|
-
this.allowManualEntry = definition.allowManualEntry ??
|
|
105
|
+
this.allowManualEntry = definition.allowManualEntry ?? !this.readOnly;
|
|
106
106
|
if (definition.destructive != void 0 && typeof definition.destructive !== "boolean") {
|
|
107
107
|
(0, import_utils_safe.throwInvalidConfig)("devices", `packages/config/config/devices/${parent.filename}:
|
|
108
108
|
Parameter #${parameterNumber} has a non-boolean property destructive`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/devices/ParamInformation.ts"],
|
|
4
|
-
"sourcesContent": ["import { tryParseParamNumber } from \"@zwave-js/core\";\nimport {\n\ttype JSONObject,\n\tObjectKeyMap,\n\ttype ReadonlyObjectKeyMap,\n\tpick,\n} from \"@zwave-js/shared\";\nimport { isArray, isObject } from \"alcalzone-shared/typeguards\";\nimport { throwInvalidConfig } from \"../utils_safe.js\";\nimport {\n\ttype ConditionalItem,\n\tconditionApplies,\n\tevaluateDeep,\n\tvalidateCondition,\n} from \"./ConditionalItem.js\";\nimport type { ConditionalDeviceConfig } from \"./DeviceConfig.js\";\nimport type { DeviceID } from \"./shared.js\";\n\nexport class ConditionalParamInformation\n\timplements ConditionalItem<ParamInformation>\n{\n\tpublic constructor(\n\t\tparent: ConditionalDeviceConfig,\n\t\tparameterNumber: number,\n\t\tvalueBitMask: number | undefined,\n\t\tdefinition: JSONObject,\n\t) {\n\t\tthis.parent = parent;\n\t\tthis.parameterNumber = parameterNumber;\n\t\tthis.valueBitMask = valueBitMask;\n\t\t// No need to validate here, this should be done one level higher\n\t\tthis.condition = definition.$if;\n\n\t\tif (typeof definition.label !== \"string\") {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-string label`,\n\t\t\t);\n\t\t}\n\t\tthis.label = definition.label;\n\n\t\tif (\n\t\t\tdefinition.description != undefined\n\t\t\t&& typeof definition.description !== \"string\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-string description`,\n\t\t\t);\n\t\t}\n\t\tthis.description = definition.description;\n\n\t\tif (\n\t\t\ttypeof definition.valueSize !== \"number\"\n\t\t\t|| definition.valueSize <= 0\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has an invalid value size`,\n\t\t\t);\n\t\t}\n\t\tthis.valueSize = definition.valueSize;\n\n\t\tif (\n\t\t\tdefinition.minValue != undefined\n\t\t\t&& typeof definition.minValue !== \"number\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property minValue`,\n\t\t\t);\n\t\t}\n\t\tthis.minValue = definition.minValue;\n\n\t\tif (\n\t\t\tdefinition.maxValue != undefined\n\t\t\t&& typeof definition.maxValue !== \"number\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property maxValue`,\n\t\t\t);\n\t\t}\n\t\tthis.maxValue = definition.maxValue;\n\n\t\tif (\n\t\t\tdefinition.unsigned != undefined\n\t\t\t&& typeof definition.unsigned !== \"boolean\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-boolean property unsigned`,\n\t\t\t);\n\t\t}\n\t\tthis.unsigned = definition.unsigned === true;\n\n\t\tif (\n\t\t\tdefinition.unit != undefined\n\t\t\t&& typeof definition.unit !== \"string\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-string unit`,\n\t\t\t);\n\t\t}\n\t\tthis.unit = definition.unit;\n\n\t\tif (definition.readOnly != undefined && definition.readOnly !== true) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\n\t\tParameter #${parameterNumber}: readOnly must true or omitted!`,\n\t\t\t);\n\t\t}\n\t\tthis.readOnly = definition.readOnly;\n\n\t\tif (\n\t\t\tdefinition.writeOnly != undefined\n\t\t\t&& definition.writeOnly !== true\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\n\t\tParameter #${parameterNumber}: writeOnly must be true or omitted!`,\n\t\t\t);\n\t\t}\n\t\tthis.writeOnly = definition.writeOnly;\n\n\t\tif (definition.defaultValue == undefined) {\n\t\t\tif (!this.readOnly) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"devices\",\n\t\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} is missing defaultValue, which is required unless the parameter is readOnly`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (typeof definition.defaultValue !== \"number\") {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property defaultValue`,\n\t\t\t);\n\t\t}\n\t\tthis.defaultValue = definition.defaultValue;\n\n\t\tif (\n\t\t\tdefinition.recommendedValue != undefined\n\t\t\t&& typeof definition.recommendedValue !== \"number\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property recommendedValue`,\n\t\t\t);\n\t\t}\n\t\tthis.recommendedValue = definition.recommendedValue;\n\n\t\tif (\n\t\t\tdefinition.allowManualEntry != undefined\n\t\t\t&& definition.allowManualEntry !== false\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber}: allowManualEntry must be false or omitted!`,\n\t\t\t);\n\t\t}\n\t\t// Default to allowing manual entry, except if the param is readonly\n\t\tthis.allowManualEntry = definition.allowManualEntry\n\t\t\t?? (this.readOnly ? false : true);\n\n\t\tif (\n\t\t\tdefinition.destructive != undefined\n\t\t\t&& typeof definition.destructive !== \"boolean\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-boolean property destructive`,\n\t\t\t);\n\t\t}\n\t\tthis.destructive = definition.destructive;\n\n\t\tif (\n\t\t\tisArray(definition.options)\n\t\t\t&& !definition.options.every(\n\t\t\t\t(opt: unknown) =>\n\t\t\t\t\tisObject(opt)\n\t\t\t\t\t&& typeof opt.label === \"string\"\n\t\t\t\t\t&& typeof opt.value === \"number\",\n\t\t\t)\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber}: options is malformed!`,\n\t\t\t);\n\t\t}\n\n\t\tthis.options = definition.options?.map(\n\t\t\t(opt: any) =>\n\t\t\t\tnew ConditionalConfigOption(opt.value, opt.label, opt.$if),\n\t\t) ?? [];\n\t}\n\n\tprivate parent: ConditionalDeviceConfig;\n\tpublic readonly parameterNumber: number;\n\tpublic readonly valueBitMask?: number;\n\tpublic readonly label: string;\n\tpublic readonly description?: string;\n\tpublic readonly valueSize: number;\n\tpublic readonly minValue?: number;\n\tpublic readonly maxValue?: number;\n\tpublic readonly unsigned?: boolean;\n\tpublic readonly defaultValue: number;\n\tpublic readonly recommendedValue?: number;\n\tpublic readonly unit?: string;\n\tpublic readonly readOnly?: true;\n\tpublic readonly writeOnly?: true;\n\tpublic readonly allowManualEntry: boolean;\n\tpublic readonly destructive?: boolean;\n\tpublic readonly options: readonly ConditionalConfigOption[];\n\n\tpublic readonly condition?: string;\n\n\tpublic evaluateCondition(\n\t\tdeviceId?: DeviceID,\n\t): ParamInformation | undefined {\n\t\tif (!conditionApplies(this, deviceId)) return;\n\n\t\tconst ret = {\n\t\t\t...pick(this, [\n\t\t\t\t\"parameterNumber\",\n\t\t\t\t\"valueBitMask\",\n\t\t\t\t\"label\",\n\t\t\t\t\"description\",\n\t\t\t\t\"valueSize\",\n\t\t\t\t\"minValue\",\n\t\t\t\t\"maxValue\",\n\t\t\t\t\"unsigned\",\n\t\t\t\t\"defaultValue\",\n\t\t\t\t\"recommendedValue\",\n\t\t\t\t\"unit\",\n\t\t\t\t\"readOnly\",\n\t\t\t\t\"writeOnly\",\n\t\t\t\t\"allowManualEntry\",\n\t\t\t\t\"destructive\",\n\t\t\t]),\n\t\t\toptions: evaluateDeep(this.options, deviceId, true),\n\t\t};\n\t\t// Infer minValue from options if possible\n\t\tif (ret.minValue == undefined) {\n\t\t\tif (ret.allowManualEntry === false && ret.options.length > 0) {\n\t\t\t\tret.minValue = Math.min(...ret.options.map((o) => o.value));\n\t\t\t} else {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"devices\",\n\t\t\t\t\t`packages/config/config/devices/${this.parent.filename}:\nParameter #${this.parameterNumber} is missing required property \"minValue\"!`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (ret.maxValue == undefined) {\n\t\t\tif (ret.allowManualEntry === false && ret.options.length > 0) {\n\t\t\t\tret.maxValue = Math.max(...ret.options.map((o) => o.value));\n\t\t\t} else {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"devices\",\n\t\t\t\t\t`packages/config/config/devices/${this.parent.filename}:\nParameter #${this.parameterNumber} is missing required property \"maxValue\"!`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// @ts-expect-error TS doesn't seem to understand that we do set min/maxValue\n\t\treturn ret;\n\t}\n}\n\nexport type ParamInformation =\n\t& Omit<\n\t\tConditionalParamInformation,\n\t\t\"condition\" | \"evaluateCondition\" | \"options\" | \"minValue\" | \"maxValue\"\n\t>\n\t& {\n\t\toptions: readonly ConfigOption[];\n\t\tminValue: NonNullable<ConditionalParamInformation[\"minValue\"]>;\n\t\tmaxValue: NonNullable<ConditionalParamInformation[\"maxValue\"]>;\n\t};\n\nexport class ConditionalConfigOption implements ConditionalItem<ConfigOption> {\n\tpublic constructor(\n\t\tpublic readonly value: number,\n\t\tpublic readonly label: string,\n\t\tpublic readonly condition?: string,\n\t) {}\n\n\tpublic evaluateCondition(deviceId?: DeviceID): ConfigOption | undefined {\n\t\tif (!conditionApplies(this, deviceId)) return;\n\n\t\treturn pick(this, [\"value\", \"label\"]);\n\t}\n}\n\nexport interface ConfigOption {\n\tvalue: number;\n\tlabel: string;\n}\n\nexport type ConditionalParamInfoMap = ReadonlyObjectKeyMap<\n\t{ parameter: number; valueBitMask?: number },\n\tConditionalParamInformation[]\n>;\n\nexport type ParamInfoMap = ReadonlyObjectKeyMap<\n\t{ parameter: number; valueBitMask?: number },\n\tParamInformation\n>;\n\nexport function parseConditionalParamInformationMap(\n\tdefinition: JSONObject,\n\tparent: ConditionalDeviceConfig,\n\terrorPrefix: string = \"\",\n): ConditionalParamInfoMap {\n\tconst paramInformation = new ObjectKeyMap<\n\t\t{ parameter: number; valueBitMask?: number },\n\t\tConditionalParamInformation[]\n\t>();\n\n\tconst filename = parent.filename;\n\n\tif (isArray(definition.paramInformation)) {\n\t\t// Check that every param has a param number\n\t\tif (!definition.paramInformation.every((entry: any) => \"#\" in entry)) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t`device`,\n\t\t\t\t`packages/config/config/devices/${filename}: \n${errorPrefix}required property \"#\" missing in at least one entry of paramInformation`,\n\t\t\t);\n\t\t}\n\n\t\t// And a valid $if condition\n\t\tfor (const entry of definition.paramInformation) {\n\t\t\tvalidateCondition(\n\t\t\t\tfilename,\n\t\t\t\tentry,\n\t\t\t\t`${errorPrefix}At least one entry of paramInformation contains an`,\n\t\t\t);\n\t\t}\n\n\t\tfor (const paramDefinition of definition.paramInformation) {\n\t\t\tconst { [\"#\"]: paramNo, ...defn } = paramDefinition;\n\t\t\tconst key = tryParseParamNumber(paramNo);\n\t\t\tif (!key) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}: \n${errorPrefix}found invalid param number \"${paramNo}\" in paramInformation`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!paramInformation.has(key)) paramInformation.set(key, []);\n\t\t\tparamInformation\n\t\t\t\t.get(key)!\n\t\t\t\t.push(\n\t\t\t\t\tnew ConditionalParamInformation(\n\t\t\t\t\t\tparent,\n\t\t\t\t\t\tkey.parameter,\n\t\t\t\t\t\tkey.valueBitMask,\n\t\t\t\t\t\tdefn,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t}\n\t} else if (isObject(definition.paramInformation)) {\n\t\t// Silently ignore this old format\n\t} else {\n\t\tthrowInvalidConfig(\n\t\t\t`device`,\n\t\t\t`packages/config/config/devices/${filename}:\n${errorPrefix}paramInformation must be an array!`,\n\t\t);\n\t}\n\n\treturn paramInformation;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAAA,kBAAoC;AACpC,oBAKO;AACP,wBAAkC;AAClC,wBAAmC;AACnC,6BAKO;AAID,MAAO,4BAA2B;EAlBxC,OAkBwC;;;EAGvC,YACC,QACA,iBACA,cACA,YAAsB;AAEtB,SAAK,SAAS;AACd,SAAK,kBAAkB;AACvB,SAAK,eAAe;AAEpB,SAAK,YAAY,WAAW;AAE5B,QAAI,OAAO,WAAW,UAAU,UAAU;AACzC,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,yBAAyB;IAEnD;AACA,SAAK,QAAQ,WAAW;AAExB,QACC,WAAW,eAAe,UACvB,OAAO,WAAW,gBAAgB,UACpC;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,+BAA+B;IAEzD;AACA,SAAK,cAAc,WAAW;AAE9B,QACC,OAAO,WAAW,cAAc,YAC7B,WAAW,aAAa,GAC1B;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,4BAA4B;IAEtD;AACA,SAAK,YAAY,WAAW;AAE5B,QACC,WAAW,YAAY,UACpB,OAAO,WAAW,aAAa,UACjC;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,sCAAsC;IAEhE;AACA,SAAK,WAAW,WAAW;AAE3B,QACC,WAAW,YAAY,UACpB,OAAO,WAAW,aAAa,UACjC;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,sCAAsC;IAEhE;AACA,SAAK,WAAW,WAAW;AAE3B,QACC,WAAW,YAAY,UACpB,OAAO,WAAW,aAAa,WACjC;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,sCAAsC;IAEhE;AACA,SAAK,WAAW,WAAW,aAAa;AAExC,QACC,WAAW,QAAQ,UAChB,OAAO,WAAW,SAAS,UAC7B;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,wBAAwB;IAElD;AACA,SAAK,OAAO,WAAW;AAEvB,QAAI,WAAW,YAAY,UAAa,WAAW,aAAa,MAAM;AACrE,gDACC,WACA,kCAAkC,OAAO,QAAQ;eACtC,eAAe,kCAAkC;IAE9D;AACA,SAAK,WAAW,WAAW;AAE3B,QACC,WAAW,aAAa,UACrB,WAAW,cAAc,MAC3B;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;eACtC,eAAe,sCAAsC;IAElE;AACA,SAAK,YAAY,WAAW;AAE5B,QAAI,WAAW,gBAAgB,QAAW;AACzC,UAAI,CAAC,KAAK,UAAU;AACnB,kDACC,WACA,kCAAkC,OAAO,QAAQ;aACzC,eAAe,8EAA8E;MAEvG;IACD,WAAW,OAAO,WAAW,iBAAiB,UAAU;AACvD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,0CAA0C;IAEpE;AACA,SAAK,eAAe,WAAW;AAE/B,QACC,WAAW,oBAAoB,UAC5B,OAAO,WAAW,qBAAqB,UACzC;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,8CAA8C;IAExE;AACA,SAAK,mBAAmB,WAAW;AAEnC,QACC,WAAW,oBAAoB,UAC5B,WAAW,qBAAqB,OAClC;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,8CAA8C;IAExE;AAEA,SAAK,mBAAmB,WAAW,
|
|
4
|
+
"sourcesContent": ["import { tryParseParamNumber } from \"@zwave-js/core\";\nimport {\n\ttype JSONObject,\n\tObjectKeyMap,\n\ttype ReadonlyObjectKeyMap,\n\tpick,\n} from \"@zwave-js/shared\";\nimport { isArray, isObject } from \"alcalzone-shared/typeguards\";\nimport { throwInvalidConfig } from \"../utils_safe.js\";\nimport {\n\ttype ConditionalItem,\n\tconditionApplies,\n\tevaluateDeep,\n\tvalidateCondition,\n} from \"./ConditionalItem.js\";\nimport type { ConditionalDeviceConfig } from \"./DeviceConfig.js\";\nimport type { DeviceID } from \"./shared.js\";\n\nexport class ConditionalParamInformation\n\timplements ConditionalItem<ParamInformation>\n{\n\tpublic constructor(\n\t\tparent: ConditionalDeviceConfig,\n\t\tparameterNumber: number,\n\t\tvalueBitMask: number | undefined,\n\t\tdefinition: JSONObject,\n\t) {\n\t\tthis.parent = parent;\n\t\tthis.parameterNumber = parameterNumber;\n\t\tthis.valueBitMask = valueBitMask;\n\t\t// No need to validate here, this should be done one level higher\n\t\tthis.condition = definition.$if;\n\n\t\tif (typeof definition.label !== \"string\") {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-string label`,\n\t\t\t);\n\t\t}\n\t\tthis.label = definition.label;\n\n\t\tif (\n\t\t\tdefinition.description != undefined\n\t\t\t&& typeof definition.description !== \"string\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-string description`,\n\t\t\t);\n\t\t}\n\t\tthis.description = definition.description;\n\n\t\tif (\n\t\t\ttypeof definition.valueSize !== \"number\"\n\t\t\t|| definition.valueSize <= 0\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has an invalid value size`,\n\t\t\t);\n\t\t}\n\t\tthis.valueSize = definition.valueSize;\n\n\t\tif (\n\t\t\tdefinition.minValue != undefined\n\t\t\t&& typeof definition.minValue !== \"number\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property minValue`,\n\t\t\t);\n\t\t}\n\t\tthis.minValue = definition.minValue;\n\n\t\tif (\n\t\t\tdefinition.maxValue != undefined\n\t\t\t&& typeof definition.maxValue !== \"number\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property maxValue`,\n\t\t\t);\n\t\t}\n\t\tthis.maxValue = definition.maxValue;\n\n\t\tif (\n\t\t\tdefinition.unsigned != undefined\n\t\t\t&& typeof definition.unsigned !== \"boolean\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-boolean property unsigned`,\n\t\t\t);\n\t\t}\n\t\tthis.unsigned = definition.unsigned === true;\n\n\t\tif (\n\t\t\tdefinition.unit != undefined\n\t\t\t&& typeof definition.unit !== \"string\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-string unit`,\n\t\t\t);\n\t\t}\n\t\tthis.unit = definition.unit;\n\n\t\tif (definition.readOnly != undefined && definition.readOnly !== true) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\n\t\tParameter #${parameterNumber}: readOnly must true or omitted!`,\n\t\t\t);\n\t\t}\n\t\tthis.readOnly = definition.readOnly;\n\n\t\tif (\n\t\t\tdefinition.writeOnly != undefined\n\t\t\t&& definition.writeOnly !== true\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\n\t\tParameter #${parameterNumber}: writeOnly must be true or omitted!`,\n\t\t\t);\n\t\t}\n\t\tthis.writeOnly = definition.writeOnly;\n\n\t\tif (definition.defaultValue == undefined) {\n\t\t\tif (!this.readOnly) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"devices\",\n\t\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} is missing defaultValue, which is required unless the parameter is readOnly`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (typeof definition.defaultValue !== \"number\") {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property defaultValue`,\n\t\t\t);\n\t\t}\n\t\tthis.defaultValue = definition.defaultValue;\n\n\t\tif (\n\t\t\tdefinition.recommendedValue != undefined\n\t\t\t&& typeof definition.recommendedValue !== \"number\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property recommendedValue`,\n\t\t\t);\n\t\t}\n\t\tthis.recommendedValue = definition.recommendedValue;\n\n\t\tif (\n\t\t\tdefinition.allowManualEntry != undefined\n\t\t\t&& definition.allowManualEntry !== false\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber}: allowManualEntry must be false or omitted!`,\n\t\t\t);\n\t\t}\n\t\t// Default to allowing manual entry, except if the param is readonly\n\t\tthis.allowManualEntry = definition.allowManualEntry ?? !this.readOnly;\n\n\t\tif (\n\t\t\tdefinition.destructive != undefined\n\t\t\t&& typeof definition.destructive !== \"boolean\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-boolean property destructive`,\n\t\t\t);\n\t\t}\n\t\tthis.destructive = definition.destructive;\n\n\t\tif (\n\t\t\tisArray(definition.options)\n\t\t\t&& !definition.options.every(\n\t\t\t\t(opt: unknown) =>\n\t\t\t\t\tisObject(opt)\n\t\t\t\t\t&& typeof opt.label === \"string\"\n\t\t\t\t\t&& typeof opt.value === \"number\",\n\t\t\t)\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber}: options is malformed!`,\n\t\t\t);\n\t\t}\n\n\t\tthis.options = definition.options?.map(\n\t\t\t(opt: any) =>\n\t\t\t\tnew ConditionalConfigOption(opt.value, opt.label, opt.$if),\n\t\t) ?? [];\n\t}\n\n\tprivate parent: ConditionalDeviceConfig;\n\tpublic readonly parameterNumber: number;\n\tpublic readonly valueBitMask?: number;\n\tpublic readonly label: string;\n\tpublic readonly description?: string;\n\tpublic readonly valueSize: number;\n\tpublic readonly minValue?: number;\n\tpublic readonly maxValue?: number;\n\tpublic readonly unsigned?: boolean;\n\tpublic readonly defaultValue: number;\n\tpublic readonly recommendedValue?: number;\n\tpublic readonly unit?: string;\n\tpublic readonly readOnly?: true;\n\tpublic readonly writeOnly?: true;\n\tpublic readonly allowManualEntry: boolean;\n\tpublic readonly destructive?: boolean;\n\tpublic readonly options: readonly ConditionalConfigOption[];\n\n\tpublic readonly condition?: string;\n\n\tpublic evaluateCondition(\n\t\tdeviceId?: DeviceID,\n\t): ParamInformation | undefined {\n\t\tif (!conditionApplies(this, deviceId)) return;\n\n\t\tconst ret = {\n\t\t\t...pick(this, [\n\t\t\t\t\"parameterNumber\",\n\t\t\t\t\"valueBitMask\",\n\t\t\t\t\"label\",\n\t\t\t\t\"description\",\n\t\t\t\t\"valueSize\",\n\t\t\t\t\"minValue\",\n\t\t\t\t\"maxValue\",\n\t\t\t\t\"unsigned\",\n\t\t\t\t\"defaultValue\",\n\t\t\t\t\"recommendedValue\",\n\t\t\t\t\"unit\",\n\t\t\t\t\"readOnly\",\n\t\t\t\t\"writeOnly\",\n\t\t\t\t\"allowManualEntry\",\n\t\t\t\t\"destructive\",\n\t\t\t]),\n\t\t\toptions: evaluateDeep(this.options, deviceId, true),\n\t\t};\n\t\t// Infer minValue from options if possible\n\t\tif (ret.minValue == undefined) {\n\t\t\tif (ret.allowManualEntry === false && ret.options.length > 0) {\n\t\t\t\tret.minValue = Math.min(...ret.options.map((o) => o.value));\n\t\t\t} else {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"devices\",\n\t\t\t\t\t`packages/config/config/devices/${this.parent.filename}:\nParameter #${this.parameterNumber} is missing required property \"minValue\"!`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (ret.maxValue == undefined) {\n\t\t\tif (ret.allowManualEntry === false && ret.options.length > 0) {\n\t\t\t\tret.maxValue = Math.max(...ret.options.map((o) => o.value));\n\t\t\t} else {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"devices\",\n\t\t\t\t\t`packages/config/config/devices/${this.parent.filename}:\nParameter #${this.parameterNumber} is missing required property \"maxValue\"!`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// @ts-expect-error TS doesn't seem to understand that we do set min/maxValue\n\t\treturn ret;\n\t}\n}\n\nexport type ParamInformation =\n\t& Omit<\n\t\tConditionalParamInformation,\n\t\t\"condition\" | \"evaluateCondition\" | \"options\" | \"minValue\" | \"maxValue\"\n\t>\n\t& {\n\t\toptions: readonly ConfigOption[];\n\t\tminValue: NonNullable<ConditionalParamInformation[\"minValue\"]>;\n\t\tmaxValue: NonNullable<ConditionalParamInformation[\"maxValue\"]>;\n\t};\n\nexport class ConditionalConfigOption implements ConditionalItem<ConfigOption> {\n\tpublic constructor(\n\t\tpublic readonly value: number,\n\t\tpublic readonly label: string,\n\t\tpublic readonly condition?: string,\n\t) {}\n\n\tpublic evaluateCondition(deviceId?: DeviceID): ConfigOption | undefined {\n\t\tif (!conditionApplies(this, deviceId)) return;\n\n\t\treturn pick(this, [\"value\", \"label\"]);\n\t}\n}\n\nexport interface ConfigOption {\n\tvalue: number;\n\tlabel: string;\n}\n\nexport type ConditionalParamInfoMap = ReadonlyObjectKeyMap<\n\t{ parameter: number; valueBitMask?: number },\n\tConditionalParamInformation[]\n>;\n\nexport type ParamInfoMap = ReadonlyObjectKeyMap<\n\t{ parameter: number; valueBitMask?: number },\n\tParamInformation\n>;\n\nexport function parseConditionalParamInformationMap(\n\tdefinition: JSONObject,\n\tparent: ConditionalDeviceConfig,\n\terrorPrefix: string = \"\",\n): ConditionalParamInfoMap {\n\tconst paramInformation = new ObjectKeyMap<\n\t\t{ parameter: number; valueBitMask?: number },\n\t\tConditionalParamInformation[]\n\t>();\n\n\tconst filename = parent.filename;\n\n\tif (isArray(definition.paramInformation)) {\n\t\t// Check that every param has a param number\n\t\tif (!definition.paramInformation.every((entry: any) => \"#\" in entry)) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t`device`,\n\t\t\t\t`packages/config/config/devices/${filename}: \n${errorPrefix}required property \"#\" missing in at least one entry of paramInformation`,\n\t\t\t);\n\t\t}\n\n\t\t// And a valid $if condition\n\t\tfor (const entry of definition.paramInformation) {\n\t\t\tvalidateCondition(\n\t\t\t\tfilename,\n\t\t\t\tentry,\n\t\t\t\t`${errorPrefix}At least one entry of paramInformation contains an`,\n\t\t\t);\n\t\t}\n\n\t\tfor (const paramDefinition of definition.paramInformation) {\n\t\t\tconst { [\"#\"]: paramNo, ...defn } = paramDefinition;\n\t\t\tconst key = tryParseParamNumber(paramNo);\n\t\t\tif (!key) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}: \n${errorPrefix}found invalid param number \"${paramNo}\" in paramInformation`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!paramInformation.has(key)) paramInformation.set(key, []);\n\t\t\tparamInformation\n\t\t\t\t.get(key)!\n\t\t\t\t.push(\n\t\t\t\t\tnew ConditionalParamInformation(\n\t\t\t\t\t\tparent,\n\t\t\t\t\t\tkey.parameter,\n\t\t\t\t\t\tkey.valueBitMask,\n\t\t\t\t\t\tdefn,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t}\n\t} else if (isObject(definition.paramInformation)) {\n\t\t// Silently ignore this old format\n\t} else {\n\t\tthrowInvalidConfig(\n\t\t\t`device`,\n\t\t\t`packages/config/config/devices/${filename}:\n${errorPrefix}paramInformation must be an array!`,\n\t\t);\n\t}\n\n\treturn paramInformation;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAAA,kBAAoC;AACpC,oBAKO;AACP,wBAAkC;AAClC,wBAAmC;AACnC,6BAKO;AAID,MAAO,4BAA2B;EAlBxC,OAkBwC;;;EAGvC,YACC,QACA,iBACA,cACA,YAAsB;AAEtB,SAAK,SAAS;AACd,SAAK,kBAAkB;AACvB,SAAK,eAAe;AAEpB,SAAK,YAAY,WAAW;AAE5B,QAAI,OAAO,WAAW,UAAU,UAAU;AACzC,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,yBAAyB;IAEnD;AACA,SAAK,QAAQ,WAAW;AAExB,QACC,WAAW,eAAe,UACvB,OAAO,WAAW,gBAAgB,UACpC;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,+BAA+B;IAEzD;AACA,SAAK,cAAc,WAAW;AAE9B,QACC,OAAO,WAAW,cAAc,YAC7B,WAAW,aAAa,GAC1B;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,4BAA4B;IAEtD;AACA,SAAK,YAAY,WAAW;AAE5B,QACC,WAAW,YAAY,UACpB,OAAO,WAAW,aAAa,UACjC;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,sCAAsC;IAEhE;AACA,SAAK,WAAW,WAAW;AAE3B,QACC,WAAW,YAAY,UACpB,OAAO,WAAW,aAAa,UACjC;AACD,gD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