Merge branch 'v1.5.0'
This commit is contained in:
commit
348ae0bd7d
@ -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.2",
|
"version": "1.5.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",
|
||||||
|
|||||||
40
src/ha.h
40
src/ha.h
@ -224,6 +224,20 @@ namespace Ha {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Light : Component, StatefulCommand {
|
||||||
|
|
||||||
|
Light(const char* name, const char* id, onMessage f = nullptr) : Component(id, name, "light"), StatefulCommand(this, f) {}
|
||||||
|
|
||||||
|
void updateState(bool state) {
|
||||||
|
State::updateState(state ? "ON" : "OFF");
|
||||||
|
}
|
||||||
|
|
||||||
|
void buildConfig(JsonDocument& jsonDoc) override {
|
||||||
|
Component::buildConfig(jsonDoc);
|
||||||
|
StatefulCommand::buildConfig(jsonDoc);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct Number : Component, StatefulCommand {
|
struct Number : Component, StatefulCommand {
|
||||||
unsigned int min = 1;
|
unsigned int min = 1;
|
||||||
unsigned int max = 100;
|
unsigned int max = 100;
|
||||||
@ -244,6 +258,27 @@ namespace Ha {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Text : Component, StatefulCommand {
|
||||||
|
unsigned int min = 1;
|
||||||
|
unsigned int 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) {
|
||||||
|
State::updateState(to_string(value).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void buildConfig(JsonDocument& jsonDoc) override {
|
||||||
|
Component::buildConfig(jsonDoc);
|
||||||
|
StatefulCommand::buildConfig(jsonDoc);
|
||||||
|
jsonDoc["min"] = min;
|
||||||
|
jsonDoc["max"] = max;
|
||||||
|
jsonDoc["platform"] = "text";
|
||||||
|
if (pattern) jsonDoc["pattern"] = pattern;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct Sensor : Component, State {
|
struct Sensor : Component, State {
|
||||||
const char* unitMeasure = nullptr;
|
const char* unitMeasure = nullptr;
|
||||||
const char* valueTemplate = nullptr;
|
const char* valueTemplate = nullptr;
|
||||||
@ -377,6 +412,11 @@ namespace Ha {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Builder& withPattern(const char* value) {
|
||||||
|
cmp->pattern = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Builder& withJsonAttributes(const char* value) {
|
Builder& withJsonAttributes(const char* value) {
|
||||||
cmp->jsonAttributesTemplate = value;
|
cmp->jsonAttributesTemplate = value;
|
||||||
return *this;
|
return *this;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user