u
This commit is contained in:
@@ -491,6 +491,9 @@ function evaluateCondition(condition) {
|
||||
}
|
||||
}
|
||||
|
||||
// Global set to track currently active rule IDs
|
||||
const activeRuleIds = new Set();
|
||||
|
||||
// Run all rules
|
||||
function runRules() {
|
||||
if (!db) return;
|
||||
@@ -498,6 +501,9 @@ function runRules() {
|
||||
try {
|
||||
const rules = db.prepare('SELECT * FROM rules WHERE enabled = 1 ORDER BY position ASC').all();
|
||||
|
||||
// Clear active rules list at start of run
|
||||
activeRuleIds.clear();
|
||||
|
||||
// Default all outputs to OFF (0) - if no rule sets them, they stay off
|
||||
const desiredOutputs = {};
|
||||
for (const ch of OUTPUT_CHANNELS) {
|
||||
@@ -510,6 +516,9 @@ function runRules() {
|
||||
const action = JSON.parse(rule.action || '{}');
|
||||
|
||||
if (evaluateCondition(conditions)) {
|
||||
// Rule matches - add to active list
|
||||
activeRuleIds.add(rule.id);
|
||||
|
||||
// Rule matches - set output (later rules override)
|
||||
if (action.channel && action.value !== undefined) {
|
||||
let finalValue = action.value;
|
||||
@@ -818,6 +827,11 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/rules/status - Get currently active rule IDs
|
||||
app.get('/api/rules/status', (req, res) => {
|
||||
res.json({ activeIds: Array.from(activeRuleIds) });
|
||||
});
|
||||
|
||||
// GET /api/rules - List all rules
|
||||
app.get('/api/rules', (req, res) => {
|
||||
try {
|
||||
@@ -835,6 +849,8 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// POST /api/rules - Create rule (admin only)
|
||||
app.post('/api/rules', requireAdmin, (req, res) => {
|
||||
const { name, type = 'static', enabled = 1, conditions, action } = req.body;
|
||||
|
||||
Reference in New Issue
Block a user