Compare commits
2 Commits
1affe0fde2
...
aa23ddcffa
Author | SHA1 | Date | |
---|---|---|---|
aa23ddcffa | |||
a0f103570d |
@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
import typer
|
import typer
|
||||||
@ -28,7 +29,7 @@ COLOR_MAP = {
|
|||||||
"warm": (0.5056, 0.4152),
|
"warm": (0.5056, 0.4152),
|
||||||
"warmest": (0.5267, 0.4133),
|
"warmest": (0.5267, 0.4133),
|
||||||
}
|
}
|
||||||
MQTT_BROKER = "mqtt://ha1:1183"
|
MQTT_BROKER = "ha1"
|
||||||
|
|
||||||
|
|
||||||
class LightID(str, Enum):
|
class LightID(str, Enum):
|
||||||
@ -38,6 +39,12 @@ class LightID(str, Enum):
|
|||||||
all = "all"
|
all = "all"
|
||||||
infuse = "infuse"
|
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):
|
def complete_color(incomplete: str):
|
||||||
completion = []
|
completion = []
|
||||||
@ -130,7 +137,7 @@ def set_color(
|
|||||||
xy = rgb_to_xy(float(c[0]), float(c[1]), float(c[2]))
|
xy = rgb_to_xy(float(c[0]), float(c[1]), float(c[2]))
|
||||||
raw_payload = {"x": xy[0], "y": xy[1]}
|
raw_payload = {"x": xy[0], "y": xy[1]}
|
||||||
payload = json.dumps(raw_payload)
|
payload = json.dumps(raw_payload)
|
||||||
pub.single(topic, payload, hostname="ha1")
|
pub.single(topic, payload, hostname=get_mqtt_broker())
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
@ -147,7 +154,7 @@ def set_state(
|
|||||||
str_id = NAME_TO_ID[id]
|
str_id = NAME_TO_ID[id]
|
||||||
topic = f"zigbee2mqtt/{str_id}/set"
|
topic = f"zigbee2mqtt/{str_id}/set"
|
||||||
payload = json.dumps({"state": state.value})
|
payload = json.dumps({"state": state.value})
|
||||||
pub.single(topic, payload, hostname="ha1")
|
pub.single(topic, payload, hostname=get_mqtt_broker())
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
@ -164,7 +171,7 @@ def set_brightness(
|
|||||||
str_id = NAME_TO_ID[id]
|
str_id = NAME_TO_ID[id]
|
||||||
topic = f"zigbee2mqtt/{str_id}/set"
|
topic = f"zigbee2mqtt/{str_id}/set"
|
||||||
payload = json.dumps({"brightness": brightness})
|
payload = json.dumps({"brightness": brightness})
|
||||||
pub.single(topic, payload, hostname="ha1")
|
pub.single(topic, payload, hostname=get_mqtt_broker())
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
6
poetry.lock
generated
6
poetry.lock
generated
@ -59,13 +59,13 @@ standard = ["rich (>=10.11.0)", "shellingham (>=1.3.0)"]
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typing-extensions"
|
name = "typing-extensions"
|
||||||
version = "4.12.0"
|
version = "4.12.2"
|
||||||
description = "Backported and Experimental Type Hints for Python 3.8+"
|
description = "Backported and Experimental Type Hints for Python 3.8+"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.8"
|
python-versions = ">=3.8"
|
||||||
files = [
|
files = [
|
||||||
{file = "typing_extensions-4.12.0-py3-none-any.whl", hash = "sha256:b349c66bea9016ac22978d800cfff206d5f9816951f12a7d0ec5578b0a819594"},
|
{file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"},
|
||||||
{file = "typing_extensions-4.12.0.tar.gz", hash = "sha256:8cbcdc8606ebcb0d95453ad7dc5065e6237b6aa230a31e81d0f440c30fed5fd8"},
|
{file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
|
Loading…
Reference in New Issue
Block a user