From 9093996ec97285c566c88f5d7be2f71f293ba3c4 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 8 Oct 2025 17:14:06 +0200 Subject: [PATCH] use standard fixed length types --- src/esp.h | 2 +- src/ha.h | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/esp.h b/src/esp.h index a438d5c..f7cfbce 100644 --- a/src/esp.h +++ b/src/esp.h @@ -22,7 +22,7 @@ namespace HaESP { ESP.getHeapStats(&hfree, &hmax, &hfrag); char value[128]; - snprintf_P(value, sizeof(value), PSTR("{\"fragmentation\":%d,\"heap\":{\"Heap free\":\"%d B\",\"Heap max free block\":\"%d B\"}}"), hfrag, hfree, hmax); + snprintf_P(value, sizeof(value), PSTR("{\"fragmentation\":%lu,\"heap\":{\"Heap free\":\"%lu B\",\"Heap max free block\":\"%u B\"}}"), hfrag, hfree, hmax); GenericSensor::mapSensors["heap_fragmentation"]->updateState(value); GenericSensor::mapSensors["heap_free"]->updateState(to_string(hfree).c_str()); GenericSensor::mapSensors["heap_max_free_block"]->updateState(to_string(hmax).c_str()); diff --git a/src/ha.h b/src/ha.h index c8c568a..d559d19 100644 --- a/src/ha.h +++ b/src/ha.h @@ -258,14 +258,14 @@ namespace Ha { }; struct Number : Component, StatefulCommand { - unsigned int min = 1; - unsigned int max = 100; - unsigned int step = 1; + uint16_t min = 1; + uint16_t max = 100; + uint16_t step = 1; const char* unitMeasure = nullptr; Number(const char* name, const char* id, onMessage f) : Component(id, name, "number"), StatefulCommand(this, f) {} - void updateState(unsigned int value) { + void updateState(uint16_t value) { State::updateState(to_string(value).c_str()); } @@ -280,13 +280,13 @@ namespace Ha { }; struct Text : Component, StatefulCommand { - unsigned int min = 1; - unsigned int max = 100; + uint16_t min = 1; + uint16_t max = 100; const char* pattern = nullptr; Text(const char* name, const char* id, onMessage f) : Component(id, name, "text"), StatefulCommand(this, f) {} - void updateState(unsigned int value) { + void updateState(uint16_t value) { State::updateState(to_string(value).c_str()); } @@ -315,7 +315,7 @@ namespace Ha { }; struct BinarySensor : GenericSensor { - unsigned int off_delay_seconds = 0; + uint16_t off_delay_seconds = 0; BinarySensor(const char* id, const char* name = nullptr) : GenericSensor(id, name, "binary_sensor") {} @@ -327,7 +327,7 @@ namespace Ha { struct Sensor : GenericSensor { const char* unitMeasure = nullptr; - unsigned int precision = 2; + uint16_t precision = 2; SensorStateClass sensorStateClass; Sensor(const char* name, const char* id) : GenericSensor(id, name, "sensor") {} @@ -419,7 +419,7 @@ namespace Ha { return *this; } - Builder& withPrecision(unsigned int value) { + Builder& withPrecision(uint16_t value) { cmp->precision = value; return *this; } @@ -429,22 +429,22 @@ namespace Ha { return *this; } - Builder& withMin(unsigned int value) { + Builder& withMin(uint16_t value) { cmp->min = value; return *this; } - Builder& withMax(unsigned int value) { + Builder& withMax(uint16_t value) { cmp->max = value; return *this; } - Builder& withStep(unsigned int value) { + Builder& withStep(uint16_t value) { cmp->step = value; return *this; } - Builder& withOffDelaySeconds(unsigned int value) { + Builder& withOffDelaySeconds(uint16_t value) { cmp->off_delay_seconds = value; return *this; }