This commit is contained in:
sebseb7
2025-12-26 01:57:15 +01:00
parent e9a66cd1f4
commit 86bea2fa6d
7 changed files with 608 additions and 33 deletions

View File

@@ -2,10 +2,10 @@
* Outputs API - Output channel definitions and values
*/
module.exports = function setupOutputsApi(app, { db, OUTPUT_CHANNELS, OUTPUT_BINDINGS }) {
module.exports = function setupOutputsApi(app, { db, getOutputChannels, getOutputBindings }) {
// GET /api/outputs - List output channel definitions
app.get('/api/outputs', (req, res) => {
res.json(OUTPUT_CHANNELS);
res.json(getOutputChannels());
});
// GET /api/outputs/values - Get current output values
@@ -24,7 +24,8 @@ module.exports = function setupOutputsApi(app, { db, OUTPUT_CHANNELS, OUTPUT_BIN
result[row.channel] = row.value;
});
// Fill in defaults for missing channels
OUTPUT_CHANNELS.forEach(ch => {
const outputChannels = getOutputChannels();
outputChannels.forEach(ch => {
if (result[ch.channel] === undefined) {
result[ch.channel] = 0;
}
@@ -55,8 +56,9 @@ module.exports = function setupOutputsApi(app, { db, OUTPUT_CHANNELS, OUTPUT_BIN
});
// Map to device commands
const bindings = getOutputBindings();
const commands = {};
for (const [outputChannel, binding] of Object.entries(OUTPUT_BINDINGS)) {
for (const [outputChannel, binding] of Object.entries(bindings)) {
const value = outputValues[outputChannel] ?? 0;
const deviceKey = `${binding.device}:${binding.channel}`;
commands[deviceKey] = {