Add support for specifying custom config using env variable

master
Kuba Orlik 3 months ago
parent aec23b6c55
commit e8525f76ac

@ -2,5 +2,6 @@ const TOKEN = process.env.HA_TOKEN;
const HA_URL = process.env.HA_URL || "http://127.0.0.1:8123";
const PORT = parseInt(process.env.HA_BRIDGE_PORT || "41234");
const TRANSITION_DURATION_DIVIDER = parseInt(process.env.HA_DURATION_DIVIDER || "1");
const CONFIG_FILE = process.env.CONFIG_FILE || "./config.js" ;
module.exports = { TOKEN, HA_URL, PORT, TRANSITION_DURATION_DIVIDER };
module.exports = { TOKEN, HA_URL, PORT, TRANSITION_DURATION_DIVIDER, CONFIG_FILE };

@ -0,0 +1,7 @@
const { CONFIG_FILE } = require("./env.js");
module.exports = {
getConfig: function getConfig() {
return require(CONFIG_FILE);
},
};

@ -1,7 +1,8 @@
const dgram = require("node:dgram");
const server = dgram.createSocket("udp4");
const { getConfig } = require("./get-config.js");
const { lights } = require("./config.js");
const { lights } = getConfig();
const light_loop = require("./light-loop.js");
const latest_color = require("./latest_color.js");
const { TOKEN, PORT } = require("./env.js");
@ -16,12 +17,12 @@ const max_brightness = 0.8;
if (!TOKEN) {
throw new Error(
"Provide the Home Assistant Long Lived Token as a HA_TOKEN environment variable. Go to /profile in Home Assistant and scroll down.",
"Provide the Home Assistant Long Lived Token as a HA_TOKEN environment variable. Go to /profile in Home Assistant and scroll down."
);
}
console.log(
`Remember to set the Hyperion output controller type to UDPRAW and set it to output ${lights.length} lights`,
`Remember to set the Hyperion output controller type to UDPRAW and set it to output ${lights.length} lights`
);
server.on("message", (msg, rinfo) => {

@ -1,4 +1,6 @@
const { lights } = require("./config.js");
const { getConfig } = require("./get-config.js");
const { lights } = getConfig();
let latest_color = [];

@ -2,7 +2,8 @@ const { HA_URL, TOKEN, TRANSITION_DURATION_DIVIDER } = require("./env.js");
const { sleep } = require("./util.js");
const latest_color = require("./latest_color.js");
const { lights } = require("./config.js");
const { getConfig } = require("./get-config.js");
const { lights } = getConfig();
async function send_color(
light_data,

Loading…
Cancel
Save