feat(power): add setting to show current status instead of action

Reddit report: the header power toggle switches correctly but
displays "backwards" - the button shows the action a click would
perform (e.g. "Aus" while the printer is on), not the printer's
actual current state, which some users find counterintuitive.

Both readings are legitimate, so this adds a per-printer opt-in
(Settings -> Power Switch -> "Aktuellen Status statt Aktion
anzeigen") rather than flipping the default for everyone.
power_status_inverted=0 (default) keeps today's behavior; =1 mirrors
the actual on/off state instead. The backend's power-status parsing
is untouched - only _applyHeaderPowerState() picks which state to
display, so the click handler still always toggles the real state
regardless of display mode.
This commit is contained in:
2026-09-01 17:31:38 +02:00
parent b44c9021a0
commit 7d28ed4e92
11 changed files with 30 additions and 2 deletions

View File

@ -355,10 +355,17 @@ function _applyHeaderPowerState(state){
_headerPowerState=state;
var btn=document.getElementById('h-power-btn'), lbl=document.getElementById('h-power-lbl');
if(!btn||!lbl)return;
if(state==='on'){
// Default: show the action a click would perform (printer on -> offer
// "Aus"). With power_status_inverted set (Settings -> Power Switch), show
// the actual current state instead (printer on -> show "An") - some users
// expect the button to mirror reality, not the available action.
var inverted=!!(_activePrinter&&_activePrinter.power_status_inverted);
var showOn=inverted?state==='on':state==='off';
var showOff=inverted?state==='off':state==='on';
if(showOff){
btn.classList.remove('h-power-can-on');btn.classList.add('h-power-can-off');
lbl.textContent=T.printers_power_off_short||'Aus';
}else if(state==='off'){
}else if(showOn){
btn.classList.remove('h-power-can-off');btn.classList.add('h-power-can-on');
lbl.textContent=T.printers_power_on_short||'An';
}else{
@ -572,6 +579,7 @@ function applyLang(){
setText('lbl-power-off-url',T.settings_power_off_url||'Power-Off URL');
setText('lbl-power-status-url',T.settings_power_status_url||'Status URL');
setText('lbl-power-hint',T.settings_power_hint||'Optional: plain HTTP GET URLs for a smart plug (e.g. Tasmota) controlling the printer\'s mains power. Leave empty to hide the power button.');
setText('lbl-power-status-inverted',T.settings_power_status_inverted||'Show current status instead of action');
setText('lbl-default-slot',T.settings_default_slot);
setText('opt-slot-auto',T.settings_slot_auto);
setText('lbl-auto-leveling',T.settings_auto_leveling);
@ -1254,6 +1262,7 @@ function openSettings(){
var pon=document.getElementById('s-power-on-url');if(pon)pon.value=d.power_on_url||'';
var poff=document.getElementById('s-power-off-url');if(poff)poff.value=d.power_off_url||'';
var pstat=document.getElementById('s-power-status-url');if(pstat)pstat.value=d.power_status_url||'';
var pinv=document.getElementById('s-power-status-inverted');if(pinv)pinv.checked=!!d.power_status_inverted;
document.getElementById('s-default-slot').value=d.default_ams_slot||'auto';
document.getElementById('s-auto-leveling').checked=(d.auto_leveling===undefined?true:!!d.auto_leveling);
var vc=document.getElementById('s-vibration-compensation');if(vc)vc.checked=!!d.vibration_compensation;
@ -2033,6 +2042,7 @@ function saveSettings(){
power_on_url: (document.getElementById('s-power-on-url')||{}).value||'',
power_off_url: (document.getElementById('s-power-off-url')||{}).value||'',
power_status_url: (document.getElementById('s-power-status-url')||{}).value||'',
power_status_inverted: (document.getElementById('s-power-status-inverted')||{}).checked?1:0,
default_ams_slot: document.getElementById('s-default-slot').value,
auto_leveling: document.getElementById('s-auto-leveling').checked?1:0,
vibration_compensation: (document.getElementById('s-vibration-compensation')||{}).checked?1:0,