From 33fecbd74d59cdb5d814460b7b9a14a7fb1fa1f5 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Sat, 12 Oct 2024 11:56:55 -0700 Subject: [PATCH] Add other telemetry variants to automatic handling/adding to node information --- meshtastic/__init__.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/meshtastic/__init__.py b/meshtastic/__init__.py index 03d2072..b632d34 100644 --- a/meshtastic/__init__.py +++ b/meshtastic/__init__.py @@ -194,13 +194,31 @@ def _onNodeInfoReceive(iface, asDict): def _onTelemetryReceive(iface, asDict): """Automatically update device metrics on received packets""" logging.debug(f"in _onTelemetryReceive() asDict:{asDict}") - deviceMetrics = asDict.get("decoded", {}).get("telemetry", {}).get("deviceMetrics") - if "from" in asDict and deviceMetrics is not None: - node = iface._getOrCreateByNum(asDict["from"]) - newMetrics = node.get("deviceMetrics", {}) - newMetrics.update(deviceMetrics) - logging.debug(f"updating metrics for {asDict['from']} to {newMetrics}") - node["deviceMetrics"] = newMetrics + if "from" not in asDict: + return + + toUpdate = None + + telemetry = asDict.get("decoded", {}).get("telemetry", {}) + node = iface._getOrCreateByNum(asDict["from"]) + if "deviceMetrics" in telemetry: + toUpdate = "deviceMetrics" + elif "environmentMetrics" in telemetry: + toUpdate = "environmentMetrics" + elif "airQualityMetrics" in telemetry: + toUpdate = "airQualityMetrics" + elif "powerMetrics" in telemetry: + toUpdate = "powerMetrics" + elif "localStats" in telemetry: + toUpdate = "localStats" + else: + return + + updateObj = telemetry.get(toUpdate) + newMetrics = node.get(toUpdate, {}) + newMetrics.update(updateObj) + logging.debug(f"updating {toUpdate} metrics for {asDict['from']} to {newMetrics}") + node[toUpdate] = newMetrics def _receiveInfoUpdate(iface, asDict): if "from" in asDict: