Skip to content

Commit

Permalink
Minor bug fixes to the birth message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindkinsey committed Dec 10, 2024
1 parent c1e42af commit 2208e49
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = avionmqtt
version = 1.3.4
version = 1.3.5
author = Sean Kinsey
author_email = [email protected]
description = A python library to bridge between Avi-on based lights and Home Assistant using MQTT
Expand Down
16 changes: 11 additions & 5 deletions src/avionmqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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}")
Expand All @@ -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():
Expand Down

0 comments on commit 2208e49

Please sign in to comment.