Add get-state command
This commit is contained in:
parent
fdf7e5c642
commit
455b3c5f3c
@ -6,6 +6,7 @@ from typing_extensions import Annotated
|
||||
import typer
|
||||
import json
|
||||
import paho.mqtt.publish as pub
|
||||
import paho.mqtt.subscribe as sub
|
||||
|
||||
|
||||
class LightState(str, Enum):
|
||||
@ -185,6 +186,30 @@ def set_brightness(
|
||||
payload = json.dumps({"brightness": brightness})
|
||||
pub.single(topic, payload, hostname=get_mqtt_broker())
|
||||
|
||||
@app.command()
|
||||
@app.command("s", hidden=True)
|
||||
def get_state(
|
||||
id: Annotated[
|
||||
LightID, typer.Argument(help="ID of light.", autocompletion=complete_id)
|
||||
],
|
||||
as_json: Annotated[
|
||||
bool, typer.Option("--json", help="Print state as json."),
|
||||
] = False
|
||||
):
|
||||
"""
|
||||
Get the state of ID
|
||||
"""
|
||||
str_id = NAME_TO_ID[id]
|
||||
topic = f"zigbee2mqtt/{str_id}/get"
|
||||
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())
|
||||
data = json.loads(resp.payload.decode("utf-8"))
|
||||
if as_json:
|
||||
print(json.dumps(data))
|
||||
else:
|
||||
print(f"{data['state']}")
|
||||
|
||||
@app.command()
|
||||
def version():
|
||||
|
@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "huecli"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
description = "Set Philips Hue lights using MQTT"
|
||||
authors = ["Torjus Håkestad <torjus@uio.no>"]
|
||||
license = "MIT"
|
||||
|
Loading…
Reference in New Issue
Block a user