diff --git a/flake.nix b/flake.nix index 551bf16..570fb18 100644 --- a/flake.nix +++ b/flake.nix @@ -86,6 +86,7 @@ dontConfigure = true; dontInstall = true; buildPhase = '' + mypy --version mkdir $out mypy --strict huecli --junit-xml $out/junit.xml ''; diff --git a/huecli/__main__.py b/huecli/__main__.py index 55e4996..8ed1256 100644 --- a/huecli/__main__.py +++ b/huecli/__main__.py @@ -25,7 +25,7 @@ NAME_TO_ID = { "office": "0x001788010e371aa4", "all": "all_lights", "infuse": "infuse_group", - "living_room": "living_room" + "living_room": "living_room", } COLOR_MAP = { "red": (0.6942, 0.2963), @@ -50,14 +50,14 @@ class LightID(str, Enum): livingroom = "living_room" -def get_mqtt_broker(): +def get_mqtt_broker() -> str: if "HUECLI_BROKER" in os.environ: return os.environ["HUECLI_BROKER"] else: return MQTT_BROKER -def complete_color(incomplete: str): +def complete_color(incomplete: str) -> list[str]: completion = [] for color in COLOR_MAP: if color.startswith(incomplete): @@ -65,7 +65,7 @@ def complete_color(incomplete: str): return completion -def complete_id(incomplete: str): +def complete_id(incomplete: str) -> list[str]: completion = [] for id in NAME_TO_ID: if id.startswith(incomplete): @@ -73,7 +73,7 @@ def complete_id(incomplete: str): return completion -def complete_state(incomplete: str): +def complete_state(incomplete: str) -> list[str]: states = ["on", "off"] completion = [] for id in states: @@ -82,7 +82,7 @@ def complete_state(incomplete: str): return completion -def rgb_to_xy(red, green, blue) -> XYColor: +def rgb_to_xy(red: float, green: float, blue: float) -> XYColor: """conversion of RGB colors to CIE1931 XY colors Formulas implemented from: https://gist.github.com/popcorn245/30afa0f98eea1c2fd34d @@ -132,7 +132,7 @@ def set_color( color: Annotated[ str, typer.Argument(help="Color to set", autocompletion=complete_color) ], -): +) -> None: """ Set the color of ID to COLOR where COLOR is either a known color value, or a comma separated RGB value, like "0.1,0.2,0.3". @@ -158,7 +158,7 @@ def set_state( LightState, typer.Argument(help="State of light.", autocompletion=complete_state), ], -): +) -> None: """ Set the state of ID to STATE """ @@ -175,7 +175,7 @@ def set_brightness( LightID, typer.Argument(help="ID of light.", autocompletion=complete_id) ], brightness: int, -): +) -> None: """ Set brigthness of ID to BRIGHTNESS """ @@ -186,6 +186,7 @@ def set_brightness( payload = json.dumps({"brightness": brightness}) pub.single(topic, payload, hostname=get_mqtt_broker()) + @app.command() @app.command("get", hidden=True) def get_state( @@ -193,9 +194,10 @@ def get_state( LightID, typer.Argument(help="ID of light.", autocompletion=complete_id) ], as_json: Annotated[ - bool, typer.Option("--json", help="Print state as json."), - ] = False - ): + bool, + typer.Option("--json", help="Print state as json."), + ] = False, +) -> None: """ Get the state of ID """ @@ -204,15 +206,16 @@ def get_state( resp_topic = f"zigbee2mqtt/{str_id}" payload = json.dumps({"state": ""}) pub.single(topic, payload, hostname=get_mqtt_broker()) - resp = sub.simple(resp_topic, hostname=get_mqtt_broker()) + resp = sub.simple(resp_topic, hostname=get_mqtt_broker()) # type: ignore[no-untyped-call] data = json.loads(resp.payload.decode("utf-8")) if as_json: print(json.dumps(data)) else: print(f"{data['state']}") + @app.command() -def version(): +def version() -> None: """ Print huecli version """ @@ -244,7 +247,7 @@ def _parse_rgb_color(r: float, g: float, b: float) -> XYColor: raise ValueError("RGB values must be between 0 and 255 or 0.0 and 1.0") -def main(): +def main() -> None: app()