Compare commits
No commits in common. "55a82add9f5a097cacf392743fe9a0883d6d1bb0" and "365b2d685799906d541dcd10c59df4c29e1e9301" have entirely different histories.
55a82add9f
...
365b2d6857
@ -41,7 +41,6 @@
|
|||||||
huecli = mkPoetryApplication {
|
huecli = mkPoetryApplication {
|
||||||
projectDir = ./.;
|
projectDir = ./.;
|
||||||
overrides = p2n-overrides;
|
overrides = p2n-overrides;
|
||||||
python = pkgs.python312;
|
|
||||||
nativeBuildInputs = [ pkgs.installShellFiles ];
|
nativeBuildInputs = [ pkgs.installShellFiles ];
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
installShellCompletion --cmd huecli \
|
installShellCompletion --cmd huecli \
|
||||||
|
@ -12,7 +12,6 @@ class LightState(str, Enum):
|
|||||||
on = "off"
|
on = "off"
|
||||||
off = "on"
|
off = "on"
|
||||||
|
|
||||||
|
|
||||||
class XYColor(NamedTuple):
|
class XYColor(NamedTuple):
|
||||||
x: float
|
x: float
|
||||||
y: float
|
y: float
|
||||||
@ -46,7 +45,6 @@ class LightID(str, Enum):
|
|||||||
all = "all"
|
all = "all"
|
||||||
infuse = "infuse"
|
infuse = "infuse"
|
||||||
|
|
||||||
|
|
||||||
def get_mqtt_broker():
|
def get_mqtt_broker():
|
||||||
if "HUECLI_BROKER" in os.environ:
|
if "HUECLI_BROKER" in os.environ:
|
||||||
return os.environ["HUECLI_BROKER"]
|
return os.environ["HUECLI_BROKER"]
|
||||||
@ -69,7 +67,6 @@ def complete_id(incomplete: str):
|
|||||||
completion.append(id)
|
completion.append(id)
|
||||||
return completion
|
return completion
|
||||||
|
|
||||||
|
|
||||||
def complete_state(incomplete: str):
|
def complete_state(incomplete: str):
|
||||||
states = ["on", "off"]
|
states = ["on", "off"]
|
||||||
completion = []
|
completion = []
|
||||||
@ -136,7 +133,7 @@ def set_color(
|
|||||||
str_id = NAME_TO_ID[id]
|
str_id = NAME_TO_ID[id]
|
||||||
topic = f"zigbee2mqtt/{str_id}/set"
|
topic = f"zigbee2mqtt/{str_id}/set"
|
||||||
xy = parse_color(color)
|
xy = parse_color(color)
|
||||||
payload_raw = {
|
payload_raw= {
|
||||||
"color": {"x": xy[0], "y": xy[1]},
|
"color": {"x": xy[0], "y": xy[1]},
|
||||||
"color_mode": "xy",
|
"color_mode": "xy",
|
||||||
}
|
}
|
||||||
@ -150,10 +147,8 @@ def set_state(
|
|||||||
LightID, typer.Argument(help="ID of light.", autocompletion=complete_id)
|
LightID, typer.Argument(help="ID of light.", autocompletion=complete_id)
|
||||||
],
|
],
|
||||||
state: Annotated[
|
state: Annotated[
|
||||||
LightState,
|
LightState, typer.Argument(help="State of light.", autocompletion=complete_state)
|
||||||
typer.Argument(help="State of light.", autocompletion=complete_state),
|
]):
|
||||||
],
|
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
Set the state of ID to STATE
|
Set the state of ID to STATE
|
||||||
"""
|
"""
|
||||||
@ -168,8 +163,7 @@ def set_brightness(
|
|||||||
id: Annotated[
|
id: Annotated[
|
||||||
LightID, typer.Argument(help="ID of light.", autocompletion=complete_id)
|
LightID, typer.Argument(help="ID of light.", autocompletion=complete_id)
|
||||||
],
|
],
|
||||||
brightness: int,
|
brightness: int):
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
Set brigthness of ID to BRIGHTNESS
|
Set brigthness of ID to BRIGHTNESS
|
||||||
"""
|
"""
|
||||||
@ -180,7 +174,6 @@ def set_brightness(
|
|||||||
payload = json.dumps({"brightness": brightness})
|
payload = json.dumps({"brightness": brightness})
|
||||||
pub.single(topic, payload, hostname=get_mqtt_broker())
|
pub.single(topic, payload, hostname=get_mqtt_broker())
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def version():
|
def version():
|
||||||
"""
|
"""
|
||||||
@ -189,7 +182,6 @@ def version():
|
|||||||
version = importlib.metadata.version("huecli")
|
version = importlib.metadata.version("huecli")
|
||||||
typer.echo(f"huecli {version}")
|
typer.echo(f"huecli {version}")
|
||||||
|
|
||||||
|
|
||||||
def parse_color(color: str) -> XYColor:
|
def parse_color(color: str) -> XYColor:
|
||||||
if color in COLOR_MAP:
|
if color in COLOR_MAP:
|
||||||
return XYColor(COLOR_MAP[color][0], COLOR_MAP[color][1])
|
return XYColor(COLOR_MAP[color][0], COLOR_MAP[color][1])
|
||||||
@ -202,18 +194,16 @@ def parse_color(color: str) -> XYColor:
|
|||||||
case _:
|
case _:
|
||||||
raise ValueError("Invalid color format")
|
raise ValueError("Invalid color format")
|
||||||
|
|
||||||
|
|
||||||
def _parse_rgb_color(r: float, g: float, b: float) -> XYColor:
|
def _parse_rgb_color(r: float, g: float, b: float) -> XYColor:
|
||||||
if any(val > 1 for val in [r, g, b]):
|
if any(val > 1 for val in [r,g,b]):
|
||||||
if any(val > 255 for val in [r, g, b]):
|
if any(val > 255 for val in [r,g,b]):
|
||||||
raise ValueError("RGB values must be between 0 and 255 or 0.0 and 1.0")
|
raise ValueError("RGB values must be between 0 and 255 or 0.0 and 1.0")
|
||||||
vals = [val / 255 for val in [r, g, b]]
|
vals = [val/255 for val in [r,g,b]]
|
||||||
return rgb_to_xy(vals[0], vals[1], vals[2])
|
return rgb_to_xy(vals[0], vals[1], vals[2])
|
||||||
if all(val > 0 and val < 1 for val in [r, g, b]):
|
if all(val > 0 and val < 1 for val in [r,g,b]):
|
||||||
return rgb_to_xy(r, g, b)
|
return rgb_to_xy(r,g,b)
|
||||||
raise ValueError("RGB values must be between 0 and 255 or 0.0 and 1.0")
|
raise ValueError("RGB values must be between 0 and 255 or 0.0 and 1.0")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app()
|
app()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user