From ce0ee49ebf83e484fb833b9e31f59673bce4adc6 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sun, 18 Dec 2022 16:22:18 +0100 Subject: [PATCH] add step to numeric command-values in HA discovery --- src/mqtt.cpp | 14 ++++++++++---- src/mqtt.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 8a1d7ef07..9dd961435 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -942,6 +942,7 @@ void Mqtt::publish_ha_sensor_config(DeviceValue & dv, const std::string & model, dv.options_size, dv_set_min, dv_set_max, + dv.numeric_operator, dev_json.as()); } @@ -953,7 +954,7 @@ void Mqtt::publish_system_ha_sensor_config(uint8_t type, const char * name, cons JsonArray ids = dev_json.createNestedArray("ids"); ids.add("ems-esp"); - publish_ha_sensor_config(type, DeviceValueTAG::TAG_HEARTBEAT, name, name, EMSdevice::DeviceType::SYSTEM, entity, uom, false, false, nullptr, 0, 0, 0, dev_json); + publish_ha_sensor_config(type, DeviceValueTAG::TAG_HEARTBEAT, name, name, EMSdevice::DeviceType::SYSTEM, entity, uom, false, false, nullptr, 0, 0, 0, 0, dev_json); } // MQTT discovery configs @@ -972,6 +973,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev uint8_t options_size, const int16_t dv_set_min, const int16_t dv_set_max, + const int8_t num_op, const JsonObject & dev_json) { // ignore if name (fullname) is empty if (!fullname || !en_name) { @@ -1097,15 +1099,19 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev // mode can be auto, slider or box. Because its fiddly and error prone, force conversion to box // but... this is not currently supported in HA MQTT Number yet! // doc["mode"] = "box"; + if (num_op > 0) { + doc["step"] = 1.0 / num_op; + } else if (num_op < 0) { + doc["step"] = -num_op; + } else { + doc["step"] = 1; + } } // set min and max values, if we have a valid range if (dv_set_min != 0 || dv_set_max != 0) { doc["min"] = dv_set_min; doc["max"] = dv_set_max; - if ((uom == DeviceValueUOM::DEGREES) || (uom == DeviceValueUOM::DEGREES_R)) { - doc["step"] = 0.5; - } } // set icons diff --git a/src/mqtt.h b/src/mqtt.h index cf19d6c8e..1bc46f390 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -105,6 +105,7 @@ class Mqtt { uint8_t options_size, const int16_t dv_set_min, const int16_t dv_set_max, + const int8_t num_op, const JsonObject & dev_json); static void publish_system_ha_sensor_config(uint8_t type, const char * name, const char * entity, const uint8_t uom);