Files
KX-Bridge-Release/bridge_constants.py
viewit 6ab5c31035
All checks were successful
Testing Build / build (push) Successful in 8m44s
feat(kxgauge): add KXGauge round-display integration
Adds an optional per-printer integration with KXGauge
(https://gitea.it-drui.de/viewit/kxgauge), a small ESP32 round-face
display that shows printer status as an emotion and hotend temperature
as a color ring. KXGauge only exposes a GET-only HTTP API with no
push/websocket, so the bridge actively pushes to it from the existing
MQTT callbacks (_on_temp for the heat ring, _on_print + offline
transitions for the emotion) whenever state actually changes, with a
built-in dedupe so it doesn't spam the device every poll tick.

- kxgauge_client.py: thin synchronous HTTP client (mirrors
  spoolman_client.py's shape - called from the MQTT reader thread).
- New [kxgauge]/[kxgauge_mapping] config.ini sections; the mapping
  (kobra_state -> KXGauge emotion) is user-editable with a sane
  default and falls back per-key if only partially configured.
- Settings UI: new card under Integrations with enable/URL/target-temp
  fields, a per-state emotion mapping list, and a connection-test
  button (/api/kxgauge/test).
- Multi-printer aware: kxgauge_url/enabled/heat_peak merge per
  [printer_N] like the existing power-switch settings.

Also fixes a real bug found while testing this: _find_config_path()
resolves to the live project config/config.ini, not a sandboxed path,
so any test hitting /api/settings POST without stubbing it out will
silently overwrite the real printer config. test_settings.py already
guards against this - test_kxgauge.py now does too.
2026-08-05 15:13:43 +02:00

57 lines
2.0 KiB
Python

"""
bridge_constants.py - shared constants for the bridge modules.
Extracted so the mixin modules can import these without a circular dependency
on the kobrax_moonraker_bridge facade. Re-exported from there for callers.
────────────────────────────────────────────────────────────────────────────
Copyright (C) 2026 viewit (KX-Bridge contributors)
Licensed under GPLv3 — see LICENSE in the project root. See NOTICE.md.
"""
# Maps the printer's own MQTT state strings to Klipper/Moonraker print states.
KOBRA_TO_KLIPPER_STATE = {
"free": "standby",
"busy": "printing",
"printing": "printing",
"preheating": "printing",
"auto_leveling": "printing",
"checking": "printing",
"updated": "printing",
"init": "printing",
"pausing": "paused",
"paused": "paused",
"resuming": "printing",
"resumed": "printing",
"stopping": "printing",
"stoped": "standby",
"finished": "complete",
"failed": "error",
"canceled": "standby",
}
MOONRAKER_VERSION = "v0.9.3-1"
KLIPPER_VERSION = "v0.12.0-1"
# Default kobra_state -> KXGauge emotion mapping (used when [kxgauge_mapping]
# is absent or incomplete in config.ini).
DEFAULT_KXGAUGE_MAPPING = {
"free": "neutral",
"printing": "happy",
"paused": "worried",
"pause": "worried",
"finished": "glee",
"error": "scared",
"offline": "tired",
}
# Valid KXGauge emotion names (see kxgauge/API.md) - used to reject garbage
# values coming in through the settings save.
KXGAUGE_VALID_EMOTIONS = {
"neutral", "happy", "angry", "tired", "surprised", "curious", "confused",
"sleepy", "love", "dizzy", "crying", "focused", "glee", "sad", "worried",
"annoyed", "skeptic", "frustrated", "unimpressed", "suspicious", "squint",
"furious", "scared", "awe",
}