mirror of
https://github.com/RunLit/Bambu-Run.git
synced 2026-08-22 06:44:19 +01:00
The printer publishes partial deltas most of the time; the accumulator merges each one onto whatever state it already has. When the printer powers off, our cloud MQTT connection stays up (it's a persistent session to Bambu's broker, not a socket to the printer), so nothing signals the outage. When the printer reconnects and resumes its normal partial updates, those deltas get merged onto the stale pre-outage state — fields the delta doesn't mention (e.g. nozzle_temp) stay frozen at their old values. Sending any command happens to trigger a full report from the printer, which is why toggling the light "fixes" it. Track the time of the last message per BambuPrinter instance. When a new message arrives after a gap longer than BAMBU_RUN_MQTT_RESYNC_GAP_SECONDS (default 90s), request a pushall before processing it, forcing a complete state refresh instead of trusting the partial delta to overwrite stale fields.
93 lines
2.6 KiB
Python
93 lines
2.6 KiB
Python
"""
|
|
App-level settings with sensible defaults.
|
|
|
|
Override in your Django settings.py:
|
|
BAMBU_RUN_TIMEZONE = 'Australia/Melbourne'
|
|
BAMBU_RUN_BASE_TEMPLATE = 'base/base.html'
|
|
"""
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
def get_setting(name, default):
|
|
return getattr(settings, name, default)
|
|
|
|
|
|
# Timezone for all timestamp display and queries
|
|
BAMBU_RUN_TIMEZONE = property(lambda self: get_setting("BAMBU_RUN_TIMEZONE", "UTC"))
|
|
|
|
# Base template that all bambu_run templates extend
|
|
BAMBU_RUN_BASE_TEMPLATE = property(
|
|
lambda self: get_setting("BAMBU_RUN_BASE_TEMPLATE", "bambu_run/base.html")
|
|
)
|
|
|
|
# Login URL for @login_required redirects
|
|
BAMBU_RUN_LOGIN_URL = property(
|
|
lambda self: get_setting("BAMBU_RUN_LOGIN_URL", "/accounts/login/")
|
|
)
|
|
|
|
# Default brand for auto-created filaments from MQTT
|
|
BAMBU_RUN_AUTO_CREATE_BRAND = property(
|
|
lambda self: get_setting("BAMBU_RUN_AUTO_CREATE_BRAND", "Bambu Lab")
|
|
)
|
|
|
|
|
|
class _Settings:
|
|
"""Lazy settings object that reads from Django settings with defaults."""
|
|
|
|
@property
|
|
def TIMEZONE(self):
|
|
return get_setting("BAMBU_RUN_TIMEZONE", "UTC")
|
|
|
|
@property
|
|
def BASE_TEMPLATE(self):
|
|
return get_setting("BAMBU_RUN_BASE_TEMPLATE", "bambu_run/base.html")
|
|
|
|
@property
|
|
def LOGIN_URL(self):
|
|
return get_setting("BAMBU_RUN_LOGIN_URL", "/accounts/login/")
|
|
|
|
@property
|
|
def AUTO_CREATE_BRAND(self):
|
|
return get_setting("BAMBU_RUN_AUTO_CREATE_BRAND", "Bambu Lab")
|
|
|
|
# MCP Server settings
|
|
@property
|
|
def MCP_API_KEY(self):
|
|
return get_setting("BAMBU_RUN_MCP_API_KEY", None)
|
|
|
|
@property
|
|
def MCP_HOST(self):
|
|
return get_setting("BAMBU_RUN_MCP_HOST", "0.0.0.0")
|
|
|
|
@property
|
|
def MCP_PORT(self):
|
|
return get_setting("BAMBU_RUN_MCP_PORT", 8808)
|
|
|
|
@property
|
|
def MCP_AUTH_BACKEND(self):
|
|
return get_setting("BAMBU_RUN_MCP_AUTH_BACKEND", None)
|
|
|
|
@property
|
|
def MCP_HIDE_SENSITIVE(self):
|
|
return get_setting("BAMBU_RUN_MCP_HIDE_SENSITIVE", False)
|
|
|
|
# Cloud sync settings
|
|
@property
|
|
def CLOUD_SYNC_ENABLED(self):
|
|
return get_setting("BAMBU_RUN_CLOUD_SYNC_ENABLED", True)
|
|
|
|
@property
|
|
def CLOUD_SYNC_DAYS(self):
|
|
return get_setting("BAMBU_RUN_CLOUD_SYNC_DAYS", 30)
|
|
|
|
# Seconds of silence on the MQTT report topic that, once broken by a new
|
|
# message, is treated as "the printer was probably offline" and triggers
|
|
# a pushall re-sync instead of trusting the partial delta to fill in stale
|
|
# fields left over from before the gap.
|
|
@property
|
|
def MQTT_RESYNC_GAP_SECONDS(self):
|
|
return get_setting("BAMBU_RUN_MQTT_RESYNC_GAP_SECONDS", 90)
|
|
|
|
app_settings = _Settings()
|