@@ -191,6 +191,16 @@ def _onNodeInfoReceive(iface, asDict):
191191 iface .nodes [p ["id" ]] = n
192192 _receiveInfoUpdate (iface , asDict )
193193
194+ def _onTelemetryReceive (iface , asDict ):
195+ """Automatically update device metrics on received packets"""
196+ logging .debug (f"in _onTelemetryReceive() asDict:{ asDict } " )
197+ deviceMetrics = asDict .get ("decoded" , {}).get ("telemetry" , {}).get ("deviceMetrics" )
198+ if "from" in asDict and deviceMetrics is not None :
199+ node = iface ._getOrCreateByNum (asDict ["from" ])
200+ newMetrics = node .get ("deviceMetrics" , {})
201+ newMetrics .update (deviceMetrics )
202+ logging .debug (f"updating metrics for { asDict ['from' ]} to { newMetrics } " )
203+ node ["deviceMetrics" ] = newMetrics
194204
195205def _receiveInfoUpdate (iface , asDict ):
196206 if "from" in asDict :
@@ -221,7 +231,7 @@ def _receiveInfoUpdate(iface, asDict):
221231 portnums_pb2 .PortNum .ADMIN_APP : KnownProtocol ("admin" , admin_pb2 .AdminMessage ),
222232 portnums_pb2 .PortNum .ROUTING_APP : KnownProtocol ("routing" , mesh_pb2 .Routing ),
223233 portnums_pb2 .PortNum .TELEMETRY_APP : KnownProtocol (
224- "telemetry" , telemetry_pb2 .Telemetry
234+ "telemetry" , telemetry_pb2 .Telemetry , _onTelemetryReceive
225235 ),
226236 portnums_pb2 .PortNum .REMOTE_HARDWARE_APP : KnownProtocol (
227237 "remotehw" , remote_hardware_pb2 .HardwareMessage
0 commit comments