mirror of
https://github.com/randybb/esphome-configs.git
synced 2026-01-02 19:47:29 +01:00
have fun
This commit is contained in:
12
custom_components/heapmon/README.md
Normal file
12
custom_components/heapmon/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# heap space monitor
|
||||
|
||||
A sensor to show the available heap space.
|
||||
|
||||
Example:
|
||||
```yaml
|
||||
sensor:
|
||||
- platform: heapmon
|
||||
id: heapspace
|
||||
name: "Free Space"
|
||||
```
|
||||
|
||||
0
custom_components/heapmon/__init__.py
Normal file
0
custom_components/heapmon/__init__.py
Normal file
17
custom_components/heapmon/heapmon.cpp
Normal file
17
custom_components/heapmon/heapmon.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "heapmon.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace debug {
|
||||
|
||||
static const char *TAG = "heapmon";
|
||||
|
||||
void HeapMonitor::update() {
|
||||
uint32_t free_heap = ESP.getFreeHeap();
|
||||
ESP_LOGD(TAG, "Free Heap Size: %u bytes", free_heap);
|
||||
this->publish_state(free_heap);
|
||||
}
|
||||
|
||||
} // namespace debug
|
||||
} // namespace esphome
|
||||
|
||||
17
custom_components/heapmon/heapmon.h
Normal file
17
custom_components/heapmon/heapmon.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace debug {
|
||||
|
||||
class HeapMonitor : public sensor::Sensor, public PollingComponent {
|
||||
public:
|
||||
void update() override;
|
||||
float get_setup_priority() const override { return setup_priority::LATE; };
|
||||
};
|
||||
|
||||
} // namespace debug
|
||||
} // namespace esphome
|
||||
|
||||
18
custom_components/heapmon/sensor.py
Normal file
18
custom_components/heapmon/sensor.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import esphome.config_validation as cv
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import sensor
|
||||
from esphome.const import CONF_ID, ICON_GAUGE
|
||||
|
||||
UNIT_BYTE = "B"
|
||||
|
||||
debug_ns = cg.esphome_ns.namespace('debug')
|
||||
HeapMonitor = debug_ns.class_('HeapMonitor', cg.PollingComponent)
|
||||
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_BYTE, ICON_GAUGE, 0).extend({
|
||||
cv.GenerateID(): cv.declare_id(HeapMonitor),
|
||||
}).extend(cv.polling_component_schema('60s'))
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield sensor.register_sensor(var, config)
|
||||
|
||||
Reference in New Issue
Block a user