This commit is contained in:
Mateusz Gruszczyński
2026-09-01 15:38:46 +02:00
parent 1392114c1e
commit 3000dbaf01
26 changed files with 7520 additions and 2299 deletions
+21 -21
View File
@@ -66,7 +66,7 @@ function currentSettingsBody() {
outdoor_entity_id: ha.outdoor_entity_id || '',
sensor_stale_after_seconds: Number(ha.sensor_stale_after_seconds || 300),
allow_invalid_tls: !!ha.allow_invalid_tls,
sensor_aliases: {...(ha.sensor_aliases || {})},
sensor_aliases: { ...(ha.sensor_aliases || {}) },
},
};
}
@@ -92,7 +92,7 @@ function settingsBodyFromForm(form) {
org: raw.influx_org, bucket: raw.influx_bucket, token: raw.influx_token,
history_threshold_days: Number(raw.influx_threshold_days),
};
body.debug = {overlay_enabled: form.debug_overlay_enabled.checked, gree_frames: form.debug_gree_frames.checked};
body.debug = { overlay_enabled: form.debug_overlay_enabled.checked, gree_frames: form.debug_gree_frames.checked };
body.notifications = {
enabled: form.notifications_enabled.checked, mode: raw.notifications_mode, provider: raw.notifications_provider,
pushover_app_token: raw.pushover_app_token || '', pushover_user_key: raw.pushover_user_key || '',
@@ -139,14 +139,14 @@ function homeAssistantSettingsBodyFromForm(form) {
outdoor_entity_id: raw.ha_outdoor_entity_id,
sensor_stale_after_seconds: Math.max(60, Math.min(86400, Math.round(Number(raw.ha_sensor_stale_after_minutes || 5) * 60))),
allow_invalid_tls: form.ha_allow_invalid_tls.checked,
sensor_aliases: {...(app.sensorAliases || {})},
sensor_aliases: { ...(app.sensorAliases || {}) },
};
return body;
}
async function saveRuntimeSettings(body, notify = true) {
app.settings = await api('/api/settings', {method:'PUT', body});
app.sensorAliases = {...(app.settings?.home_assistant?.sensor_aliases || {})};
app.settings = await api('/api/settings', { method: 'PUT', body });
app.sensorAliases = { ...(app.settings?.home_assistant?.sensor_aliases || {}) };
renderSettings();
renderNightSettings();
renderHomeAssistantSettings();
@@ -202,10 +202,10 @@ document.addEventListener('click', event => {
$('#saveLogRetention')?.addEventListener('click', async () => {
const days = Number($('#logRetentionDays')?.value || 30);
try {
const result = await api('/api/events/retention', {method:'PUT', body:{days}});
const result = await api('/api/events/retention', { method: 'PUT', body: { days } });
app.settings.event_log_retention_days = result.days;
$('#settingsForm').event_log_retention_days.value = result.days;
renderLogRetention(); await loadLogs(); toast(tr('logs.retentionSaved', {days: result.days}));
renderLogRetention(); await loadLogs(); toast(tr('logs.retentionSaved', { days: result.days }));
} catch (error) { toast(error.message, true); }
});
@@ -213,7 +213,7 @@ $('#createAccessToken').addEventListener('click', async event => {
const button = event.currentTarget;
button.disabled = true;
try {
const result = await api('/api/access-tokens', {method:'POST', body:{name:'Home Assistant'}});
const result = await api('/api/access-tokens', { method: 'POST', body: { name: 'Home Assistant' } });
if (result.item) app.accessTokens.unshift(result.item);
renderAccessTokens();
$('#generatedAccessToken').value = result.token || '';
@@ -236,7 +236,7 @@ $('#copyAccessToken').addEventListener('click', async () => {
});
$('#haTest').addEventListener('click', async event => {
const form=$('#homeAssistantForm'), button=event.currentTarget;
const form = $('#homeAssistantForm'), button = event.currentTarget;
if (!validateForm(form)) return;
button.disabled = true;
const idle = button.textContent;
@@ -244,11 +244,11 @@ $('#haTest').addEventListener('click', async event => {
try {
await saveRuntimeSettings(homeAssistantSettingsBodyFromForm(form), false);
const entity = form.ha_entity_id.value || form.ha_outdoor_entity_id.value || null;
const result=await api('/api/integrations/home-assistant/test',{method:'POST',body:{entity_id:entity}});
const result = await api('/api/integrations/home-assistant/test', { method: 'POST', body: { entity_id: entity } });
markFormClean(form);
toast(tr('toast.haTemperature',{temperature:result.temperature_c.toFixed(1)}));
} catch(error){presentFormError(form,error);}
finally { button.disabled=false; button.textContent=idle; }
toast(tr('toast.haTemperature', { temperature: result.temperature_c.toFixed(1) }));
} catch (error) { presentFormError(form, error); }
finally { button.disabled = false; button.textContent = idle; }
});
$('#simulationRefresh')?.addEventListener('click', async () => {
@@ -259,10 +259,10 @@ $('#simulationRefresh')?.addEventListener('click', async () => {
$('#exportSettings').addEventListener('click', async () => {
try {
const data = await api('/api/settings/export');
const blob = new Blob([JSON.stringify(data, null, 2)], {type:'application/json'});
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = `gree-controller-settings-${new Date().toISOString().slice(0,10)}.json`;
link.download = `gree-controller-settings-${new Date().toISOString().slice(0, 10)}.json`;
document.body.appendChild(link); link.click(); link.remove(); URL.revokeObjectURL(link.href);
toast(tr('toast.exported'));
} catch (error) { toast(error.message, true); }
@@ -274,7 +274,7 @@ $('#importSettingsFile').addEventListener('change', async event => {
try {
if (!confirm(tr('settings.importConfirm'))) return;
const body = JSON.parse(await file.text());
await api('/api/settings/import', {method:'POST', body});
await api('/api/settings/import', { method: 'POST', body });
app.debugBacklogLoaded = false;
await loadBootstrap();
toast(tr('toast.imported'));
@@ -283,11 +283,11 @@ $('#importSettingsFile').addEventListener('change', async event => {
});
document.addEventListener('change', event => {
const target=event.target;
if(target.id==='historyZoneSelect'){app.historyZone=target.value;updateBrowserUrl(currentHistoryPath());renderHistoryPage();}
else if(target.id==='historyDeviceSelect'){app.historyDevice=target.value;updateBrowserUrl(currentHistoryPath());renderHistoryPage();}
else if(target.id==='historySensorSelect'){app.historySensor=target.value;updateBrowserUrl(currentHistoryPath());renderHistoryPage();}
else if(target.name==='influx_version') updateInfluxFields();
const target = event.target;
if (target.id === 'historyZoneSelect') { app.historyZone = target.value; updateBrowserUrl(currentHistoryPath()); renderHistoryPage(); }
else if (target.id === 'historyDeviceSelect') { app.historyDevice = target.value; updateBrowserUrl(currentHistoryPath()); renderHistoryPage(); }
else if (target.id === 'historySensorSelect') { app.historySensor = target.value; updateBrowserUrl(currentHistoryPath()); renderHistoryPage(); }
else if (target.name === 'influx_version') updateInfluxFields();
});