This commit is contained in:
Mateusz Gruszczyński
2026-09-07 10:01:52 +02:00
parent 11da46c4d6
commit 7772e1e339
18 changed files with 347 additions and 170 deletions
+59 -18
View File
@@ -1,25 +1,67 @@
function settingsFromSnapshot(sections, houseMode = app.settings?.house_mode || 'cool') {
const application = sections?.application || {};
const gree = sections?.gree || {};
const history = sections?.history || {};
const influxdb = sections?.influxdb || {};
const notifications = sections?.notifications || {};
const night = sections?.night || {};
const homeAssistant = sections?.home_assistant || {};
const debug = sections?.debug || {};
return {
simulator_enabled: !!application.simulator_enabled,
controller_id: gree.controller_id,
poll_interval_seconds: Number(gree.poll_interval_seconds),
zone_interval_seconds: Number(gree.zone_interval_seconds),
discovery_timeout_ms: Number(gree.discovery_timeout_ms),
discovery_broadcast: gree.discovery_broadcast,
suppress_device_beep: !!gree.suppress_device_beep,
compressor_protection_enabled: gree.compressor_protection_enabled !== false,
compressor_protection_seconds: Number(gree.compressor_protection_seconds),
history_retention_days: Number(history.retention_days),
history_compaction_enabled: history.compaction_enabled !== false,
event_log_retention_days: Number(history.event_retention_days),
influxdb,
notifications,
night_mode: night,
home_assistant: homeAssistant,
outdoor_assist_enabled: !!homeAssistant.outdoor_assist_enabled,
debug,
house_mode: houseMode || 'cool',
};
}
function applyBootstrapSnapshot(data) {
app.devices = data.devices || [];
app.zones = data.zones || [];
app.groups = data.groups || [];
app.schedules = data.schedules || [];
app.automations = data.automations || [];
app.flows = data.flows || [];
app.accessTokens = data.access_tokens || [];
app.settings = settingsFromSnapshot(data.settings, data.house?.mode || 'cool');
app.sensorAliases = { ...(app.settings.home_assistant?.sensor_aliases || {}) };
app.flowSharedInputs = JSON.parse(JSON.stringify(app.settings.home_assistant?.flow_inputs || []));
app.system = data.system || {};
app.systemSnapshotAt = Date.now();
const outdoorTemperature = data.outdoor_temperature;
app.outdoorTemperature = outdoorTemperature === null || outdoorTemperature === undefined || outdoorTemperature === ''
? null
: (Number.isFinite(Number(outdoorTemperature)) ? Number(outdoorTemperature) : null);
const hasControlPlan = !!data.control_plan;
if (hasControlPlan) app.controlPlan = data.control_plan;
if (Number.isFinite(Number(data.control_plan_revision))) app.controlPlanRevision = Number(data.control_plan_revision);
return hasControlPlan;
}
async function loadBootstrap(showMessage = false) {
if (app.loading) { app.bootstrapReloadPending = true; return; }
app.loading = true;
try {
const [data, sections] = await Promise.all([api('/api/bootstrap'), fetchSettingsSections()]);
app.devices = data.devices || [];
app.zones = data.zones || [];
app.groups = data.groups || [];
app.schedules = data.schedules || [];
app.automations = data.automations || [];
app.flows = data.flows || [];
app.accessTokens = data.access_tokens || [];
app.settings = aggregateSettingsSections(sections, data.house?.mode || 'cool');
app.sensorAliases = { ...(app.settings.home_assistant?.sensor_aliases || {}) };
app.flowSharedInputs = JSON.parse(JSON.stringify(app.settings.home_assistant?.flow_inputs || []));
app.system = data.system || {};
app.systemSnapshotAt = Date.now();
app.outdoorTemperature = Number.isFinite(Number(data.outdoor_temperature)) ? Number(data.outdoor_temperature) : null;
app.controlPlan = data.control_plan || app.controlPlan;
app.controlPlanRevision = Number.isFinite(Number(data.control_plan_revision)) ? Number(data.control_plan_revision) : app.controlPlanRevision;
const data = await api('/api/bootstrap');
const hasControlPlan = applyBootstrapSnapshot(data);
renderAll();
if (!data.control_plan) scheduleControlPlanLoad(0);
if (!hasControlPlan) scheduleControlPlanLoad(0);
if (app.settings?.debug?.overlay_enabled) loadDebugBacklog();
if (showMessage) toast(tr('common.updated'));
if ($('#tokenDialog').open) $('#tokenDialog').close();
@@ -34,4 +76,3 @@ async function loadBootstrap(showMessage = false) {
}
}
}
+8 -11
View File
@@ -26,17 +26,14 @@ async function handleWebSocketMessage(event) {
try {
const message = JSON.parse(event.data);
if (message.event === 'bootstrap') {
const data = message.data; app.devices = data.devices || []; app.zones = data.zones || []; app.groups = data.groups || []; app.schedules = data.schedules || []; app.automations = data.automations || [];
app.flows = data.flows || []; await loadSettingsSections(data.house?.mode || app.settings?.house_mode || 'cool'); app.system = data.system || app.system; app.systemSnapshotAt = Date.now(); app.outdoorTemperature = Number.isFinite(Number(data.outdoor_temperature)) ? Number(data.outdoor_temperature) : app.outdoorTemperature;
if (data.control_plan) {
app.controlPlan = data.control_plan;
app.controlPlanRevision = Number.isFinite(Number(data.control_plan_revision)) ? Number(data.control_plan_revision) : app.controlPlanRevision;
app.controlPlanPushReady = true;
stopControlPlanFallback();
} else {
app.controlPlanPushReady = false;
}
renderAll(); if (!data.control_plan) scheduleControlPlanLoad(0); if (app.settings?.debug?.overlay_enabled) loadDebugBacklog(); return;
const data = message.data || {};
const hasControlPlan = applyBootstrapSnapshot(data);
app.controlPlanPushReady = hasControlPlan;
if (hasControlPlan) stopControlPlanFallback();
renderAll();
if (!hasControlPlan) scheduleControlPlanLoad(0);
if (app.settings?.debug?.overlay_enabled) loadDebugBacklog();
return;
}
const data = message.data || {};
if (message.event === 'control_plan.updated') { app.controlPlanPushReady = true; stopControlPlanFallback(); applyControlPlan(data.plan, data.revision); }
-46
View File
@@ -9,52 +9,6 @@ const SETTINGS_ENDPOINTS = {
debug: '/api/settings/debug',
};
async function fetchSettingsSections() {
const [application, gree, history, influxdb, notifications, night, homeAssistant, debug] = await Promise.all([
api(SETTINGS_ENDPOINTS.application),
api(SETTINGS_ENDPOINTS.gree),
api(SETTINGS_ENDPOINTS.history),
api(SETTINGS_ENDPOINTS.influxdb),
api(SETTINGS_ENDPOINTS.notifications),
api(SETTINGS_ENDPOINTS.night),
api(SETTINGS_ENDPOINTS.homeAssistant),
api(SETTINGS_ENDPOINTS.debug),
]);
return { application, gree, history, influxdb, notifications, night, homeAssistant, debug };
}
function aggregateSettingsSections(sections, houseMode = app.settings?.house_mode || 'cool') {
return {
simulator_enabled: !!sections.application.simulator_enabled,
controller_id: sections.gree.controller_id,
poll_interval_seconds: Number(sections.gree.poll_interval_seconds),
zone_interval_seconds: Number(sections.gree.zone_interval_seconds),
discovery_timeout_ms: Number(sections.gree.discovery_timeout_ms),
discovery_broadcast: sections.gree.discovery_broadcast,
suppress_device_beep: !!sections.gree.suppress_device_beep,
compressor_protection_enabled: sections.gree.compressor_protection_enabled !== false,
compressor_protection_seconds: Number(sections.gree.compressor_protection_seconds),
history_retention_days: Number(sections.history.retention_days),
history_compaction_enabled: sections.history.compaction_enabled !== false,
event_log_retention_days: Number(sections.history.event_retention_days),
influxdb: sections.influxdb,
notifications: sections.notifications,
night_mode: sections.night,
home_assistant: sections.homeAssistant,
outdoor_assist_enabled: !!sections.homeAssistant.outdoor_assist_enabled,
debug: sections.debug,
house_mode: houseMode || 'cool',
};
}
async function loadSettingsSections(houseMode = app.settings?.house_mode || 'cool') {
const sections = await fetchSettingsSections();
app.settings = aggregateSettingsSections(sections, houseMode);
app.sensorAliases = { ...(app.settings.home_assistant?.sensor_aliases || {}) };
app.flowSharedInputs = JSON.parse(JSON.stringify(app.settings.home_assistant?.flow_inputs || []));
return app.settings;
}
function applySettingsSection(section, data) {
app.settings = app.settings || {};
if (section === 'application') app.settings.simulator_enabled = !!data.simulator_enabled;