diff --git a/CHANGELOG.md b/CHANGELOG.md index ce3627d..5315593 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,8 +17,8 @@ Added several small improvements, leaving the package in a reasonable usable sta - Add include and exclude options for registering devices - Add option to automatically exclude devices part of a group -## 1.3.0 2024-12-09 +## 1.3.1 2024-12-09 - Add service install script -## 1.3.0 2024-12-09 +## 1.3.4 2024-12-09 - Remove use of retained messages and subcribe to Home Assistant's birth message instead diff --git a/setup.cfg b/setup.cfg index 3a91e79..e9a6717 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = avionmqtt -version = 1.3.4 +version = 1.3.5 author = Sean Kinsey author_email = oyvind@kinsey.no description = A python library to bridge between Avi-on based lights and Home Assistant using MQTT diff --git a/src/avionmqtt/__init__.py b/src/avionmqtt/__init__.py index 629e216..e43d8a8 100644 --- a/src/avionmqtt/__init__.py +++ b/src/avionmqtt/__init__.py @@ -145,6 +145,7 @@ async def mqtt_register_category(settings: dict, list: List[dict], mqtt: aiomqtt async def mqtt_register_lights(settings: dict, location: dict, mqtt: aiomqtt.Client): + print("mqtt: Registering devices") await mqtt_register_category(settings["groups"], location["groups"], mqtt) if settings["devices"].get("exclude_in_group"): @@ -232,13 +233,16 @@ async def mesh_send(avid: int, raw_payload: str, mqtt: aiomqtt.Client, mesh: Ble async def mqtt_subscribe(mqtt: aiomqtt.Client, mesh: BleakClient, key: str, settings: dict, location: dict): - await mqtt.subscribe("hmd/light/avid/+/command") await mqtt.subscribe("homeassistant/status") + await mqtt.subscribe("hmd/light/avid/+/command") async for message in mqtt.messages: if message.topic.matches("homeassistant/status"): - if message.payload == "online": + if message.payload.decode() == "online": + print("mqtt: Home Assistant back online") await mqtt_register_lights(settings, location, mqtt) - else: + else: + print("mqtt: Home Assistant offline") + elif message.topic.matches("hmd/light/avid/+/command"): json = message.payload.decode() avid = int(message.topic.value.split("/")[3]) print(f"mqtt: received {json} for {avid}") @@ -256,11 +260,13 @@ async def mqtt_send_state(mqtt: aiomqtt.Client, message: dict): "state": "ON" if brightness != 0 else "OFF", "brightness": brightness, } - await mqtt.publish(state_topic, json.dumps(payload)) elif "color_temp" in message: color_temp = message["color_temp"] payload = {"color_temp": color_temp} - await mqtt.publish(state_topic, json.dumps(payload)) + else: + return + + await mqtt.publish(state_topic, json.dumps(payload), retain=True) async def mac_ordered_by_rssi():