Skip to content

Commit 21e11cf

Browse files
committed
feat: add heap sensors
1 parent 7bf108d commit 21e11cf

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

custom_components/meshtastic/sensor.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
SIGNAL_STRENGTH_DECIBELS,
2929
UnitOfElectricCurrent,
3030
UnitOfElectricPotential,
31+
UnitOfInformation,
3132
UnitOfLength,
3233
UnitOfMass,
3334
UnitOfPressure,
@@ -477,6 +478,46 @@ def _build_local_stats_sensors(
477478
)
478479
for node_id, node_info in nodes_with_local_stats.items()
479480
]
481+
482+
entities += [
483+
MeshtasticSensor(
484+
coordinator=coordinator,
485+
entity_description=MeshtasticSensorEntityDescription(
486+
key="stats_heap_total_bytes",
487+
name="Heap Total",
488+
icon="mdi:memory",
489+
native_unit_of_measurement=UnitOfInformation.BYTES,
490+
device_class=SensorDeviceClass.DATA_SIZE,
491+
state_class=SensorStateClass.MEASUREMENT,
492+
value_fn=lambda device: device.coordinator.data[device.node_id]
493+
.get("localStats", {})
494+
.get("heapTotalBytes", None),
495+
),
496+
gateway=gateway,
497+
node_id=node_id,
498+
)
499+
for node_id, node_info in nodes_with_local_stats.items()
500+
]
501+
502+
entities += [
503+
MeshtasticSensor(
504+
coordinator=coordinator,
505+
entity_description=MeshtasticSensorEntityDescription(
506+
key="stats_heap_free_bytes",
507+
name="Heap Free",
508+
icon="mdi:memory",
509+
native_unit_of_measurement=UnitOfInformation.BYTES,
510+
device_class=SensorDeviceClass.DATA_SIZE,
511+
state_class=SensorStateClass.MEASUREMENT,
512+
value_fn=lambda device: device.coordinator.data[device.node_id]
513+
.get("localStats", {})
514+
.get("heapFreeBytes", None),
515+
),
516+
gateway=gateway,
517+
node_id=node_id,
518+
)
519+
for node_id, node_info in nodes_with_local_stats.items()
520+
]
480521
except: # noqa: E722
481522
LOGGER.warning("Failed to create local stats entities", exc_info=True)
482523

0 commit comments

Comments
 (0)