Skip to content

Commit ce4f324

Browse files
refactor: consolidate display overrides and add field validation asserts
Phase 3 of dynamic typing hardening: - Remove duplicate _FIRE_MODE_DISPLAY and _FLAME_COLOR_DISPLAY dicts from cli.py, replacing with centralized display_name() from models.py - Remove duplicate _MODE_DISPLAY dict from tui/widgets.py - Add module-level assert validating _FEATURE_LABELS field names against FireFeatures dataclass fields - Add module-level assert validating _FLAME_EFFECT_SETTERS field names against FlameEffectParam dataclass fields Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a6a0625 commit ce4f324

2 files changed

Lines changed: 13 additions & 21 deletions

File tree

src/flameconnect/cli.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import argparse
66
import asyncio
7+
import dataclasses
78
import logging
89
import sys
910
import webbrowser
@@ -54,18 +55,6 @@
5455
temp_suffix,
5556
)
5657

57-
# ---------------------------------------------------------------------------
58-
# Enum display-name overrides (only where display_name() is insufficient)
59-
# ---------------------------------------------------------------------------
60-
61-
_FIRE_MODE_DISPLAY: dict[FireMode, str] = {FireMode.MANUAL: "On"}
62-
63-
_FLAME_COLOR_DISPLAY: dict[FlameColor, str] = {
64-
FlameColor.YELLOW_RED: "Yellow/Red",
65-
FlameColor.YELLOW_BLUE: "Yellow/Blue",
66-
FlameColor.BLUE_RED: "Blue/Red",
67-
}
68-
6958
# Mapping from CLI heat-mode string to HeatMode enum value
7059
_HEAT_MODE_LOOKUP: dict[str, HeatMode] = {
7160
kebab_name(m): m for m in (HeatMode.NORMAL, HeatMode.BOOST, HeatMode.ECO)
@@ -129,7 +118,7 @@ def _display_mode(
129118
display_temp = convert_temp(param.target_temperature, unit)
130119
print("\n [321] Mode")
131120
print(f" {'─' * 40}")
132-
mode = _FIRE_MODE_DISPLAY.get(param.mode, display_name(param.mode))
121+
mode = display_name(param.mode)
133122
print(f" Mode: {mode}")
134123
print(f" Target Temp: {display_temp}\u00b0{unit_suffix}")
135124

@@ -145,7 +134,7 @@ def _display_flame_effect(param: FlameEffectParam) -> None:
145134
pulsating = display_name(param.pulsating_effect)
146135
print(f" Brightness: {brightness}")
147136
print(f" Pulsating: {pulsating}")
148-
color = _FLAME_COLOR_DISPLAY.get(param.flame_color, display_name(param.flame_color))
137+
color = display_name(param.flame_color)
149138
print(f" Flame Color: {color}")
150139
theme = display_name(param.media_theme)
151140
rgbw = _format_rgbw(param.media_color)
@@ -286,6 +275,10 @@ def _display_log_effect(param: LogEffectParam) -> None:
286275
("rgb_log_effect", "RGB Log Effect"),
287276
]
288277

278+
assert {fn for fn, _ in _FEATURE_LABELS} == {
279+
f.name for f in dataclasses.fields(FireFeatures)
280+
}, "_FEATURE_LABELS field names do not match FireFeatures fields"
281+
289282

290283
def _display_features(features: FireFeatures) -> None:
291284
"""Display supported feature flags."""
@@ -408,6 +401,11 @@ async def cmd_status(client: FlameConnectClient, fire_id: str) -> None:
408401
),
409402
}
410403

404+
assert all(
405+
setter.field in {f.name for f in dataclasses.fields(FlameEffectParam)}
406+
for setter in _FLAME_EFFECT_SETTERS.values()
407+
), "_FLAME_EFFECT_SETTERS contains invalid FlameEffectParam field names"
408+
411409

412410
async def cmd_on(client: FlameConnectClient, fire_id: str) -> None:
413411
"""Turn on a fireplace."""

src/flameconnect/tui/widgets.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ def _format_rgbw(color: RGBWColor) -> str:
122122
return f"R:{color.red} G:{color.green} B:{color.blue} W:{color.white}"
123123

124124

125-
_MODE_DISPLAY: dict[FireMode, str] = {
126-
FireMode.STANDBY: "Standby",
127-
FireMode.MANUAL: "On",
128-
}
129-
130-
131125
def _format_mode(
132126
param: ModeParam,
133127
temp_unit: TempUnitParam | None = None,
@@ -136,7 +130,7 @@ def _format_mode(
136130
137131
Returns a list of FormattedParam tuples.
138132
"""
139-
mode_label = _MODE_DISPLAY.get(param.mode, display_name(param.mode))
133+
mode_label = display_name(param.mode)
140134
suffix = temp_suffix(temp_unit)
141135
unit = temp_unit.unit if temp_unit else TempUnit.CELSIUS
142136
display_temp = convert_temp(param.target_temperature, unit)

0 commit comments

Comments
 (0)