From 107eaa7e35fe1615c9a58db23c82d92283277fac Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Wed, 14 Oct 2026 12:33:57 +0000 Subject: [PATCH] Register lights app (LXC 133) and capabilities Co-Authored-By: Claude Sonnet 5.5 --- src/db.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/db.js b/src/db.js index 41ef29e..b21be98 100644 --- a/src/db.js +++ b/src/db.js @@ -617,6 +617,40 @@ export async function initDb() { sort_order = EXCLUDED.sort_order `) + // Seed lights app + capabilities (no default Staff grants — admin assigns via portal, + // same convention as hvac/plant/wages/utilities). LXC 133 — Tasmota smart-switch + // lighting control + schedules (fixed time, sunrise/sunset) over MQTT. + await pool.query(` + INSERT INTO apps (slug, name, description, base_path, icon, theme_color, category, internal_host, internal_port) + VALUES ('lights', 'Lighting', 'Tasmota smart-switch lighting — manual control plus on/off and sunrise/sunset schedules via MQTT', '/lights', 'Lightbulb', '#b45309', 'Hotel', '10.10.10.133', 3080) + ON CONFLICT (slug) DO UPDATE SET + name = EXCLUDED.name, + description = EXCLUDED.description, + base_path = EXCLUDED.base_path, + icon = EXCLUDED.icon, + theme_color = EXCLUDED.theme_color, + category = EXCLUDED.category, + internal_host = EXCLUDED.internal_host, + internal_port = EXCLUDED.internal_port + `) + + await pool.query(` + INSERT INTO app_capabilities (app_id, slug, name, description, sort_order) + SELECT a.id, c.slug, c.name, c.description, c.sort_order + FROM apps a, (VALUES + ('view', 'View', 'See the lighting control screen, schedules and activity log', 1), + ('control', 'Control', 'Switch lights and groups on/off manually', 2), + ('schedules', 'Schedules', 'Create, edit and delete on/off and sunrise/sunset schedules', 3), + ('manage_devices', 'Manage Devices', 'Add, edit and remove lights and light groups', 4), + ('settings', 'Settings', 'Configure site location, timezone and view MQTT status', 5) + ) AS c(slug, name, description, sort_order) + WHERE a.slug = 'lights' + ON CONFLICT (app_id, slug) DO UPDATE SET + name = EXCLUDED.name, + description = EXCLUDED.description, + sort_order = EXCLUDED.sort_order + `) + // Seed first admin user if table is empty const { rows } = await pool.query('SELECT COUNT(*) FROM users') if (parseInt(rows[0].count) === 0) {