mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-26 16:49:11 +03:00
merge mqtt ha number mode
This commit is contained in:
@@ -248,6 +248,7 @@ void MqttSettings::read(MqttSettings & settings, JsonObject root) {
|
||||
root["nested_format"] = settings.nested_format;
|
||||
root["discovery_prefix"] = settings.discovery_prefix;
|
||||
root["discovery_type"] = settings.discovery_type;
|
||||
root["ha_number_mode"] = settings.ha_number_mode;
|
||||
root["publish_single"] = settings.publish_single;
|
||||
root["publish_single2cmd"] = settings.publish_single2cmd;
|
||||
root["send_response"] = settings.send_response;
|
||||
@@ -288,6 +289,7 @@ StateUpdateResult MqttSettings::update(JsonObject root, MqttSettings & settings)
|
||||
newSettings.nested_format = static_cast<uint8_t>(root["nested_format"] | EMSESP_DEFAULT_NESTED_FORMAT);
|
||||
newSettings.discovery_prefix = root["discovery_prefix"] | EMSESP_DEFAULT_DISCOVERY_PREFIX;
|
||||
newSettings.discovery_type = static_cast<uint8_t>(root["discovery_type"] | EMSESP_DEFAULT_DISCOVERY_TYPE);
|
||||
newSettings.ha_number_mode = static_cast<uint8_t>(root["ha_number_mode"] | EMSESP_DEFAULT_HA_NUMBER_MODE);
|
||||
newSettings.publish_single = root["publish_single"] | EMSESP_DEFAULT_PUBLISH_SINGLE;
|
||||
newSettings.publish_single2cmd = root["publish_single2cmd"] | EMSESP_DEFAULT_PUBLISH_SINGLE2CMD;
|
||||
newSettings.send_response = root["send_response"] | EMSESP_DEFAULT_SEND_RESPONSE;
|
||||
|
||||
@@ -93,6 +93,7 @@ class MqttSettings {
|
||||
uint8_t nested_format = EMSESP_DEFAULT_NESTED_FORMAT;
|
||||
String discovery_prefix = EMSESP_DEFAULT_DISCOVERY_PREFIX;
|
||||
uint8_t discovery_type = EMSESP_DEFAULT_DISCOVERY_TYPE;
|
||||
uint8_t ha_number_mode = EMSESP_DEFAULT_HA_NUMBER_MODE;
|
||||
bool publish_single = EMSESP_DEFAULT_PUBLISH_SINGLE;
|
||||
bool publish_single2cmd = EMSESP_DEFAULT_PUBLISH_SINGLE2CMD;
|
||||
bool send_response = EMSESP_DEFAULT_SEND_RESPONSE;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "3.8.1-dev.5"
|
||||
#define EMSESP_APP_VERSION "3.8.1-dev.6"
|
||||
|
||||
Reference in New Issue
Block a user