From ab11cdacd866adef1cf7fc02823509d14bec8fc8 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Fri, 10 Jan 2025 13:33:58 +0100 Subject: [PATCH] use inline for static members - avoid declaring them outside of class --- library.json | 2 +- src/ha.h | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/library.json b/library.json index 09207b2..6ddcfee 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json", "name": "ha-mqtt", - "version": "1.4.1", + "version": "1.4.2", "description": "Home Assistant classes for integration with MQTT auto discovery", "repository": { "type": "git", diff --git a/src/ha.h b/src/ha.h index ae43d0a..3139cdb 100644 --- a/src/ha.h +++ b/src/ha.h @@ -78,7 +78,7 @@ namespace Ha { const char* entityCategory = nullptr; const char* deviceClass = nullptr; DeviceConfig* mainDevice = nullptr; - static List components; + inline static List components; bool multiValueComponent = false; Component(const char* id, const char* name, const char* type) : id(id), type(type), name(name) { @@ -133,7 +133,7 @@ namespace Ha { struct Command : Config { bool retain = false; - static unordered_map mapCommandTopics; + inline static unordered_map mapCommandTopics; Command(Component* cmp, onMessage f) : f(f), cmp(cmp) { snprintf(commandTopic, sizeof(commandTopic), BASE_TOPIC"/set", cmp->type, MAIN_DEVICE_ID, cmp->id); @@ -185,7 +185,7 @@ namespace Ha { }; struct StatefulCommand : Command, State { - static unordered_map mapRestoreStateTopics; + inline static unordered_map mapRestoreStateTopics; StatefulCommand(Component* cmp, onMessage f) : Command(cmp, f), State(cmp) {} @@ -248,7 +248,7 @@ namespace Ha { const char* unitMeasure = nullptr; const char* valueTemplate = nullptr; unsigned int precision = 2; - static unordered_map mapSensors; + inline static unordered_map mapSensors; Sensor(const char* name, const char* id) : Component(id, name, "sensor"), State(this) { withStateTopic(); @@ -307,7 +307,7 @@ namespace Ha { }; struct AbstractBuilder { - static List builders; + inline static List builders; static void deleteAll() { builders.forEach([](AbstractBuilder* builder) { delete builder; }); @@ -422,10 +422,4 @@ namespace Ha { return *this; } }; - - List Component::components; - List AbstractBuilder::builders; - unordered_map Command::mapCommandTopics; - unordered_map Sensor::mapSensors; - unordered_map StatefulCommand::mapRestoreStateTopics; }