add support for precision in sensors
This commit is contained in:
parent
bf8439bdd1
commit
6c78efa3c2
@ -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.0.1",
|
"version": "1.1.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",
|
||||||
|
|||||||
8
src/ha.h
8
src/ha.h
@ -162,6 +162,11 @@ namespace Ha {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Builder& withPrecision(unsigned int value) {
|
||||||
|
cmp->precision = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Builder& addSecondary(Component* c) {
|
Builder& addSecondary(Component* c) {
|
||||||
if (cmp->mainDevice) c->mainDevice = &DeviceConfig::create(cmp->mainDevice->id);
|
if (cmp->mainDevice) c->mainDevice = &DeviceConfig::create(cmp->mainDevice->id);
|
||||||
return *this;
|
return *this;
|
||||||
@ -294,6 +299,7 @@ namespace Ha {
|
|||||||
struct Sensor : Component, StateConfig {
|
struct Sensor : Component, StateConfig {
|
||||||
const char* unitMeasure = nullptr;
|
const char* unitMeasure = nullptr;
|
||||||
const char* valueTemplate = nullptr;
|
const char* valueTemplate = nullptr;
|
||||||
|
unsigned int precision = 2;
|
||||||
static unordered_map<string, Sensor*> mapSensors;
|
static unordered_map<string, Sensor*> mapSensors;
|
||||||
|
|
||||||
Sensor(const char* name, const char* id) : Component(name, id, "sensor"), StateConfig(this) {
|
Sensor(const char* name, const char* id) : Component(name, id, "sensor"), StateConfig(this) {
|
||||||
@ -322,7 +328,7 @@ namespace Ha {
|
|||||||
StateConfig::buildConfig(jsonDoc);
|
StateConfig::buildConfig(jsonDoc);
|
||||||
if (unitMeasure) jsonDoc["unit_of_measurement"] = unitMeasure;
|
if (unitMeasure) jsonDoc["unit_of_measurement"] = unitMeasure;
|
||||||
if (valueTemplate) jsonDoc["value_template"] = valueTemplate;
|
if (valueTemplate) jsonDoc["value_template"] = valueTemplate;
|
||||||
jsonDoc["suggested_display_precision"] = 2;
|
jsonDoc["suggested_display_precision"] = precision;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user