use inline for static members - avoid declaring them outside of class
This commit is contained in:
parent
a3b8b8a65d
commit
ab11cdacd8
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
|
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
|
||||||
"name": "ha-mqtt",
|
"name": "ha-mqtt",
|
||||||
"version": "1.4.1",
|
"version": "1.4.2",
|
||||||
"description": "Home Assistant classes for integration with MQTT auto discovery",
|
"description": "Home Assistant classes for integration with MQTT auto discovery",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
16
src/ha.h
16
src/ha.h
@ -78,7 +78,7 @@ namespace Ha {
|
|||||||
const char* entityCategory = nullptr;
|
const char* entityCategory = nullptr;
|
||||||
const char* deviceClass = nullptr;
|
const char* deviceClass = nullptr;
|
||||||
DeviceConfig* mainDevice = nullptr;
|
DeviceConfig* mainDevice = nullptr;
|
||||||
static List<Component> components;
|
inline static List<Component> components;
|
||||||
bool multiValueComponent = false;
|
bool multiValueComponent = false;
|
||||||
|
|
||||||
Component(const char* id, const char* name, const char* type) : id(id), type(type), name(name) {
|
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 {
|
struct Command : Config {
|
||||||
bool retain = false;
|
bool retain = false;
|
||||||
static unordered_map<string, Command*> mapCommandTopics;
|
inline static unordered_map<string, Command*> mapCommandTopics;
|
||||||
|
|
||||||
Command(Component* cmp, onMessage f) : f(f), cmp(cmp) {
|
Command(Component* cmp, onMessage f) : f(f), cmp(cmp) {
|
||||||
snprintf(commandTopic, sizeof(commandTopic), BASE_TOPIC"/set", cmp->type, MAIN_DEVICE_ID, cmp->id);
|
snprintf(commandTopic, sizeof(commandTopic), BASE_TOPIC"/set", cmp->type, MAIN_DEVICE_ID, cmp->id);
|
||||||
@ -185,7 +185,7 @@ namespace Ha {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct StatefulCommand : Command, State {
|
struct StatefulCommand : Command, State {
|
||||||
static unordered_map<string, Command*> mapRestoreStateTopics;
|
inline static unordered_map<string, Command*> mapRestoreStateTopics;
|
||||||
|
|
||||||
StatefulCommand(Component* cmp, onMessage f) : Command(cmp, f), State(cmp) {}
|
StatefulCommand(Component* cmp, onMessage f) : Command(cmp, f), State(cmp) {}
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ namespace Ha {
|
|||||||
const char* unitMeasure = nullptr;
|
const char* unitMeasure = nullptr;
|
||||||
const char* valueTemplate = nullptr;
|
const char* valueTemplate = nullptr;
|
||||||
unsigned int precision = 2;
|
unsigned int precision = 2;
|
||||||
static unordered_map<string, Sensor*> mapSensors;
|
inline static unordered_map<string, Sensor*> mapSensors;
|
||||||
|
|
||||||
Sensor(const char* name, const char* id) : Component(id, name, "sensor"), State(this) {
|
Sensor(const char* name, const char* id) : Component(id, name, "sensor"), State(this) {
|
||||||
withStateTopic();
|
withStateTopic();
|
||||||
@ -307,7 +307,7 @@ namespace Ha {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct AbstractBuilder {
|
struct AbstractBuilder {
|
||||||
static List<AbstractBuilder> builders;
|
inline static List<AbstractBuilder> builders;
|
||||||
|
|
||||||
static void deleteAll() {
|
static void deleteAll() {
|
||||||
builders.forEach([](AbstractBuilder* builder) { delete builder; });
|
builders.forEach([](AbstractBuilder* builder) { delete builder; });
|
||||||
@ -422,10 +422,4 @@ namespace Ha {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
List<Component> Component::components;
|
|
||||||
List<AbstractBuilder> AbstractBuilder::builders;
|
|
||||||
unordered_map<string, Command*> Command::mapCommandTopics;
|
|
||||||
unordered_map<string, Sensor*> Sensor::mapSensors;
|
|
||||||
unordered_map<string, Command*> StatefulCommand::mapRestoreStateTopics;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user