Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support all configuration options in config.js #1345

Open
synthead opened this issue Nov 19, 2024 · 0 comments
Open

Support all configuration options in config.js #1345

synthead opened this issue Nov 19, 2024 · 0 comments

Comments

@synthead
Copy link

This is example_config.js:

module.exports = {
logConfig: {
filename: "/var/log/zwave/zwave",
forceConsole: true,
logToFile: true,
level: "info",
},
storage: {
cacheDir: "/opt/zwave_js_server/data",
deviceConfigPriorityDir: "/opt/zwave_js_server/data/config",
},
// Generated with: "< /dev/urandom tr -dc A-F0-9 | head -c32 ;echo"
securityKeys: {
S0_Legacy: Buffer.from("<NETWORK_KEY>", "hex"),
},
};

Here is where the config file is parsed:

if (configPath) {
try {
// Pull presets out of options so we can pass them to the driver
({ presets: presetNames, ...options } = require(configPath));
// If both securityKeys.S0_Legacy and networkKey are defined, throw an error.
if (options.securityKeys?.S0_Legacy && options.networkKey) {
throw new Error(
"Both `networkKey` and `securityKeys.S0_Legacy` options are present in the " +
"config. Remove `networkKey`.",
);
}
const securityKeyNames = [
"S0_Legacy",
"S2_AccessControl",
"S2_Authenticated",
"S2_Unauthenticated",
];
// We prefer the securityKeys option over the networkKey one
if (options.securityKeys) {
for (const key of securityKeyNames) {
if (key in options.securityKeys) {
options.securityKeys[key] = normalizeKey(
options.securityKeys[key],
`securityKeys.${key}`,
);
}
}
}
// If we get here, securityKeys.S0_Legacy is not defined, so we can safely use networkKey
// make sure that networkKey is passed as buffer and accept both zwave2mqtt format and ozw format
if (options.networkKey) {
if (!options.securityKeys) options.securityKeys = {};
options.securityKeys.S0_Legacy = normalizeKey(
options.networkKey,
"networkKey",
);
console.warn(
"The `networkKey` option is deprecated in favor of `securityKeys` option. To eliminate " +
"this warning, move your networkKey into the securityKeys.S0_Legacy option. Refer to " +
"the Z-Wave JS docs for more information",
);
delete options.networkKey;
} else if (!options.securityKeys?.S0_Legacy)
throw new Error("Error: `securityKeys.S0_Legacy` key is missing.");
// Support long range keys
const securityKeysLongRangeNames = [
"S2_AccessControl",
"S2_Authenticated",
];
if (options.securityKeysLongRange) {
for (const key of securityKeysLongRangeNames) {
if (key in options.securityKeysLongRange) {
options.securityKeysLongRange[key] = normalizeKey(
options.securityKeysLongRange[key],
`securityKeysLongRange.${key}`,
);
}
}
}
} catch (err) {
console.error(`Error: failed loading config file ${configPath}`);
console.error(err);
return;
}
}

It supports a lot of options, but it does not support "mock-driver", "port", "host", or "disable-dns-sd" options. Instead, these options are parsed separately:

const args = parseArgs<Args>([
"_",
"config",
"mock-driver",
"port",
"host",
"disable-dns-sd",
]);

It would be really great to be able to tell zwave-js-server to "read all my config options" and have the port, host, encryption keys, and the like all in one place. This would make it a lot easier to maintain individual configurations for each zwave device and its corresponding server, which is useful for how zwave-js-server is typically deployed on a server.

For example, this is the zwave-js-server package in the Arch Linux AUR:

https://aur.archlinux.org/packages/zwave-js-server

Here is the [email protected] file that it includes (link):

[Unit]
Description=ZWave-JS Server Daemon "%i" instance
Before=home-assistant.service

[Service]
ExecStart=/usr/bin/zwave-server /dev/%I

[Install]
WantedBy=multi-user.target

If we could pass a configuration file to zwave-server and have everything we need, then this would be great 😄

Thanks for the great project! Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant