add steps to web input of numbers, #329

This commit is contained in:
MichaelDvP
2022-01-26 18:35:55 +01:00
parent 233d82805b
commit 508a707c6e
3 changed files with 17 additions and 4 deletions

View File

@@ -244,6 +244,7 @@ const DashboardData: FC = () => {
sx={{ width: '30ch' }}
type={deviceValue.u ? 'number' : 'text'}
onChange={updateValue(setDeviceValue)}
inputProps={{ step: deviceValue.s }}
InputProps={{
startAdornment: <InputAdornment position="start">{DeviceValueUOM_s[deviceValue.u]}</InputAdornment>
}}

View File

@@ -132,6 +132,7 @@ export interface DeviceValue {
c: string; // command
l: string[]; // list
h?: string; // help text
s?: string; // steps for up/down
}
export interface DeviceData {

View File

@@ -731,17 +731,28 @@ void EMSdevice::generate_values_web(JsonObject & output) {
l.add(read_flash_string(dv.options[i]));
}
}
}
if (dv.type == DeviceValueType::BOOL) {
} else if (dv.type == DeviceValueType::BOOL) {
JsonArray l = obj.createNestedArray("l");
l.add("off");
l.add("on");
}
// add command help template
if ((dv.type == DeviceValueType::STRING || dv.type == DeviceValueType::CMD) && dv.options_size == 1) {
else if (dv.type == DeviceValueType::STRING || dv.type == DeviceValueType::CMD) {
if (dv.options_size == 1) {
obj["h"] = dv.options[0];
}
}
// add steps to numeric values with divider/multiplier
else {
int8_t divider = (dv.options_size == 1) ? Helpers::atoint(read_flash_string(dv.options[0]).c_str()) : 0;
char s[10];
if (divider > 0) {
obj["s"] = Helpers::render_value(s, (float)1 / divider, 1);
} else if (divider < 0) {
obj["s"] = Helpers::render_value(s, (-1) * divider, 0);
}
}
}
}
}
}