hvac/seed-app.js
jtricerolph 276c04f8c6 Scaffold Phase 1 hvac app — NewBook-driven room TRV heating scheduler
Ports the state machine, retry/backoff, and guest-override detection from
the retired homeassistant-newbook-heating-component, without depending on
Home Assistant. Backend (Fastify/pg) + frontend (React/Vite/TS) following
standard stack conventions; LXC 128 (127 was already taken by utilities).

MHI/Midea/Daikin/boiler drivers and the shared MQTT broker (LXC 104) are
later phases/infra, not included here.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-26 18:00:42 +00:00

50 lines
2.6 KiB
JavaScript

#!/usr/bin/env node
// Run from hvac/ dir: DATABASE_URL=... node seed-app.js
import pg from 'pg'
const { Pool } = pg
const pool = new Pool({ connectionString: process.env.DATABASE_URL })
await pool.query(`
INSERT INTO apps (slug, name, description, base_path, icon, theme_color, category, internal_host, internal_port)
VALUES ('hvac', 'HVAC', 'Room heating control — NewBook-driven TRV scheduling, aircon and boiler (phased)', '/hvac', 'Thermometer', '#c1440e', 'Operations', '10.10.10.128', 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
`)
// Seed capabilities. public_area_control / boiler_view / boiler_control are
// Phase 3/4 capabilities seeded now (per the plan) so role assignment doesn't
// need a second migration later — no routes are gated on them yet.
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', 'View zone dashboard, device status and activity', 1),
('control', 'Manual Override', 'Force a zone''s temperature and disable auto mode', 2),
('schedule_edit', 'Edit Schedules', 'Adjust per-zone temps, offsets and auto mode', 3),
('manage_devices', 'Manage Devices', 'Discover, map, photograph devices; sync zones from NewBook',4),
('public_area_control', 'Public Area Control', 'Central control of public-area zones (Phase 3)', 5),
('boiler_view', 'Boiler — View', 'View boiler controller status (Phase 4)', 6),
('boiler_control', 'Boiler — Control', 'Adjust boiler weather-compensation / pump disable (Phase 4)',7),
('settings', 'Settings', 'Configure hvac app settings', 8)
) AS c(slug, name, description, sort_order)
WHERE a.slug = 'hvac'
ON CONFLICT (app_id, slug) DO UPDATE SET
name = EXCLUDED.name,
description = EXCLUDED.description,
sort_order = EXCLUDED.sort_order
`)
// No default Staff grants — this app drives physical room heating, so access is
// admin-assigned per role via the portal (same convention as wages/utilities,
// the two most recently-added apps).
console.log('hvac app seeded.')
await pool.end()