merge mqtt ha number mode

This commit is contained in:
MichaelDvP
2026-01-08 21:12:52 +01:00
22 changed files with 91 additions and 50 deletions

View File

@@ -210,6 +210,10 @@
#define EMSESP_DEFAULT_DISCOVERY_TYPE 0 // HA
#endif
#ifndef EMSESP_DEFAULT_HA_NUMBER_MODE
#define EMSESP_DEFAULT_HA_NUMBER_MODE 0 // BOX
#endif
#ifndef EMSESP_DEFAULT_PUBLISH_SINGLE
#define EMSESP_DEFAULT_PUBLISH_SINGLE false
#endif

View File

@@ -43,6 +43,7 @@ bool Mqtt::ha_enabled_;
uint8_t Mqtt::nested_format_;
std::string Mqtt::discovery_prefix_;
uint8_t Mqtt::discovery_type_;
uint8_t Mqtt::ha_number_mode_;
bool Mqtt::send_response_;
bool Mqtt::publish_single_;
bool Mqtt::publish_single2cmd_;
@@ -343,6 +344,7 @@ void Mqtt::load_settings() {
discovery_prefix_ = mqttSettings.discovery_prefix.c_str();
entity_format_ = mqttSettings.entity_format;
discovery_type_ = mqttSettings.discovery_type;
ha_number_mode_ = mqttSettings.ha_number_mode;
// convert to milliseconds
publish_time_boiler_ = mqttSettings.publish_time_boiler * 1000;
@@ -1024,8 +1026,12 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
snprintf(sample_val, sizeof(sample_val), "'%s'", Helpers::translated_word(options[0]));
}
} else if (type != DeviceValueType::STRING && type != DeviceValueType::BOOL) {
// For numeric's add the range
doc["mode"] = "box"; // auto, slider or box
// For numeric's add the range and mode
if (ha_number_mode_ == 1 && (dv_set_max - dv_set_min) <= 100) {
doc["mode"] = "slider";
} else {
doc["mode"] = "box"; // auto, slider or box
}
if (num_op > 0) {
doc["step"] = 1.0 / num_op;
} else if (num_op < 0) {

View File

@@ -341,6 +341,7 @@ class Mqtt {
static uint8_t entity_format_;
static std::string discovery_prefix_;
static uint8_t discovery_type_;
static uint8_t ha_number_mode_;
static bool publish_single_;
static bool publish_single2cmd_;
static bool send_response_;