feat(printer): add smart-plug power switch button (Issue #103); fix(update): stable update check missing behind prereleases (Issue #104)

Issue #103: the printer has no MQTT-level command to power off or enter
standby, so users on a separate-room setup have to physically walk over
or use a smart plug (e.g. Tasmota) manually. Added per-printer
power_on_url/power_off_url/power_status_url config (Settings > Power
Switch) and a power button with a live on/off indicator on each printer's
card in the Printers grid - plain HTTP GET calls, no Moonraker
device_power dependency.

Issue #104: the stable-release update check only ever requested the
single newest Gitea release (limit=1) regardless of type. Since
nightly/dev prereleases publish far more often than stable ones, that
newest release is almost always a prerelease, so the "not a prerelease"
filter found nothing and reported "no stable releases found" even
though a newer stable release existed further back in the list.
Fixed by requesting enough releases (limit=20) to look past a run of
prereleases.

Also fixes a related pre-existing bug surfaced while testing #103's
config: configparser's default string interpolation rejected any
config.ini value containing a literal '%' (ValueError: invalid
interpolation syntax) - this broke saving Tasmota-style power URLs
(cmnd=Power%20on) and would have broken any other value with a '%'
character. Fixed globally with interpolation=None on every
ConfigParser() instantiation in config_loader.py and
kobrax_moonraker_bridge.py.
This commit is contained in:
2026-08-02 15:59:35 +02:00
parent 0a9bf6def6
commit ecc53cd7cb
14 changed files with 462 additions and 14 deletions

View File

@@ -450,6 +450,11 @@ function applyLang(){
setText('lbl-password',T.settings_password);
setText('lbl-device-id',T.settings_device_id);
setText('lbl-mode-id',T.settings_mode_id);
setText('modal-sec-power',T.settings_power||'Power Switch');
setText('lbl-power-on-url',T.settings_power_on_url||'Power-On URL');
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-default-slot',T.settings_default_slot);
setText('opt-slot-auto',T.settings_slot_auto);
setText('lbl-auto-leveling',T.settings_auto_leveling);
@@ -1127,6 +1132,9 @@ function openSettings(){
document.getElementById('s-password').value=d.password||'';
document.getElementById('s-device-id').value=d.device_id||'';
document.getElementById('s-mode-id').value=d.mode_id||'';
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||'';
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;
@@ -1895,6 +1903,9 @@ function saveSettings(){
password: document.getElementById('s-password').value,
device_id: document.getElementById('s-device-id').value,
mode_id: document.getElementById('s-mode-id').value,
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||'',
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,
@@ -3984,6 +3995,7 @@ function loadPrinterTab(){
'<span style="font-weight:700;font-size:14px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">🖨 '+p.name+'</span>'+
'<span style="display:flex;align-items:center;gap:8px;flex-shrink:0">'+
(isActive?'<span style="font-size:11px;color:var(--accent);font-weight:600">'+T.printers_active+'</span>':'')+
(p.has_power_control?'<button id="power-btn-'+printerNum+'" onclick="togglePrinterPower(\''+printerNum+'\')" title="'+T.printers_power+'" style="background:none;border:none;color:var(--txt2);font-size:16px;cursor:pointer;line-height:1;padding:0">🔌</button>':'')+
'<button onclick="removePrinter(\''+printerNum+'\',\''+nameEsc+'\')" title="'+T.printers_remove+'" style="background:none;border:none;color:var(--txt2);font-size:16px;cursor:pointer;line-height:1;padding:0">✕</button>'+
'</span>'+
'</div>'+
@@ -4000,8 +4012,40 @@ function loadPrinterTab(){
(!isActive?'<a href="'+url+'/printer'+printerNum+'" style="display:block;text-align:center;padding:7px;background:var(--accent);color:#fff;border-radius:7px;font-size:13px;font-weight:600;text-decoration:none;margin-top:4px">'+T.printers_switch+'</a>':'<div style="text-align:center;padding:7px;font-size:12px;color:var(--txt2)">'+T.printers_current+'</div>')+
'</div>';
}).join('');
results.forEach(function(res){
if(res.printer.has_power_control)_refreshPrinterPowerIcon(res.printer.id,(res.printer.bridge_url||'').replace(/\/+$/,''));
});
});
}).catch(function(e){
if(grid)grid.innerHTML='<div style="color:var(--err);font-size:13px;padding:20px">Fehler: '+e+'</div>';
});
}
function _refreshPrinterPowerIcon(pid,bridgeUrl){
fetch((bridgeUrl||'')+'/kx/printers/'+encodeURIComponent(pid)+'/power-status',{signal:AbortSignal.timeout(5000)})
.then(function(r){return r.json()})
.then(function(d){
var btn=document.getElementById('power-btn-'+pid);
if(!btn)return;
if(d.state==='on'){btn.style.color='var(--ok)';btn.title=T.printers_power_on||'Power: On';}
else if(d.state==='off'){btn.style.color='var(--txt2)';btn.title=T.printers_power_off||'Power: Off';}
})
.catch(function(){/* status endpoint optional - icon just stays neutral */});
}
function togglePrinterPower(pid){
var btn=document.getElementById('power-btn-'+pid);
var currentlyOn=btn&&btn.style.color&&btn.style.color.indexOf('var(--ok)')!==-1;
// Without a known current state, default to "on" - turning an already-off
// switch on is harmless, whereas guessing "off" on a printer mid-print is not.
var action=currentlyOn?'off':'on';
if(action==='off'&&!confirm(T.printers_power_off_confirm||'Turn printer power off? Make sure no print is running.'))return;
if(btn)btn.style.opacity='0.5';
post('/kx/printers/'+encodeURIComponent(pid)+'/power',{action:action}).then(function(){
if(btn)btn.style.opacity='1';
setTimeout(function(){loadPrinterTab();},1500);
}).catch(function(e){
if(btn)btn.style.opacity='1';
clog('Power-Fehler: '+e,'msg-err');
});
}

View File

@@ -548,6 +548,22 @@
<input type="text" id="s-mode-id" placeholder="20030">
</div>
</div>
<div class="card">
<div class="card-title"><span>🔌</span> <span id="modal-sec-power">Power Switch</span></div>
<div class="modal-field">
<label id="lbl-power-on-url">Power-On URL</label>
<input type="text" id="s-power-on-url" placeholder="http://192.168.x.x/cm?cmnd=Power%20on">
</div>
<div class="modal-field">
<label id="lbl-power-off-url">Power-Off URL</label>
<input type="text" id="s-power-off-url" placeholder="http://192.168.x.x/cm?cmnd=Power%20off">
</div>
<div class="modal-field">
<label id="lbl-power-status-url">Status URL</label>
<input type="text" id="s-power-status-url" placeholder="http://192.168.x.x/cm?cmnd=Power">
<small id="lbl-power-hint" style="color:var(--txt2)"></small>
</div>
</div>
</div>
<!-- Drucker -->