Skip to content

Commit

Permalink
Only publish messages with expected protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
mdegat01 committed Dec 1, 2021
1 parent e8ead62 commit c2cb54a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions amr2mqtt/rootfs/amr2mqtt/amr2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c2cb54a

Please sign in to comment.