u
This commit is contained in:
@@ -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] = {
|
||||
|
||||
Reference in New Issue
Block a user