mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-21 10:15:04 +02:00
feat(printers): airduct mode + status badges + force refresh on printer card
Surface four Home Assistant-style controls on the Printers page card:
- SD Card badge in the top status row (green / red, icon-only).
- Enclosure Door badge in the top status row (green / yellow, icon-only).
Detection per printer family — X1/X1C/X1E read home_flag bit 23, all
others read top-level `stat` (hex string) bit 23 — so X1 firmware that
does not flip stat bit 23 stops false-triggering "open". WebSocket
status-change dedup key now includes door_open so toggling the door
alone publishes a push, no 30s REST-poll wait.
- Airduct Mode badge beside the speed control (cooling / heating)
for P2S/H2D/H2C/H2S; one-click dropdown calls the existing
set_airduct MQTT command via a new POST /printers/{id}/airduct-mode
route.
- Force Refresh entry in the kebab menu — calls the existing
/printers/{id}/refresh-status endpoint to request a pushall snapshot
without forcing a reconnect.
Tests: door-open parsing (X1 home_flag, non-X1 stat, ignore mismatched
source, invalid hex) and airduct route (validation, not-connected,
success, failure).
This commit is contained in:
@@ -583,6 +583,7 @@ async def get_printer_status(
|
||||
ipcam=state.ipcam,
|
||||
wifi_signal=state.wifi_signal,
|
||||
wired_network=state.wired_network,
|
||||
door_open=state.door_open,
|
||||
nozzles=nozzles,
|
||||
nozzle_rack=nozzle_rack,
|
||||
print_options=print_options,
|
||||
@@ -2333,6 +2334,33 @@ async def set_print_speed(
|
||||
return {"success": True, "message": f"Print speed set to {speed_names.get(mode, 'Unknown')}"}
|
||||
|
||||
|
||||
@router.post("/{printer_id}/airduct-mode")
|
||||
async def set_airduct_mode(
|
||||
printer_id: int,
|
||||
mode: str = Query(..., description="Airduct mode: 'cooling' or 'heating'"),
|
||||
_=RequirePermissionIfAuthEnabled(Permission.PRINTERS_CONTROL),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""Set the airduct mode (cooling/heating) on supported printers (P2S/H2*)."""
|
||||
if mode not in ("cooling", "heating"):
|
||||
raise HTTPException(400, "Mode must be 'cooling' or 'heating'")
|
||||
|
||||
result = await db.execute(select(Printer).where(Printer.id == printer_id))
|
||||
printer = result.scalar_one_or_none()
|
||||
if not printer:
|
||||
raise HTTPException(404, "Printer not found")
|
||||
|
||||
client = printer_manager.get_client(printer_id)
|
||||
if not client:
|
||||
raise HTTPException(400, "Printer not connected")
|
||||
|
||||
success = client.set_airduct_mode(mode)
|
||||
if not success:
|
||||
raise HTTPException(500, "Failed to set airduct mode")
|
||||
|
||||
return {"success": True, "message": f"Airduct mode set to {mode}"}
|
||||
|
||||
|
||||
@router.post("/{printer_id}/chamber-light")
|
||||
async def set_chamber_light(
|
||||
printer_id: int,
|
||||
|
||||
Reference in New Issue
Block a user