Merge branch 'v1.6.0'
This commit is contained in:
commit
e129097b52
@ -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.5.1",
|
"version": "1.6.0",
|
||||||
"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",
|
||||||
|
|||||||
@ -60,6 +60,15 @@ namespace HaESP {
|
|||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Builder<Button>& restartButton() {
|
||||||
|
return Builder<Button>::instance(new Button{"Restart", "restart",
|
||||||
|
[](const char* msg) {
|
||||||
|
if (strcmp("PRESS", msg) == 0) ESP.restart();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.withIcon("mdi:restart");
|
||||||
|
}
|
||||||
|
|
||||||
void enableSensors() {
|
void enableSensors() {
|
||||||
if (activeSensors.heapStats) tHeap.enable();
|
if (activeSensors.heapStats) tHeap.enable();
|
||||||
if (activeSensors.restartInfo) tRestartInfo.enable();
|
if (activeSensors.restartInfo) tRestartInfo.enable();
|
||||||
|
|||||||
13
src/ha.h
13
src/ha.h
@ -77,6 +77,7 @@ namespace Ha {
|
|||||||
const char* name = nullptr;
|
const char* name = nullptr;
|
||||||
const char* entityCategory = nullptr;
|
const char* entityCategory = nullptr;
|
||||||
const char* deviceClass = nullptr;
|
const char* deviceClass = nullptr;
|
||||||
|
const char* icon = nullptr;
|
||||||
DeviceConfig* mainDevice = nullptr;
|
DeviceConfig* mainDevice = nullptr;
|
||||||
inline static List<Component> components;
|
inline static List<Component> components;
|
||||||
bool multiValueComponent = false;
|
bool multiValueComponent = false;
|
||||||
@ -104,6 +105,7 @@ namespace Ha {
|
|||||||
if (mainDevice) mainDevice->buildConfig(jsonDoc);
|
if (mainDevice) mainDevice->buildConfig(jsonDoc);
|
||||||
if (entityCategory) jsonDoc["entity_category"] = entityCategory;
|
if (entityCategory) jsonDoc["entity_category"] = entityCategory;
|
||||||
if (deviceClass) jsonDoc["device_class"] = deviceClass;
|
if (deviceClass) jsonDoc["device_class"] = deviceClass;
|
||||||
|
if (icon) jsonDoc["icon"] = icon;
|
||||||
jsonDoc["name"] = name;
|
jsonDoc["name"] = name;
|
||||||
|
|
||||||
buildUniqueId(jsonDoc);
|
buildUniqueId(jsonDoc);
|
||||||
@ -159,6 +161,7 @@ namespace Ha {
|
|||||||
struct State : Config {
|
struct State : Config {
|
||||||
char stateTopic[TOPIC_SIZE] = {};
|
char stateTopic[TOPIC_SIZE] = {};
|
||||||
const char* jsonAttributesTemplate = nullptr;
|
const char* jsonAttributesTemplate = nullptr;
|
||||||
|
const char* valueTemplate = nullptr;
|
||||||
|
|
||||||
State(Component* cmp) : cmp(cmp) {}
|
State(Component* cmp) : cmp(cmp) {}
|
||||||
|
|
||||||
@ -178,6 +181,7 @@ namespace Ha {
|
|||||||
jsonDoc["json_attributes_template"] = jsonAttributesTemplate;
|
jsonDoc["json_attributes_template"] = jsonAttributesTemplate;
|
||||||
jsonDoc["json_attributes_topic"] = (const char*)stateTopic;
|
jsonDoc["json_attributes_topic"] = (const char*)stateTopic;
|
||||||
}
|
}
|
||||||
|
if (valueTemplate) jsonDoc["value_template"] = valueTemplate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
@ -243,6 +247,7 @@ namespace Ha {
|
|||||||
unsigned int min = 1;
|
unsigned int min = 1;
|
||||||
unsigned int max = 100;
|
unsigned int max = 100;
|
||||||
unsigned int step = 1;
|
unsigned int step = 1;
|
||||||
|
const char* unitMeasure = nullptr;
|
||||||
|
|
||||||
Number(const char* name, const char* id, onMessage f) : Component(id, name, "number"), StatefulCommand(this, f) {}
|
Number(const char* name, const char* id, onMessage f) : Component(id, name, "number"), StatefulCommand(this, f) {}
|
||||||
|
|
||||||
@ -256,6 +261,7 @@ namespace Ha {
|
|||||||
jsonDoc["min"] = min;
|
jsonDoc["min"] = min;
|
||||||
jsonDoc["max"] = max;
|
jsonDoc["max"] = max;
|
||||||
jsonDoc["step"] = step;
|
jsonDoc["step"] = step;
|
||||||
|
if (unitMeasure) jsonDoc["unit_of_measurement"] = unitMeasure;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -282,7 +288,6 @@ namespace Ha {
|
|||||||
|
|
||||||
struct Sensor : Component, State {
|
struct Sensor : Component, State {
|
||||||
const char* unitMeasure = nullptr;
|
const char* unitMeasure = nullptr;
|
||||||
const char* valueTemplate = nullptr;
|
|
||||||
unsigned int precision = 2;
|
unsigned int precision = 2;
|
||||||
inline static unordered_map<string, Sensor*> mapSensors;
|
inline static unordered_map<string, Sensor*> mapSensors;
|
||||||
|
|
||||||
@ -295,7 +300,6 @@ namespace Ha {
|
|||||||
Component::buildConfig(jsonDoc);
|
Component::buildConfig(jsonDoc);
|
||||||
State::buildConfig(jsonDoc);
|
State::buildConfig(jsonDoc);
|
||||||
if (unitMeasure) jsonDoc["unit_of_measurement"] = unitMeasure;
|
if (unitMeasure) jsonDoc["unit_of_measurement"] = unitMeasure;
|
||||||
if (valueTemplate) jsonDoc["value_template"] = valueTemplate;
|
|
||||||
if (isNumericSensor()) jsonDoc["suggested_display_precision"] = precision;
|
if (isNumericSensor()) jsonDoc["suggested_display_precision"] = precision;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,6 +392,11 @@ namespace Ha {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Builder& withIcon(const char* value) {
|
||||||
|
cmp->icon = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Builder& withValueTemplate(const char* value) {
|
Builder& withValueTemplate(const char* value) {
|
||||||
cmp->valueTemplate = value;
|
cmp->valueTemplate = value;
|
||||||
return *this;
|
return *this;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user