mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
add option for rendering booleans on Dashboard #456
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
- Improved Table layout in Web UI (searching, filtering, sorting, exporting to CSV)
|
||||
- API fetch individual attributes from an entity [#462](https://github.com/emsesp/EMS-ESP32/issues/462)
|
||||
- Option to disable mDNS
|
||||
- Option for rendering booleans on dashboard [#456](https://github.com/emsesp/EMS-ESP32/issues/456)
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -402,10 +402,27 @@ const SettingsApplication: FC = () => {
|
||||
Formatting Options
|
||||
</Typography>
|
||||
<Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start">
|
||||
<Grid item xs={6}>
|
||||
<Grid item xs={4}>
|
||||
<ValidatedTextField
|
||||
name="bool_dashboard"
|
||||
label="Boolean Format Dashboard"
|
||||
value={data.bool_dashboard}
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
margin="normal"
|
||||
select
|
||||
>
|
||||
<MenuItem value={1}>on/off</MenuItem>
|
||||
<MenuItem value={2}>ON/OFF</MenuItem>
|
||||
<MenuItem value={3}>true/false</MenuItem>
|
||||
<MenuItem value={5}>1/0</MenuItem>
|
||||
</ValidatedTextField>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<ValidatedTextField
|
||||
name="bool_format"
|
||||
label="Boolean Format"
|
||||
label="Boolean Format API/MQTT"
|
||||
value={data.bool_format}
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
@@ -421,10 +438,10 @@ const SettingsApplication: FC = () => {
|
||||
<MenuItem value={6}>1/0</MenuItem>
|
||||
</ValidatedTextField>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<Grid item xs={4}>
|
||||
<ValidatedTextField
|
||||
name="enum_format"
|
||||
label="Enum Format"
|
||||
label="Enum Format API/MQTT"
|
||||
value={data.enum_format}
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
|
||||
@@ -26,6 +26,7 @@ export interface Settings {
|
||||
trace_raw: boolean;
|
||||
board_profile: string;
|
||||
bool_format: number;
|
||||
bool_dashboard: number;
|
||||
enum_format: number;
|
||||
fahrenheit: boolean;
|
||||
phy_type: number;
|
||||
|
||||
@@ -35,6 +35,7 @@ class DummySettings {
|
||||
bool notoken_api = false;
|
||||
bool readonly_mode = false;
|
||||
uint8_t bool_format = 1; // using "on" and "off"
|
||||
uint8_t bool_dashboard = 1;
|
||||
uint8_t enum_format = 1;
|
||||
bool nosleep = false;
|
||||
bool fahrenheit = false;
|
||||
|
||||
@@ -670,12 +670,8 @@ void EMSdevice::generate_values_web(JsonObject & output) {
|
||||
// handle Booleans (true, false), use strings, no native true/false)
|
||||
if (dv.type == DeviceValueType::BOOL) {
|
||||
auto value_b = (bool)*(uint8_t *)(dv.value_p);
|
||||
if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
|
||||
obj["v"] = value_b ? 1 : 0;
|
||||
} else {
|
||||
char s[7];
|
||||
obj["v"] = Helpers::render_boolean(s, value_b);
|
||||
}
|
||||
char s[7];
|
||||
obj["v"] = Helpers::render_boolean(s, value_b, true);
|
||||
}
|
||||
|
||||
// handle TEXT strings
|
||||
@@ -748,8 +744,8 @@ void EMSdevice::generate_values_web(JsonObject & output) {
|
||||
} else if (dv.type == DeviceValueType::BOOL) {
|
||||
JsonArray l = obj.createNestedArray("l");
|
||||
char result[10];
|
||||
l.add(Helpers::render_boolean(result, false));
|
||||
l.add(Helpers::render_boolean(result, true));
|
||||
l.add(Helpers::render_boolean(result, false, true));
|
||||
l.add(Helpers::render_boolean(result, true, true));
|
||||
}
|
||||
// add command help template
|
||||
else if (dv.type == DeviceValueType::STRING || dv.type == DeviceValueType::CMD) {
|
||||
@@ -789,12 +785,8 @@ void EMSdevice::generate_values_web_all(JsonArray & output) {
|
||||
// handle Booleans (true, false), use strings, no native true/false)
|
||||
if (dv.type == DeviceValueType::BOOL) {
|
||||
auto value_b = (bool)*(uint8_t *)(dv.value_p);
|
||||
if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
|
||||
obj["v"] = value_b ? 1 : 0;
|
||||
} else {
|
||||
char s[7];
|
||||
obj["v"] = Helpers::render_boolean(s, value_b);
|
||||
}
|
||||
char s[7];
|
||||
obj["v"] = Helpers::render_boolean(s, value_b, true);
|
||||
}
|
||||
|
||||
// handle TEXT strings
|
||||
|
||||
@@ -176,8 +176,8 @@ char * Helpers::smallitoa(char * result, const uint16_t value) {
|
||||
|
||||
// work out how to display booleans
|
||||
// for strings only
|
||||
char * Helpers::render_boolean(char * result, bool value) {
|
||||
uint8_t bool_format_ = EMSESP::system_.bool_format();
|
||||
char * Helpers::render_boolean(char * result, const bool value, const bool dashboard) {
|
||||
uint8_t bool_format_ = dashboard ? EMSESP::system_.bool_dashboard() : EMSESP::system_.bool_format();
|
||||
if (bool_format_ == BOOL_FORMAT_ONOFF_STR) {
|
||||
strlcpy(result, value ? read_flash_string(F_(on)).c_str() : read_flash_string(F_(off)).c_str(), 5);
|
||||
} else if (bool_format_ == BOOL_FORMAT_ONOFF_STR_CAP) {
|
||||
|
||||
@@ -37,7 +37,7 @@ class Helpers {
|
||||
static char * render_value(char * result, const uint32_t value, const int8_t format, const uint8_t fahrenheit = 0);
|
||||
static char * render_value(char * result, const int16_t value, const int8_t format, const uint8_t fahrenheit = 0);
|
||||
static char * render_value(char * result, const int32_t value, const int8_t format, const uint8_t fahrenheit = 0);
|
||||
static char * render_boolean(char * result, bool value);
|
||||
static char * render_boolean(char * result, const bool value, const bool dashboard = false);
|
||||
|
||||
static char * hextoa(char * result, const uint8_t value);
|
||||
static char * hextoa(char * result, const uint16_t value);
|
||||
|
||||
@@ -332,10 +332,11 @@ void System::reload_settings() {
|
||||
syslog_host_ = settings.syslog_host;
|
||||
syslog_port_ = settings.syslog_port;
|
||||
|
||||
fahrenheit_ = settings.fahrenheit;
|
||||
bool_format_ = settings.bool_format;
|
||||
enum_format_ = settings.enum_format;
|
||||
readonly_mode_ = settings.readonly_mode;
|
||||
fahrenheit_ = settings.fahrenheit;
|
||||
bool_format_ = settings.bool_format;
|
||||
bool_dashboard_ = settings.bool_dashboard;
|
||||
enum_format_ = settings.enum_format;
|
||||
readonly_mode_ = settings.readonly_mode;
|
||||
|
||||
phy_type_ = settings.phy_type;
|
||||
eth_power_ = settings.eth_power;
|
||||
@@ -1016,6 +1017,7 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject &
|
||||
node["fahrenheit"] = settings.fahrenheit;
|
||||
node["dallas_parasite"] = settings.dallas_parasite;
|
||||
node["bool_format"] = settings.bool_format;
|
||||
node["bool_dashboard"] = settings.bool_dashboard;
|
||||
node["enum_format"] = settings.enum_format;
|
||||
node["analog_enabled"] = settings.analog_enabled;
|
||||
node["telnet_enabled"] = settings.telnet_enabled;
|
||||
|
||||
@@ -115,6 +115,10 @@ class System {
|
||||
return bool_format_;
|
||||
}
|
||||
|
||||
uint8_t bool_dashboard() {
|
||||
return bool_dashboard_;
|
||||
}
|
||||
|
||||
// see default_settings.h
|
||||
// BOOL_FORMAT_ONOFF_STR = 1,
|
||||
// BOOL_FORMAT_ONOFF_STR_CAP = 2
|
||||
@@ -126,6 +130,10 @@ class System {
|
||||
bool_format_ = format;
|
||||
}
|
||||
|
||||
void bool_dashboard(uint8_t format) {
|
||||
bool_dashboard_ = format;
|
||||
}
|
||||
|
||||
uint8_t enum_format() {
|
||||
return enum_format_;
|
||||
}
|
||||
@@ -250,6 +258,7 @@ class System {
|
||||
String syslog_host_;
|
||||
uint16_t syslog_port_;
|
||||
bool fahrenheit_;
|
||||
uint8_t bool_dashboard_;
|
||||
uint8_t bool_format_;
|
||||
uint8_t enum_format_;
|
||||
bool readonly_mode_;
|
||||
|
||||
@@ -66,6 +66,7 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
|
||||
root["board_profile"] = settings.board_profile;
|
||||
root["fahrenheit"] = settings.fahrenheit;
|
||||
root["bool_format"] = settings.bool_format;
|
||||
root["bool_dashboard"] = settings.bool_dashboard;
|
||||
root["enum_format"] = settings.enum_format;
|
||||
root["weblog_level"] = settings.weblog_level;
|
||||
root["weblog_buffer"] = settings.weblog_buffer;
|
||||
@@ -225,6 +226,9 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
|
||||
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);
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ class WebSettings {
|
||||
uint8_t solar_maxflow;
|
||||
String board_profile;
|
||||
uint8_t bool_format;
|
||||
uint8_t bool_dashboard;
|
||||
uint8_t enum_format;
|
||||
int8_t weblog_level;
|
||||
uint8_t weblog_buffer;
|
||||
|
||||
Reference in New Issue
Block a user