This commit is contained in:
Mateusz Gruszczyński
2026-08-29 22:07:54 +02:00
parent 930cb7b1e1
commit 2383526a83
16 changed files with 296 additions and 79 deletions
+55 -7
View File
@@ -28,7 +28,7 @@ const app = {
historyZone: 'all', historyDevice: 'all', historySensor: 'all', historyLoading: false,
customChartSeries: [], savedCharts: [], zoneControlSeq: {}, zoneTemperatureTimers: {},
controlPlan: null, controlPlanTimer: null, debugLines: [], debugBacklogLoaded: false, sensorAliases: {},
simulationScope: 'units', simulationTarget: 'all', standaloneSimulation: false,
simulationScope: 'units', simulationTarget: 'all', standaloneSimulation: false, dashboardTab: 'main',
};
try { app.savedCharts = JSON.parse(localStorage.getItem('gree_controller_saved_charts') || '[]'); } catch (_) { app.savedCharts = []; }
@@ -335,6 +335,8 @@ function renderSummary() {
const online = app.devices.filter(d => d.online).length;
const active = app.devices.filter(d => d.power).length;
const demand = app.zones.filter(z => z.enabled && z.demand).length;
const toolbarStatus = $('#toolbarRuntimeStatus');
if (toolbarStatus) toolbarStatus.textContent = tr('dashboard.toolbarWorking', {active, total:app.devices.length});
$('#heroTemperature').innerHTML = `${average === null ? '--' : average.toFixed(1)}<small>°C</small>`;
const activeSuffix = active ? tr('dashboard.summaryActive', {count: active}) : '';
$('#summaryText').textContent = app.devices.length
@@ -804,9 +806,9 @@ function zoneControlOwnerLabel(zone) {
function zoneControlOwnerMeta(zone) {
const parts=[];
if(zone.control_since) parts.push(`${tr('zones.ownerSince')} ${new Date(zone.control_since).toLocaleTimeString(locale(),{hour:'2-digit',minute:'2-digit'})}`);
if(zone.control_resume_at) parts.push(`${tr('zones.ownerResume')} ${new Date(zone.control_resume_at).toLocaleTimeString(locale(),{hour:'2-digit',minute:'2-digit'})}`);
if(zone.lockout_until && new Date(zone.lockout_until)>new Date()) parts.push(`${tr('zones.lockoutUntil')} ${new Date(zone.lockout_until).toLocaleTimeString(locale(),{hour:'2-digit',minute:'2-digit'})}`);
if(zone.control_since) parts.push(`${tr('zones.ownerSince')} ${dateTime(zone.control_since)}`);
if(zone.control_resume_at) parts.push(`${tr('zones.ownerResume')} ${dateTime(zone.control_resume_at)}`);
if(zone.lockout_until && new Date(zone.lockout_until)>new Date()) parts.push(`${tr('zones.lockoutUntil')} ${dateTime(zone.lockout_until)}`);
return parts.join(' · ');
}
@@ -1112,6 +1114,15 @@ function renderSettings() {
form.slack_webhook_url.placeholder=n.slack_configured?'Saved - leave empty to keep':'https://hooks.slack.com/services/…';
form.discord_webhook_url.placeholder=n.discord_configured?'Saved - leave empty to keep':'https://discord.com/api/webhooks/…';
form.notification_cooldown_seconds.value=n.cooldown_seconds||300; form.notification_failure_threshold.value=n.communication_failure_threshold||3; form.notification_target_timeout.value=n.target_timeout_minutes||60;
const alerts=n.alert_types||{};
form.notification_alert_stale_sensor.checked=alerts.stale_sensor!==false;
form.notification_alert_sensor_errors.checked=alerts.sensor_errors!==false;
form.notification_alert_communication.checked=alerts.communication!==false;
form.notification_alert_target_timeout.checked=alerts.target_timeout!==false;
form.notification_alert_automation.checked=alerts.automation!==false;
form.notification_alert_control_errors.checked=alerts.control_errors!==false;
form.notification_alert_important_events.checked=alerts.important_events!==false;
form.notification_alert_other.checked=alerts.other!==false;
updateNotificationFields();
updateInfluxFields();
renderLogRetention();
@@ -1226,12 +1237,29 @@ function updateBrowserUrl(path, replace=false) {
history[replace ? 'replaceState' : 'pushState']({}, '', target);
}
function setDashboardTab(tab, {scroll=true}={}) {
const next = ['main','thermostats','manual'].includes(tab) ? tab : 'main';
app.dashboardTab = next;
$$('[data-dashboard-tab]').forEach(button => {
const active = button.dataset.dashboardTab === next;
button.classList.toggle('active', active);
button.setAttribute('aria-selected', String(active));
});
$$('[data-dashboard-panel]').forEach(panel => {
const active = panel.dataset.dashboardPanel === next;
panel.classList.toggle('active', active);
panel.hidden = !active;
});
if (scroll && app.currentView === 'dashboard') window.scrollTo({top:0, behavior:'smooth'});
}
function showView(name, {push=true, scroll=true}={}) {
app.currentView = name;
$$('.view').forEach(view => view.classList.toggle('active', view.dataset.view === name));
$$('.bottom-nav button').forEach(button => button.classList.toggle('active', button.dataset.nav === name || (button.dataset.nav === 'more' && ['groups','schedules','automations','simulation','night','homeassistant','settings','logs'].includes(name))));
if (push) updateBrowserUrl(name === 'history' ? currentHistoryPath() : (VIEW_ROUTES[name] || '/dashboard'));
if (scroll) window.scrollTo({top: 0, behavior: 'smooth'});
if (name === 'dashboard') setDashboardTab(app.dashboardTab, {scroll:false});
if (name === 'history') { renderHistoryNavigation(); loadHistory(); }
if (name === 'logs') loadLogs();
}
@@ -1920,6 +1948,7 @@ function connectWebSocket() {
document.addEventListener('click', async event => {
const button = event.target.closest('button'); if (!button) return;
if (button.dataset.dashboardTab) { setDashboardTab(button.dataset.dashboardTab); return; }
if (button.dataset.nav) {
if (button.dataset.nav === 'more') openDialog('moreDialog'); else showView(button.dataset.nav);
return;
@@ -2015,9 +2044,8 @@ document.addEventListener('click', async event => {
}
if (action === 'zone-go-control') {
showView('dashboard', {scroll:false});
setDashboardTab('thermostats', {scroll:false});
const target = [...document.querySelectorAll('[data-zone-card]')].find(card => card.dataset.zoneCard === button.dataset.id);
const disclosure = target?.closest('details.dashboard-disclosure');
if (disclosure) disclosure.open = true;
requestAnimationFrame(() => target?.scrollIntoView({behavior:'smooth', block:'center'}));
return;
}
@@ -2064,7 +2092,7 @@ $('#simulationOpenTab')?.addEventListener('click', () => { const params=new URLS
$('#simulationFullscreen')?.addEventListener('click', async () => { try { if(document.fullscreenElement) await document.exitFullscreen(); else await document.documentElement.requestFullscreen(); } catch(error) { toast(error.message, true); } });
document.addEventListener('fullscreenchange', () => { const button=$('#simulationFullscreen'); if(button) button.textContent=tr(document.fullscreenElement?'simulation.exitFullscreen':'simulation.fullscreen'); });
$('#testNotifications')?.addEventListener('click', async () => { const f=$('#settingsForm'); const saved=app.settings?.notifications||{}; const body={enabled:true,mode:f.notifications_mode.value,provider:f.notifications_provider.value,pushover_app_token:f.pushover_app_token.value.trim(),pushover_user_key:f.pushover_user_key.value.trim(),slack_webhook_url:f.slack_webhook_url.value.trim(),discord_webhook_url:f.discord_webhook_url.value.trim(),cooldown_seconds:Number(f.notification_cooldown_seconds.value||300),communication_failure_threshold:Number(f.notification_failure_threshold.value||3),target_timeout_minutes:Number(f.notification_target_timeout.value||60)}; try{await api('/api/integrations/notifications/test',{method:'POST',body});toast('Test notification sent');}catch(e){toast(e.message,true);} });
$('#testNotifications')?.addEventListener('click', async () => { const f=$('#settingsForm'); const body={enabled:true,mode:f.notifications_mode.value,provider:f.notifications_provider.value,pushover_app_token:f.pushover_app_token.value.trim(),pushover_user_key:f.pushover_user_key.value.trim(),slack_webhook_url:f.slack_webhook_url.value.trim(),discord_webhook_url:f.discord_webhook_url.value.trim(),cooldown_seconds:Number(f.notification_cooldown_seconds.value||300),communication_failure_threshold:Number(f.notification_failure_threshold.value||3),target_timeout_minutes:Number(f.notification_target_timeout.value||60),alert_types:{stale_sensor:f.notification_alert_stale_sensor.checked,sensor_errors:f.notification_alert_sensor_errors.checked,communication:f.notification_alert_communication.checked,target_timeout:f.notification_alert_target_timeout.checked,automation:f.notification_alert_automation.checked,control_errors:f.notification_alert_control_errors.checked,important_events:f.notification_alert_important_events.checked,other:f.notification_alert_other.checked}}; try{await api('/api/integrations/notifications/test',{method:'POST',body});toast(tr('notifications.testSent'));}catch(e){toast(e.message,true);} });
$('#copyZoneSettings')?.addEventListener('click',()=>{
const f=$('#zoneForm');
@@ -2279,6 +2307,16 @@ function currentSettingsBody() {
enabled: !!settings.notifications?.enabled, mode: settings.notifications?.mode || 'problems', provider: settings.notifications?.provider || 'pushover',
pushover_app_token: '', pushover_user_key: '', slack_webhook_url: '', discord_webhook_url: '',
cooldown_seconds: Number(settings.notifications?.cooldown_seconds || 300), communication_failure_threshold: Number(settings.notifications?.communication_failure_threshold || 3), target_timeout_minutes: Number(settings.notifications?.target_timeout_minutes || 60),
alert_types: {
stale_sensor: settings.notifications?.alert_types?.stale_sensor !== false,
sensor_errors: settings.notifications?.alert_types?.sensor_errors !== false,
communication: settings.notifications?.alert_types?.communication !== false,
target_timeout: settings.notifications?.alert_types?.target_timeout !== false,
automation: settings.notifications?.alert_types?.automation !== false,
control_errors: settings.notifications?.alert_types?.control_errors !== false,
important_events: settings.notifications?.alert_types?.important_events !== false,
other: settings.notifications?.alert_types?.other !== false,
},
},
night_mode: {
enabled: !!settings.night_mode?.enabled,
@@ -2343,6 +2381,16 @@ function settingsBodyFromForm(form) {
cooldown_seconds: Number(raw.notification_cooldown_seconds || 300),
communication_failure_threshold: Number(raw.notification_failure_threshold || 3),
target_timeout_minutes: Number(raw.notification_target_timeout || 60),
alert_types: {
stale_sensor: form.notification_alert_stale_sensor.checked,
sensor_errors: form.notification_alert_sensor_errors.checked,
communication: form.notification_alert_communication.checked,
target_timeout: form.notification_alert_target_timeout.checked,
automation: form.notification_alert_automation.checked,
control_errors: form.notification_alert_control_errors.checked,
important_events: form.notification_alert_important_events.checked,
other: form.notification_alert_other.checked,
},
};
return body;
}