mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-09-30 19:21:33 +02:00
Features:
- Add wiki_url field to MaintenanceType for custom type documentation links
- Add printer_model to MaintenanceStatus for model-specific URL mapping
- Display external link icon next to maintenance item names
- Map system maintenance types to Bambu Lab wiki pages by printer model:
- Lubricate Linear Rails, Clean Nozzle/Hotend, Check Belt Tension
- Clean Carbon Rods (X1/P1 only), Clean Build Plate, Check PTFE Tube
- HEPA/Carbon Filter, Left Nozzle Rail (H2 series)
- Add Documentation Link input to custom type create/edit forms
Bug fix:
- Fix 500 error when assigning maintenance type to printer (lazy loading)
Database:
- Add migration for wiki_url column on maintenance_types table
80 lines
3.5 KiB
Python
80 lines
3.5 KiB
Python
"""Maintenance tracking models."""
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import Boolean, DateTime, Float, ForeignKey, String, Text, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from backend.app.core.database import Base
|
|
|
|
|
|
class MaintenanceType(Base):
|
|
"""Defines a type of maintenance task with default interval."""
|
|
|
|
__tablename__ = "maintenance_types"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String(100))
|
|
description: Mapped[str | None] = mapped_column(Text)
|
|
default_interval_hours: Mapped[float] = mapped_column(Float, default=100.0)
|
|
# Interval type: "hours" (print hours) or "days" (calendar days)
|
|
interval_type: Mapped[str] = mapped_column(String(20), default="hours")
|
|
icon: Mapped[str | None] = mapped_column(String(50)) # Icon name for UI
|
|
wiki_url: Mapped[str | None] = mapped_column(String(500)) # Documentation link
|
|
is_system: Mapped[bool] = mapped_column(Boolean, default=False) # Pre-defined vs custom
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
|
|
# Relationships
|
|
printer_maintenance: Mapped[list["PrinterMaintenance"]] = relationship(
|
|
back_populates="maintenance_type", cascade="all, delete-orphan"
|
|
)
|
|
|
|
|
|
class PrinterMaintenance(Base):
|
|
"""Tracks maintenance status for a specific printer."""
|
|
|
|
__tablename__ = "printer_maintenance"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
printer_id: Mapped[int] = mapped_column(ForeignKey("printers.id", ondelete="CASCADE"))
|
|
maintenance_type_id: Mapped[int] = mapped_column(ForeignKey("maintenance_types.id", ondelete="CASCADE"))
|
|
|
|
# Custom interval for this printer (overrides default if set)
|
|
custom_interval_hours: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
# Custom interval type for this printer (overrides default if set)
|
|
custom_interval_type: Mapped[str | None] = mapped_column(String(20), nullable=True)
|
|
|
|
# Tracking
|
|
enabled: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
last_performed_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
last_performed_hours: Mapped[float] = mapped_column(Float, default=0.0) # Hours at last reset
|
|
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
|
|
|
|
# Relationships
|
|
printer: Mapped["Printer"] = relationship(back_populates="maintenance_items")
|
|
maintenance_type: Mapped["MaintenanceType"] = relationship(back_populates="printer_maintenance")
|
|
history: Mapped[list["MaintenanceHistory"]] = relationship(
|
|
back_populates="printer_maintenance", cascade="all, delete-orphan"
|
|
)
|
|
|
|
|
|
class MaintenanceHistory(Base):
|
|
"""Log of maintenance actions performed."""
|
|
|
|
__tablename__ = "maintenance_history"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
printer_maintenance_id: Mapped[int] = mapped_column(ForeignKey("printer_maintenance.id", ondelete="CASCADE"))
|
|
performed_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
hours_at_maintenance: Mapped[float] = mapped_column(Float, default=0.0)
|
|
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
# Relationships
|
|
printer_maintenance: Mapped["PrinterMaintenance"] = relationship(back_populates="history")
|
|
|
|
|
|
# Import at end to avoid circular imports
|
|
from backend.app.models.printer import Printer # noqa: E402
|