Color base add support for transparent color (#5)

* added db model is transparent and fixed PETG translucent showing black

* js and filament form for transparent color

* bumped version to v0.1.2
This commit is contained in:
RunLit
2026-03-27 23:30:27 +11:00
committed by GitHub
parent 7e39d3e38d
commit 5c56711c57
16 changed files with 286 additions and 108 deletions

View File

@@ -316,7 +316,7 @@ class Command(BaseCommand):
def _auto_create_filament(self, tray_data):
from bambu_run.models import Filament, FilamentType
from bambu_run.utils import strip_color_padding, match_filament_color
from bambu_run.utils import strip_color_padding, match_filament_color, is_mqtt_color_transparent
tray_uuid = tray_data.get('tray_uuid')
tag_uid = tray_data.get('tag_uid')
@@ -329,6 +329,7 @@ class Command(BaseCommand):
default_brand = app_settings.AUTO_CREATE_BRAND
transparent = is_mqtt_color_transparent(mqtt_color)
color_code = strip_color_padding(mqtt_color)
color_hex = f"#{color_code}" if color_code else None
@@ -341,6 +342,7 @@ class Command(BaseCommand):
if filament_color:
color_name = filament_color.color_name
transparent = transparent or filament_color.is_transparent
if self.verbose:
logger.info(f"Matched color from database: {color_name} (#{color_code})")
else:
@@ -368,6 +370,7 @@ class Command(BaseCommand):
brand=default_brand,
color=color_name,
color_hex=color_hex,
is_transparent=transparent,
diameter=diameter,
initial_weight_grams=initial_weight,
remaining_percent=remain_percent,

View File

@@ -371,6 +371,11 @@ class Command(BaseCommand):
return "created"
return "no_type"
# ── Transparent detection ────────────────────────────────────────────
# "Translucent" (no colour qualifier) + #000000 = clear/transparent filament.
# Bambu Lab AMS reports these as 00000000 (alpha=00).
is_transparent = color_name.strip().lower() == "translucent" and hex_code == "000000"
# ── Duplicate check ──────────────────────────────────────────────────
# All five fields must match to be considered a duplicate:
# color_code (exact), color_name (case-insensitive), brand,
@@ -388,9 +393,10 @@ class Command(BaseCommand):
return "duplicate"
if dry_run:
transparent_note = " [transparent]" if is_transparent else ""
self.stdout.write(
f" [dry-run] Would create: {color_name!r} #{hex_code} "
f"({filament_type} / {filament_sub_type})"
f"({filament_type} / {filament_sub_type}){transparent_note}"
)
return "created"
@@ -404,6 +410,7 @@ class Command(BaseCommand):
filament_type=filament_type,
filament_sub_type=filament_sub_type,
brand=BRAND,
is_transparent=is_transparent,
)
self.stdout.write(
f" + {color_name!r} #{hex_code} ({filament_type} / {filament_sub_type})"