diff --git a/chargeamps/chargeamps2mqtt.py b/chargeamps/chargeamps2mqtt.py index de8e917..fea0b31 100644 --- a/chargeamps/chargeamps2mqtt.py +++ b/chargeamps/chargeamps2mqtt.py @@ -10,9 +10,9 @@ mqtt_reconnect_interval = 30 mqtt_broker = "127.0.0.1" + +mqtt_base_topic = "chargeamps" mqtt_commands_topic = "chargeamps/commands" -mqtt_results_topic = "chargeamps/results" -mqtt_status_topic = "chargeamps/status" mqtt_commands_queue = Queue(0) mqtt_results_queue = Queue(0) @@ -30,13 +30,32 @@ async def mqtt_results( logger.debug("Waiting for results") result = await mqtt_results_queue.get() logger.debug("Got result: %s", result) - await mqtt_client.publish(topic=mqtt_results_topic, payload=result.encode()) + + await mqtt_client.publish( + topic=f"{mqtt_base_topic}/results", payload=result.encode() + ) + chargeamps_client.process_message(result) + await mqtt_client.publish( - topic=mqtt_status_topic, - payload=chargeamps_client.state.model_dump_json().encode(), + topic=f"{mqtt_base_topic}/status", + payload=chargeamps_client.state.model_dump_json( + exclude={"connector_settings", "connector_status"} + ).encode(), ) + for n, settings in enumerate(chargeamps_client.state.connector_settings): + await mqtt_client.publish( + topic=f"{mqtt_base_topic}/connector/{n}/settings", + payload=settings.model_dump_json().encode(), + ) + + for n, status in enumerate(chargeamps_client.state.connector_status): + await mqtt_client.publish( + topic=f"{mqtt_base_topic}/connector/{n}/status", + payload=status.model_dump_json().encode(), + ) + async def mqtt_commands( mqtt_client: aiomqtt.Client, chargeamps_client: ChargeAmpsLocalClient