Compare commits

...

2 Commits

Author SHA1 Message Date
aa23ddcffa Update deps 2024-06-10 14:14:07 +02:00
a0f103570d Allow reading mqtt broker from env 2024-06-10 14:12:39 +02:00
2 changed files with 14 additions and 7 deletions

View File

@ -1,3 +1,4 @@
import os
from enum import Enum
from typing_extensions import Annotated
import typer
@ -28,7 +29,7 @@ COLOR_MAP = {
"warm": (0.5056, 0.4152),
"warmest": (0.5267, 0.4133),
}
MQTT_BROKER = "mqtt://ha1:1183"
MQTT_BROKER = "ha1"
class LightID(str, Enum):
@ -38,6 +39,12 @@ class LightID(str, Enum):
all = "all"
infuse = "infuse"
def get_mqtt_broker():
if "HUECLI_BROKER" in os.environ:
return os.environ["HUECLI_BROKER"]
else:
return MQTT_BROKER
def complete_color(incomplete: str):
completion = []
@ -130,7 +137,7 @@ def set_color(
xy = rgb_to_xy(float(c[0]), float(c[1]), float(c[2]))
raw_payload = {"x": xy[0], "y": xy[1]}
payload = json.dumps(raw_payload)
pub.single(topic, payload, hostname="ha1")
pub.single(topic, payload, hostname=get_mqtt_broker())
@app.command()
@ -147,7 +154,7 @@ def set_state(
str_id = NAME_TO_ID[id]
topic = f"zigbee2mqtt/{str_id}/set"
payload = json.dumps({"state": state.value})
pub.single(topic, payload, hostname="ha1")
pub.single(topic, payload, hostname=get_mqtt_broker())
@app.command()
@ -164,7 +171,7 @@ def set_brightness(
str_id = NAME_TO_ID[id]
topic = f"zigbee2mqtt/{str_id}/set"
payload = json.dumps({"brightness": brightness})
pub.single(topic, payload, hostname="ha1")
pub.single(topic, payload, hostname=get_mqtt_broker())
def main():

6
poetry.lock generated
View File

@ -59,13 +59,13 @@ standard = ["rich (>=10.11.0)", "shellingham (>=1.3.0)"]
[[package]]
name = "typing-extensions"
version = "4.12.0"
version = "4.12.2"
description = "Backported and Experimental Type Hints for Python 3.8+"
optional = false
python-versions = ">=3.8"
files = [
{file = "typing_extensions-4.12.0-py3-none-any.whl", hash = "sha256:b349c66bea9016ac22978d800cfff206d5f9816951f12a7d0ec5578b0a819594"},
{file = "typing_extensions-4.12.0.tar.gz", hash = "sha256:8cbcdc8606ebcb0d95453ad7dc5065e6237b6aa230a31e81d0f440c30fed5fd8"},
{file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"},
{file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"},
]
[metadata]