Fix mypy checks
This commit is contained in:
parent
15d2928771
commit
b85f50ea4c
@ -86,6 +86,7 @@
|
|||||||
dontConfigure = true;
|
dontConfigure = true;
|
||||||
dontInstall = true;
|
dontInstall = true;
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
|
mypy --version
|
||||||
mkdir $out
|
mkdir $out
|
||||||
mypy --strict huecli --junit-xml $out/junit.xml
|
mypy --strict huecli --junit-xml $out/junit.xml
|
||||||
'';
|
'';
|
||||||
|
@ -25,7 +25,7 @@ NAME_TO_ID = {
|
|||||||
"office": "0x001788010e371aa4",
|
"office": "0x001788010e371aa4",
|
||||||
"all": "all_lights",
|
"all": "all_lights",
|
||||||
"infuse": "infuse_group",
|
"infuse": "infuse_group",
|
||||||
"living_room": "living_room"
|
"living_room": "living_room",
|
||||||
}
|
}
|
||||||
COLOR_MAP = {
|
COLOR_MAP = {
|
||||||
"red": (0.6942, 0.2963),
|
"red": (0.6942, 0.2963),
|
||||||
@ -50,14 +50,14 @@ class LightID(str, Enum):
|
|||||||
livingroom = "living_room"
|
livingroom = "living_room"
|
||||||
|
|
||||||
|
|
||||||
def get_mqtt_broker():
|
def get_mqtt_broker() -> str:
|
||||||
if "HUECLI_BROKER" in os.environ:
|
if "HUECLI_BROKER" in os.environ:
|
||||||
return os.environ["HUECLI_BROKER"]
|
return os.environ["HUECLI_BROKER"]
|
||||||
else:
|
else:
|
||||||
return MQTT_BROKER
|
return MQTT_BROKER
|
||||||
|
|
||||||
|
|
||||||
def complete_color(incomplete: str):
|
def complete_color(incomplete: str) -> list[str]:
|
||||||
completion = []
|
completion = []
|
||||||
for color in COLOR_MAP:
|
for color in COLOR_MAP:
|
||||||
if color.startswith(incomplete):
|
if color.startswith(incomplete):
|
||||||
@ -65,7 +65,7 @@ def complete_color(incomplete: str):
|
|||||||
return completion
|
return completion
|
||||||
|
|
||||||
|
|
||||||
def complete_id(incomplete: str):
|
def complete_id(incomplete: str) -> list[str]:
|
||||||
completion = []
|
completion = []
|
||||||
for id in NAME_TO_ID:
|
for id in NAME_TO_ID:
|
||||||
if id.startswith(incomplete):
|
if id.startswith(incomplete):
|
||||||
@ -73,7 +73,7 @@ def complete_id(incomplete: str):
|
|||||||
return completion
|
return completion
|
||||||
|
|
||||||
|
|
||||||
def complete_state(incomplete: str):
|
def complete_state(incomplete: str) -> list[str]:
|
||||||
states = ["on", "off"]
|
states = ["on", "off"]
|
||||||
completion = []
|
completion = []
|
||||||
for id in states:
|
for id in states:
|
||||||
@ -82,7 +82,7 @@ def complete_state(incomplete: str):
|
|||||||
return completion
|
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
|
"""conversion of RGB colors to CIE1931 XY colors
|
||||||
Formulas implemented from: https://gist.github.com/popcorn245/30afa0f98eea1c2fd34d
|
Formulas implemented from: https://gist.github.com/popcorn245/30afa0f98eea1c2fd34d
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ def set_color(
|
|||||||
color: Annotated[
|
color: Annotated[
|
||||||
str, typer.Argument(help="Color to set", autocompletion=complete_color)
|
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,
|
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".
|
or a comma separated RGB value, like "0.1,0.2,0.3".
|
||||||
@ -158,7 +158,7 @@ def set_state(
|
|||||||
LightState,
|
LightState,
|
||||||
typer.Argument(help="State of light.", autocompletion=complete_state),
|
typer.Argument(help="State of light.", autocompletion=complete_state),
|
||||||
],
|
],
|
||||||
):
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Set the state of ID to STATE
|
Set the state of ID to STATE
|
||||||
"""
|
"""
|
||||||
@ -175,7 +175,7 @@ def set_brightness(
|
|||||||
LightID, typer.Argument(help="ID of light.", autocompletion=complete_id)
|
LightID, typer.Argument(help="ID of light.", autocompletion=complete_id)
|
||||||
],
|
],
|
||||||
brightness: int,
|
brightness: int,
|
||||||
):
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Set brigthness of ID to BRIGHTNESS
|
Set brigthness of ID to BRIGHTNESS
|
||||||
"""
|
"""
|
||||||
@ -186,6 +186,7 @@ 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()
|
||||||
@app.command("get", hidden=True)
|
@app.command("get", hidden=True)
|
||||||
def get_state(
|
def get_state(
|
||||||
@ -193,9 +194,10 @@ def get_state(
|
|||||||
LightID, typer.Argument(help="ID of light.", autocompletion=complete_id)
|
LightID, typer.Argument(help="ID of light.", autocompletion=complete_id)
|
||||||
],
|
],
|
||||||
as_json: Annotated[
|
as_json: Annotated[
|
||||||
bool, typer.Option("--json", help="Print state as json."),
|
bool,
|
||||||
] = False
|
typer.Option("--json", help="Print state as json."),
|
||||||
):
|
] = False,
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Get the state of ID
|
Get the state of ID
|
||||||
"""
|
"""
|
||||||
@ -204,15 +206,16 @@ def get_state(
|
|||||||
resp_topic = f"zigbee2mqtt/{str_id}"
|
resp_topic = f"zigbee2mqtt/{str_id}"
|
||||||
payload = json.dumps({"state": ""})
|
payload = json.dumps({"state": ""})
|
||||||
pub.single(topic, payload, hostname=get_mqtt_broker())
|
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"))
|
data = json.loads(resp.payload.decode("utf-8"))
|
||||||
if as_json:
|
if as_json:
|
||||||
print(json.dumps(data))
|
print(json.dumps(data))
|
||||||
else:
|
else:
|
||||||
print(f"{data['state']}")
|
print(f"{data['state']}")
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def version():
|
def version() -> None:
|
||||||
"""
|
"""
|
||||||
Print huecli version
|
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")
|
raise ValueError("RGB values must be between 0 and 255 or 0.0 and 1.0")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main() -> None:
|
||||||
app()
|
app()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user