Skip to content

Commit

Permalink
Merge pull request #685 from ianmcorvidae/more-telemetry
Browse files Browse the repository at this point in the history
Add other telemetry variants to automatic handling/adding to node information
  • Loading branch information
ianmcorvidae authored Oct 12, 2024
2 parents 6b9db7a + 33fecbd commit 6606851
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions meshtastic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6606851

Please sign in to comment.