fixed 1/0 and true/false MQTT/API format options with HA enabled (#931)

furthermore variable names in the HA discovery payload has been abbreviated according to: https://www.home-assistant.io/integrations/mqtt/#discovery-payload
This commit is contained in:
pswid
2023-01-29 18:52:13 +01:00
parent 74b961ab29
commit 226c1fd6c5
4 changed files with 52 additions and 32 deletions

View File

@@ -249,6 +249,21 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
}
#endif
//
// these may need mqtt restart to rebuild HA discovery topics
//
prev = settings.bool_format;
settings.bool_format = root["bool_format"] | EMSESP_DEFAULT_BOOL_FORMAT;
EMSESP::system_.bool_format(settings.bool_format);
if (Mqtt::ha_enabled())
check_flag(prev, settings.bool_format, ChangeFlags::MQTT);
prev = settings.enum_format;
settings.enum_format = root["enum_format"] | EMSESP_DEFAULT_ENUM_FORMAT;
EMSESP::system_.enum_format(settings.enum_format);
if (Mqtt::ha_enabled())
check_flag(prev, settings.enum_format, ChangeFlags::MQTT);
//
// without checks or necessary restarts...
//
@@ -264,15 +279,9 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
settings.readonly_mode = root["readonly_mode"] | false;
EMSESP::system_.readonly_mode(settings.readonly_mode);
settings.bool_format = root["bool_format"] | EMSESP_DEFAULT_BOOL_FORMAT;
EMSESP::system_.bool_format(settings.bool_format);
settings.bool_dashboard = root["bool_dashboard"] | EMSESP_DEFAULT_BOOL_FORMAT;
EMSESP::system_.bool_dashboard(settings.bool_dashboard);
settings.enum_format = root["enum_format"] | EMSESP_DEFAULT_ENUM_FORMAT;
EMSESP::system_.enum_format(settings.enum_format);
settings.weblog_level = root["weblog_level"] | EMSESP_DEFAULT_WEBLOG_LEVEL;
settings.weblog_buffer = root["weblog_buffer"] | EMSESP_DEFAULT_WEBLOG_BUFFER;
settings.weblog_compact = root["weblog_compact"] | EMSESP_DEFAULT_WEBLOG_COMPACT;