Skip to content

Commit ed32bfd

Browse files
JnyJnyclaude
andcommitted
Fix color parsing and pulse effect implementation
- Add case-insensitive hex prefix handling (0x/0X) in color parsing - Prioritize hex color parsing before named color lookups - Remove broken HTML5 color parsers that had typo - Fix pulse effect to use correct gradient parameters and manager method - Add missing logger import to udev_rules subcommand 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 5487cd8 commit ed32bfd

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

src/busylight/color.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,17 @@ def parse_color_string(value: str, scale: float = 1.0) -> tuple[int, int, int]:
3232
"""
3333
scale = max(0.0, min(scale, 1.0))
3434

35-
if value.startswith("0x"):
35+
if value.startswith("0x") or value.startswith("0X"):
3636
value = f"#{value[2:]}"
3737

38+
if value.startswith("#"):
39+
try:
40+
rgb = webcolors.hex_to_rgb(value)
41+
return scale_color(rgb, scale)
42+
except ValueError as error:
43+
logger.debug(f"No match found for {value} -> {error}")
44+
raise ColorLookupError(f"No color mapping for {value}") from error
45+
3846
for spec in [
3947
webcolors.CSS3,
4048
webcolors.CSS2,
@@ -47,16 +55,6 @@ def parse_color_string(value: str, scale: float = 1.0) -> tuple[int, int, int]:
4755
except ValueError as error:
4856
logger.info(f"name_to_rgb[{spec}] {value} -> {error}")
4957

50-
for parse_color in [
51-
webcolors.html5_parse_legacy_color,
52-
webcolors.html5_parse_simple_color,
53-
]:
54-
try:
55-
rgb = parse_color(value)
56-
return scale_color(rgb, scale)
57-
except ValueError as error:
58-
loggerinfo(f"[parse] {value} -> {error}")
59-
6058
raise ColorLookupError(f"No color mapping for {value}")
6159

6260

src/busylight/subcommands/pulse.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,10 @@ def pulse_lights(
4141

4242
logger.info("Applying pulse effect.")
4343

44-
effect = Effects.for_name("gradient")(
45-
speed.duty_cycle / 4,
46-
scale=ctx.obj.dim,
47-
count=count,
48-
)
44+
effect = Effects.for_name("gradient")(color, speed.duty_cycle / 16, 8, count=count)
4945

5046
try:
51-
ctx.obj.manager.apply(effect, ctx.obj.lights, timeout=ctx.obj.timeout)
47+
ctx.obj.manager.apply_effect(effect, ctx.obj.lights, timeout=ctx.obj.timeout)
5248
except (KeyboardInterrupt, TimeoutError):
5349
ctx.obj.manager.off(ctx.obj.lights)
5450
except NoLightsFoundError:

src/busylight/subcommands/udev_rules.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import typer
44
from busylight_core import Light
5+
from loguru import logger
56

67
udev_rules_cli = typer.Typer(help="Generate udev rules for supported lights.")
78

0 commit comments

Comments
 (0)