From c2cb54a936ff8e3e50099988e674477e67f8d26c Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Tue, 30 Nov 2021 23:36:51 -0500 Subject: [PATCH] Only publish messages with expected protocol --- amr2mqtt/rootfs/amr2mqtt/amr2mqtt.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/amr2mqtt/rootfs/amr2mqtt/amr2mqtt.py b/amr2mqtt/rootfs/amr2mqtt/amr2mqtt.py index b43d5c6..7ba8ed0 100644 --- a/amr2mqtt/rootfs/amr2mqtt/amr2mqtt.py +++ b/amr2mqtt/rootfs/amr2mqtt/amr2mqtt.py @@ -375,10 +375,17 @@ def main_loop(): msg_type, json_message, ) - mqttc.publish( - topic=f"{settings.MQTT_BASE_TOPIC}/{meter_id}", - payload=json_message, - ) + + # Don't publish messages for watched meters that are the wrong protocol + # Seemed either some meters were dual protocool or two had duplicate IDs + if ( + meter_id not in settings.METERS + or msg_type == settings.METERS[meter_id].protocol + ): + mqttc.publish( + topic=f"{settings.MQTT_BASE_TOPIC}/{meter_id}", + payload=json_message, + ) except Exception as ex: # pylint: disable=broad-except logging.debug("Exception squashed! %s: %s", ex.__class__.__name__, ex)