mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
Move dallas/bool/enum formats to Settings #76
This commit is contained in:
@@ -22,5 +22,6 @@
|
||||
- added debug target to PlatformIO build to help hunt down system crashes
|
||||
- enumerated values always start at zero
|
||||
- maintenance settings for time/date as extra setting
|
||||
- move api/mqtt formats to `settings`, add `enum format`
|
||||
|
||||
## Removed
|
||||
|
||||
@@ -187,32 +187,6 @@ class MqttSettingsForm extends React.Component<MqttSettingsFormProps> {
|
||||
<MenuItem value={1}>nested on a single topic</MenuItem>
|
||||
<MenuItem value={2}>as individual topics</MenuItem>
|
||||
</SelectValidator>
|
||||
<SelectValidator
|
||||
name="dallas_format"
|
||||
label="Dallas Sensor Payload Grouping"
|
||||
value={data.dallas_format}
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
onChange={handleValueChange('dallas_format')}
|
||||
margin="normal"
|
||||
>
|
||||
<MenuItem value={1}>by Sensor ID</MenuItem>
|
||||
<MenuItem value={2}>by Number</MenuItem>
|
||||
</SelectValidator>
|
||||
<SelectValidator
|
||||
name="bool_format"
|
||||
label="Boolean Format"
|
||||
value={data.bool_format}
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
onChange={handleValueChange('bool_format')}
|
||||
margin="normal"
|
||||
>
|
||||
<MenuItem value={1}>"on"/"off"</MenuItem>
|
||||
<MenuItem value={2}>true/false</MenuItem>
|
||||
<MenuItem value={3}>1/0</MenuItem>
|
||||
<MenuItem value={4}>"ON"/"OFF"</MenuItem>
|
||||
</SelectValidator>
|
||||
<SelectValidator
|
||||
name="subscribe_format"
|
||||
label="Subscribe Format"
|
||||
|
||||
@@ -34,8 +34,6 @@ export interface MqttSettings {
|
||||
publish_time_mixer: number;
|
||||
publish_time_other: number;
|
||||
publish_time_sensor: number;
|
||||
dallas_format: number;
|
||||
bool_format: number;
|
||||
mqtt_qos: number;
|
||||
mqtt_retain: boolean;
|
||||
ha_enabled: boolean;
|
||||
|
||||
@@ -394,16 +394,6 @@ class EMSESPSettingsForm extends Component<EMSESPSettingsFormProps> {
|
||||
/>
|
||||
)}
|
||||
|
||||
<BlockFormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={data.notoken_api}
|
||||
onChange={handleValueChange('notoken_api')}
|
||||
value="notoken_api"
|
||||
/>
|
||||
}
|
||||
label="Bypass Access Token authorization on API calls"
|
||||
/>
|
||||
<BlockFormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
@@ -453,6 +443,74 @@ class EMSESPSettingsForm extends Component<EMSESPSettingsFormProps> {
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<br></br>
|
||||
<Typography variant="h6" color="primary">
|
||||
API and MQTT Options
|
||||
</Typography>
|
||||
|
||||
<BlockFormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={data.notoken_api}
|
||||
onChange={handleValueChange('notoken_api')}
|
||||
value="notoken_api"
|
||||
/>
|
||||
}
|
||||
label="Bypass Access Token authorization on API calls"
|
||||
/>
|
||||
<Grid
|
||||
container
|
||||
spacing={1}
|
||||
direction="row"
|
||||
justify="flex-start"
|
||||
alignItems="flex-start"
|
||||
>
|
||||
<Grid item xs={4}>
|
||||
<SelectValidator
|
||||
name="bool_format"
|
||||
label="Boolean Format"
|
||||
value={data.bool_format}
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
onChange={handleValueChange('bool_format')}
|
||||
margin="normal"
|
||||
>
|
||||
<MenuItem value={1}>"on"/"off"</MenuItem>
|
||||
<MenuItem value={2}>"ON"/"OFF"</MenuItem>
|
||||
<MenuItem value={3}>true/false</MenuItem>
|
||||
<MenuItem value={4}>1/0</MenuItem>
|
||||
</SelectValidator>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<SelectValidator
|
||||
name="enum_format"
|
||||
label="Enum Format"
|
||||
value={data.enum_format}
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
onChange={handleValueChange('enum_format')}
|
||||
margin="normal"
|
||||
>
|
||||
<MenuItem value={1}>Text</MenuItem>
|
||||
<MenuItem value={2}>Number</MenuItem>
|
||||
</SelectValidator>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<SelectValidator
|
||||
name="dallas_format"
|
||||
label="Sensor Publishing"
|
||||
value={data.dallas_format}
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
onChange={handleValueChange('dallas_format')}
|
||||
margin="normal"
|
||||
>
|
||||
<MenuItem value={1}>by Sensor ID</MenuItem>
|
||||
<MenuItem value={2}>by Number</MenuItem>
|
||||
</SelectValidator>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<br></br>
|
||||
<Typography variant="h6" color="primary">
|
||||
Syslog
|
||||
|
||||
@@ -22,6 +22,9 @@ export interface EMSESPSettings {
|
||||
pbutton_gpio: number;
|
||||
trace_raw: boolean;
|
||||
board_profile: string;
|
||||
bool_format: number;
|
||||
dallas_format: number;
|
||||
enum_format: number;
|
||||
}
|
||||
|
||||
export enum busConnectionStatus {
|
||||
|
||||
@@ -163,8 +163,6 @@ void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
|
||||
root["publish_time_sensor"] = settings.publish_time_sensor;
|
||||
root["mqtt_qos"] = settings.mqtt_qos;
|
||||
root["mqtt_retain"] = settings.mqtt_retain;
|
||||
root["dallas_format"] = settings.dallas_format;
|
||||
root["bool_format"] = settings.bool_format;
|
||||
root["ha_climate_format"] = settings.ha_climate_format;
|
||||
root["ha_enabled"] = settings.ha_enabled;
|
||||
root["nested_format"] = settings.nested_format;
|
||||
@@ -195,8 +193,6 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
||||
newSettings.publish_time_other = root["publish_time_other"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
||||
newSettings.publish_time_sensor = root["publish_time_sensor"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
||||
|
||||
newSettings.dallas_format = root["dallas_format"] | EMSESP_DEFAULT_DALLAS_FORMAT;
|
||||
newSettings.bool_format = root["bool_format"] | EMSESP_DEFAULT_BOOL_FORMAT;
|
||||
newSettings.ha_climate_format = root["ha_climate_format"] | EMSESP_DEFAULT_HA_CLIMATE_FORMAT;
|
||||
newSettings.ha_enabled = root["ha_enabled"] | EMSESP_DEFAULT_HA_ENABLED;
|
||||
newSettings.nested_format = root["nested_format"] | EMSESP_DEFAULT_NESTED_FORMAT;
|
||||
@@ -211,11 +207,6 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (newSettings.dallas_format != settings.dallas_format) {
|
||||
emsesp::EMSESP::mqtt_.dallas_format(newSettings.dallas_format);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (newSettings.nested_format != settings.nested_format) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
@@ -86,8 +86,6 @@ class MqttSettings {
|
||||
uint16_t publish_time_sensor;
|
||||
uint8_t mqtt_qos;
|
||||
bool mqtt_retain;
|
||||
uint8_t dallas_format;
|
||||
uint8_t bool_format;
|
||||
uint8_t ha_climate_format;
|
||||
bool ha_enabled;
|
||||
uint8_t nested_format;
|
||||
|
||||
@@ -26,13 +26,15 @@ class DummySettings {
|
||||
bool shower_alert = false;
|
||||
bool hide_led = false;
|
||||
bool notoken_api = false;
|
||||
uint8_t bool_format = 1; // on off
|
||||
uint8_t enum_format = 1;
|
||||
uint8_t dallas_format = 1;
|
||||
|
||||
// MQTT
|
||||
uint16_t publish_time = 10; // seconds
|
||||
uint8_t mqtt_qos = 0;
|
||||
bool mqtt_retain = false;
|
||||
bool enabled = true;
|
||||
uint8_t dallas_format = 1;
|
||||
uint8_t nested_format = 1;
|
||||
uint8_t ha_climate_format = 1;
|
||||
bool ha_enabled = true;
|
||||
@@ -56,7 +58,6 @@ class DummySettings {
|
||||
uint16_t publish_time_mixer = 10;
|
||||
uint16_t publish_time_other = 10;
|
||||
uint16_t publish_time_sensor = 10;
|
||||
uint8_t bool_format = 1; // on off
|
||||
|
||||
#define FACTORY_MQTT_MAX_TOPIC_LENGTH 128
|
||||
|
||||
|
||||
@@ -214,8 +214,6 @@ const mqtt_settings = {
|
||||
publish_time_sensor: 10,
|
||||
mqtt_qos: 0,
|
||||
mqtt_retain: false,
|
||||
dallas_format: 1,
|
||||
bool_format: 1,
|
||||
ha_climate_format: 1,
|
||||
ha_enabled: true,
|
||||
nested_format: 1,
|
||||
@@ -307,6 +305,9 @@ const emsesp_settings = {
|
||||
analog_enabled: false,
|
||||
pbutton_gpio: 0,
|
||||
board_profile: 'S32',
|
||||
dallas_format: 1,
|
||||
bool_format: 1,
|
||||
enum_format: 1,
|
||||
}
|
||||
const emsesp_alldevices = {
|
||||
devices: [
|
||||
|
||||
@@ -57,8 +57,9 @@ void DallasSensor::start() {
|
||||
// load the MQTT settings
|
||||
void DallasSensor::reload() {
|
||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
||||
dallas_gpio_ = settings.dallas_gpio;
|
||||
parasite_ = settings.dallas_parasite;
|
||||
dallas_gpio_ = settings.dallas_gpio;
|
||||
parasite_ = settings.dallas_parasite;
|
||||
dallas_format_ = settings.dallas_format;
|
||||
});
|
||||
|
||||
if (Mqtt::ha_enabled()) {
|
||||
@@ -338,7 +339,7 @@ bool DallasSensor::command_info(const char * value, const int8_t id, JsonObject
|
||||
dataSensor["temp"] = (float)(sensor.temperature_c) / 10;
|
||||
}
|
||||
} else { // show according to format
|
||||
if (Mqtt::dallas_format() == Mqtt::Dallas_Format::SENSORID && Helpers::hasValue(sensor.temperature_c)) {
|
||||
if (dallas_format_ == Dallas_Format::SENSORID && Helpers::hasValue(sensor.temperature_c)) {
|
||||
json[sensor.to_string()] = (float)(sensor.temperature_c) / 10;
|
||||
} else if (Helpers::hasValue(sensor.temperature_c)) {
|
||||
json[sensorID] = (float)(sensor.temperature_c) / 10;
|
||||
@@ -360,19 +361,15 @@ void DallasSensor::publish_values(const bool force) {
|
||||
DynamicJsonDocument doc(100 * num_sensors);
|
||||
uint8_t sensor_no = 1;
|
||||
|
||||
// dallas format is overriden when using Home Assistant
|
||||
// uint8_t dallas_format = Mqtt::ha_enabled() ? Mqtt::Dallas_Format::NUMBER : Mqtt::dallas_format();
|
||||
uint8_t dallas_format = Mqtt::dallas_format();
|
||||
|
||||
for (const auto & sensor : sensors_) {
|
||||
char sensorID[10]; // sensor{1-n}
|
||||
snprintf_P(sensorID, 10, PSTR("sensor%d"), sensor_no);
|
||||
if (dallas_format == Mqtt::Dallas_Format::SENSORID) {
|
||||
if (dallas_format_ == Dallas_Format::SENSORID) {
|
||||
// e.g. dallassensor_data = {"28-EA41-9497-0E03":23.3,"28-233D-9497-0C03":24.0}
|
||||
if (Helpers::hasValue(sensor.temperature_c)) {
|
||||
doc[sensor.to_string()] = (float)(sensor.temperature_c) / 10;
|
||||
}
|
||||
} else if (dallas_format == Mqtt::Dallas_Format::NUMBER) {
|
||||
} else if (dallas_format_ == Dallas_Format::NUMBER) {
|
||||
// e.g. dallassensor_data = {"sensor1":{"id":"28-EA41-9497-0E03","temp":23.3},"sensor2":{"id":"28-233D-9497-0C03","temp":24.0}}
|
||||
JsonObject dataSensor = doc.createNestedObject(sensorID);
|
||||
dataSensor["id"] = sensor.to_string();
|
||||
@@ -395,7 +392,7 @@ void DallasSensor::publish_values(const bool force) {
|
||||
config["unit_of_meas"] = FJSON("°C");
|
||||
|
||||
char str[50];
|
||||
if (dallas_format == Mqtt::Dallas_Format::SENSORID) {
|
||||
if (dallas_format_ == Dallas_Format::SENSORID) {
|
||||
snprintf_P(str, sizeof(str), PSTR("{{value_json['%s']}}"), sensor.to_string().c_str());
|
||||
} else {
|
||||
snprintf_P(str, sizeof(str), PSTR("{{value_json.sensor%d.temp}}"), sensor_no);
|
||||
@@ -403,7 +400,7 @@ void DallasSensor::publish_values(const bool force) {
|
||||
config["val_tpl"] = str;
|
||||
|
||||
// name as sensor number not the long unique ID
|
||||
if (dallas_format == Mqtt::Dallas_Format::SENSORID) {
|
||||
if (dallas_format_ == Dallas_Format::SENSORID) {
|
||||
snprintf_P(str, sizeof(str), PSTR("Dallas Sensor %s"), sensor.to_string().c_str());
|
||||
} else {
|
||||
snprintf_P(str, sizeof(str), PSTR("Dallas Sensor %d"), sensor_no);
|
||||
@@ -418,7 +415,7 @@ void DallasSensor::publish_values(const bool force) {
|
||||
ids.add("ems-esp");
|
||||
|
||||
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||
if (dallas_format == Mqtt::Dallas_Format::SENSORID) {
|
||||
if (dallas_format_ == Dallas_Format::SENSORID) {
|
||||
// use '_' as HA doesn't like '-' in the topic name
|
||||
std::string topicname = sensor.to_string();
|
||||
std::replace(topicname.begin(), topicname.end(), '-', '_');
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
enum Dallas_Format : uint8_t { SENSORID = 1, NUMBER, NAME };
|
||||
|
||||
class DallasSensor {
|
||||
public:
|
||||
class Sensor {
|
||||
@@ -76,6 +78,14 @@ class DallasSensor {
|
||||
return (dallas_gpio_ != 0);
|
||||
}
|
||||
|
||||
uint8_t dallas_format() {
|
||||
return dallas_format_;
|
||||
}
|
||||
|
||||
void dallas_format(uint8_t dallas_format) {
|
||||
dallas_format_ = dallas_format;
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr uint8_t MAX_SENSORS = 20;
|
||||
|
||||
@@ -134,6 +144,7 @@ class DallasSensor {
|
||||
uint32_t sensorfails_ = 0;
|
||||
uint32_t sensorreads_ = 0;
|
||||
int8_t scanretry_ = 0;
|
||||
uint8_t dallas_format_ = 0;
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -84,6 +84,10 @@
|
||||
#define EMSESP_DEFAULT_BOOL_FORMAT 1 // on/off
|
||||
#endif
|
||||
|
||||
#ifndef EMSESP_DEFAULT_ENUM_FORMAT
|
||||
#define EMSESP_DEFAULT_ENUM_FORMAT 1 // Text
|
||||
#endif
|
||||
|
||||
#ifndef EMSESP_DEFAULT_ANALOG_ENABLED
|
||||
#define EMSESP_DEFAULT_ANALOG_ENABLED false
|
||||
#endif
|
||||
|
||||
@@ -697,7 +697,7 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t
|
||||
switch (dv.type) {
|
||||
case DeviceValueType::ENUM: {
|
||||
if (*(uint8_t *)(dv.value_p) < dv.options_size) {
|
||||
if (Mqtt::bool_format() == BOOL_FORMAT_10) {
|
||||
if (EMSESP::enum_format() == ENUM_FORMAT_NUMBER) {
|
||||
json[value] = (uint8_t)(*(uint8_t *)(dv.value_p));
|
||||
} else {
|
||||
json[value] = dv.options[*(uint8_t *)(dv.value_p)]; // text
|
||||
@@ -770,7 +770,16 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t
|
||||
|
||||
case DeviceValueType::BOOL: {
|
||||
if (Helpers::hasValue(*(uint8_t *)(dv.value_p), EMS_VALUE_BOOL)) {
|
||||
json[value] = (bool)(*(uint8_t *)(dv.value_p)) ? true : false;
|
||||
uint8_t bool_format = EMSESP::bool_format();
|
||||
if (bool_format == BOOL_FORMAT_ONOFF) {
|
||||
json[value] = (bool)(*(uint8_t *)(dv.value_p)) ? F_(on) : F_(off);
|
||||
} else if (bool_format == BOOL_FORMAT_ONOFF_CAP) {
|
||||
json[value] = (bool)(*(uint8_t *)(dv.value_p)) ? F_(ON) : F_(OFF);
|
||||
} else if (bool_format == BOOL_FORMAT_TRUEFALSE) {
|
||||
json[value] = (bool)(*(uint8_t *)(dv.value_p)) ? true : false;
|
||||
} else {
|
||||
json[value] = (bool)(*(uint8_t *)(dv.value_p)) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
json[type] = F("boolean");
|
||||
break;
|
||||
@@ -858,24 +867,17 @@ bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter
|
||||
if ((dv.type == DeviceValueType::BOOL) && Helpers::hasValue(*(uint8_t *)(dv.value_p), EMS_VALUE_BOOL)) {
|
||||
// see how to render the value depending on the setting
|
||||
// when in console mode we always use on and off
|
||||
if ((Mqtt::bool_format() == BOOL_FORMAT_ONOFF) || console) {
|
||||
// on or off as strings
|
||||
uint8_t bool_format = EMSESP::bool_format();
|
||||
if ((bool_format == BOOL_FORMAT_ONOFF) || console) {
|
||||
json[name] = *(uint8_t *)(dv.value_p) ? F_(on) : F_(off);
|
||||
has_value = true;
|
||||
} else if (Mqtt::bool_format() == BOOL_FORMAT_ONOFF_CAP) {
|
||||
// on or off as strings
|
||||
} else if (bool_format == BOOL_FORMAT_ONOFF_CAP) {
|
||||
json[name] = *(uint8_t *)(dv.value_p) ? F_(ON) : F_(OFF);
|
||||
has_value = true;
|
||||
} else if (Mqtt::bool_format() == BOOL_FORMAT_TRUEFALSE) {
|
||||
// true or false values (as real booleans, not strings)
|
||||
} else if (bool_format == BOOL_FORMAT_TRUEFALSE) {
|
||||
json[name] = (bool)(*(uint8_t *)(dv.value_p)) ? true : false;
|
||||
has_value = true;
|
||||
} else {
|
||||
// numerical 1 or 0
|
||||
json[name] = (uint8_t)(*(uint8_t *)(dv.value_p)) ? 1 : 0;
|
||||
has_value = true;
|
||||
}
|
||||
|
||||
has_value = true;
|
||||
}
|
||||
|
||||
// handle TEXT strings
|
||||
@@ -888,7 +890,7 @@ bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter
|
||||
else if ((dv.type == DeviceValueType::ENUM) && Helpers::hasValue(*(uint8_t *)(dv.value_p))) {
|
||||
if (*(uint8_t *)(dv.value_p) < dv.options_size) {
|
||||
// check for numeric enum-format, but "hamode" always as text
|
||||
if ((Mqtt::bool_format() == BOOL_FORMAT_10) && (dv.short_name != FL_(hamode)[0])) {
|
||||
if ((EMSESP::enum_format() == ENUM_FORMAT_NUMBER) && (dv.short_name != FL_(hamode)[0])) {
|
||||
json[name] = (uint8_t)(*(uint8_t *)(dv.value_p));
|
||||
} else {
|
||||
json[name] = dv.options[*(uint8_t *)(dv.value_p)];
|
||||
|
||||
@@ -75,6 +75,8 @@ uint8_t EMSESP::publish_all_idx_ = 0;
|
||||
uint8_t EMSESP::unique_id_count_ = 0;
|
||||
bool EMSESP::trace_raw_ = false;
|
||||
uint64_t EMSESP::tx_delay_ = 0;
|
||||
uint8_t EMSESP::bool_format_ = 1;
|
||||
uint8_t EMSESP::enum_format_ = 1;
|
||||
|
||||
// for a specific EMS device go and request data values
|
||||
// or if device_id is 0 it will fetch from all our known and active devices
|
||||
|
||||
18
src/emsesp.h
18
src/emsesp.h
@@ -144,6 +144,22 @@ class EMSESP {
|
||||
return (dallassensor_.dallas_enabled());
|
||||
}
|
||||
|
||||
static uint8_t bool_format() {
|
||||
return bool_format_;
|
||||
}
|
||||
|
||||
static void bool_format(uint8_t format) {
|
||||
bool_format_ = format;
|
||||
}
|
||||
|
||||
static uint8_t enum_format() {
|
||||
return enum_format_;
|
||||
}
|
||||
|
||||
static void enum_format(uint8_t format) {
|
||||
enum_format_ = format;
|
||||
}
|
||||
|
||||
enum Watch : uint8_t { WATCH_OFF, WATCH_ON, WATCH_RAW, WATCH_UNKNOWN };
|
||||
static void watch_id(uint16_t id);
|
||||
static uint16_t watch_id() {
|
||||
@@ -246,6 +262,8 @@ class EMSESP {
|
||||
static uint8_t unique_id_count_;
|
||||
static bool trace_raw_;
|
||||
static uint64_t tx_delay_;
|
||||
static uint8_t bool_format_;
|
||||
static uint8_t enum_format_;
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "helpers.h"
|
||||
#include "mqtt.h"
|
||||
#include "emsesp.h"
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
@@ -124,7 +124,7 @@ char * Helpers::smallitoa(char * result, const uint16_t value) {
|
||||
|
||||
// work out how to display booleans
|
||||
char * Helpers::render_boolean(char * result, bool value) {
|
||||
uint8_t bool_format_ = Mqtt::bool_format();
|
||||
uint8_t bool_format_ = EMSESP::bool_format();
|
||||
if (bool_format_ == BOOL_FORMAT_ONOFF) {
|
||||
strlcpy(result, value ? uuid::read_flash_string(F_(on)).c_str() : uuid::read_flash_string(F_(off)).c_str(), 5);
|
||||
} else if (bool_format_ == BOOL_FORMAT_ONOFF_CAP) {
|
||||
|
||||
@@ -35,8 +35,6 @@ uint32_t Mqtt::publish_time_mixer_;
|
||||
uint32_t Mqtt::publish_time_sensor_;
|
||||
uint32_t Mqtt::publish_time_other_;
|
||||
bool Mqtt::mqtt_enabled_;
|
||||
uint8_t Mqtt::dallas_format_;
|
||||
uint8_t Mqtt::bool_format_;
|
||||
uint8_t Mqtt::ha_climate_format_;
|
||||
bool Mqtt::ha_enabled_;
|
||||
uint8_t Mqtt::nested_format_;
|
||||
@@ -485,8 +483,6 @@ void Mqtt::load_settings() {
|
||||
mqtt_enabled_ = mqttSettings.enabled;
|
||||
ha_enabled_ = mqttSettings.ha_enabled;
|
||||
ha_climate_format_ = mqttSettings.ha_climate_format;
|
||||
dallas_format_ = mqttSettings.dallas_format;
|
||||
bool_format_ = mqttSettings.bool_format;
|
||||
nested_format_ = mqttSettings.nested_format;
|
||||
subscribe_format_ = mqttSettings.subscribe_format;
|
||||
|
||||
|
||||
17
src/mqtt.h
17
src/mqtt.h
@@ -44,8 +44,6 @@ using uuid::console::Shell;
|
||||
// size of queue
|
||||
#define MAX_MQTT_MESSAGES 200
|
||||
|
||||
enum { BOOL_FORMAT_ONOFF = 1, BOOL_FORMAT_TRUEFALSE, BOOL_FORMAT_10, BOOL_FORMAT_ONOFF_CAP }; // matches Web UI settings
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
using mqtt_subfunction_p = std::function<bool(const char * message)>;
|
||||
@@ -83,7 +81,6 @@ class Mqtt {
|
||||
|
||||
enum Operation { PUBLISH, SUBSCRIBE };
|
||||
|
||||
enum Dallas_Format : uint8_t { SENSORID = 1, NUMBER };
|
||||
enum HA_Climate_Format : uint8_t { CURRENT = 1, SETPOINT, ZERO };
|
||||
|
||||
static constexpr uint8_t MQTT_TOPIC_MAX_SIZE = 128; // note this should really match the user setting in mqttSettings.maxTopicLength
|
||||
@@ -159,14 +156,6 @@ class Mqtt {
|
||||
return ha_climate_format_;
|
||||
}
|
||||
|
||||
static uint8_t dallas_format() {
|
||||
return dallas_format_;
|
||||
}
|
||||
|
||||
static uint8_t bool_format() {
|
||||
return bool_format_;
|
||||
}
|
||||
|
||||
static uint8_t nested_format() {
|
||||
return nested_format_;
|
||||
}
|
||||
@@ -183,10 +172,6 @@ class Mqtt {
|
||||
ha_climate_format_ = ha_climate_format;
|
||||
}
|
||||
|
||||
static void dallas_format(uint8_t dallas_format) {
|
||||
dallas_format_ = dallas_format;
|
||||
}
|
||||
|
||||
static void ha_enabled(bool ha_enabled) {
|
||||
ha_enabled_ = ha_enabled;
|
||||
}
|
||||
@@ -279,8 +264,6 @@ class Mqtt {
|
||||
static uint32_t publish_time_other_;
|
||||
static uint32_t publish_time_sensor_;
|
||||
static bool mqtt_enabled_;
|
||||
static uint8_t dallas_format_;
|
||||
static uint8_t bool_format_;
|
||||
static uint8_t ha_climate_format_;
|
||||
static bool ha_enabled_;
|
||||
static uint8_t nested_format_;
|
||||
|
||||
@@ -835,8 +835,6 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject &
|
||||
node["publish_time_mixer"] = settings.publish_time_mixer;
|
||||
node["publish_time_other"] = settings.publish_time_other;
|
||||
node["publish_time_sensor"] = settings.publish_time_sensor;
|
||||
node["dallas_format"] = settings.dallas_format;
|
||||
node["bool_format"] = settings.bool_format;
|
||||
node["ha_climate_format"] = settings.ha_climate_format;
|
||||
node["ha_enabled"] = settings.ha_enabled;
|
||||
node["mqtt_qos"] = settings.mqtt_qos;
|
||||
@@ -879,6 +877,9 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject &
|
||||
node["led_gpio"] = settings.led_gpio;
|
||||
node["hide_led"] = settings.hide_led;
|
||||
node["notoken_api"] = settings.notoken_api;
|
||||
node["dallas_format"] = settings.dallas_format;
|
||||
node["bool_format"] = settings.bool_format;
|
||||
node["enum_format"] = settings.enum_format;
|
||||
node["analog_enabled"] = settings.analog_enabled;
|
||||
node["pbutton_gpio"] = settings.pbutton_gpio;
|
||||
node["board_profile"] = settings.board_profile;
|
||||
|
||||
@@ -61,6 +61,9 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
|
||||
root["pbutton_gpio"] = settings.pbutton_gpio;
|
||||
root["solar_maxflow"] = settings.solar_maxflow;
|
||||
root["board_profile"] = settings.board_profile;
|
||||
root["dallas_format"] = settings.dallas_format;
|
||||
root["bool_format"] = settings.bool_format;
|
||||
root["enum_format"] = settings.enum_format;
|
||||
}
|
||||
|
||||
// call on initialization and also when settings are updated via web or console
|
||||
@@ -173,6 +176,15 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
|
||||
settings.notoken_api = root["notoken_api"] | EMSESP_DEFAULT_NOTOKEN_API;
|
||||
settings.solar_maxflow = root["solar_maxflow"] | EMSESP_DEFAULT_SOLAR_MAXFLOW;
|
||||
|
||||
settings.dallas_format = root["dallas_format"] | EMSESP_DEFAULT_DALLAS_FORMAT;
|
||||
EMSESP::dallassensor_.dallas_format(settings.dallas_format);
|
||||
|
||||
settings.bool_format = root["bool_format"] | EMSESP_DEFAULT_BOOL_FORMAT;
|
||||
EMSESP::bool_format(settings.bool_format);
|
||||
|
||||
settings.enum_format = root["enum_format"] | EMSESP_DEFAULT_ENUM_FORMAT;
|
||||
EMSESP::enum_format(settings.enum_format);
|
||||
|
||||
return StateUpdateResult::CHANGED;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
enum { BOOL_FORMAT_ONOFF = 1, BOOL_FORMAT_ONOFF_CAP, BOOL_FORMAT_TRUEFALSE, BOOL_FORMAT_10 }; // matches Web UI settings
|
||||
enum { ENUM_FORMAT_TEXT = 1, ENUM_FORMAT_NUMBER }; // matches Web UI settings
|
||||
|
||||
class WebSettings {
|
||||
public:
|
||||
uint8_t tx_mode;
|
||||
@@ -56,6 +59,9 @@ class WebSettings {
|
||||
uint8_t pbutton_gpio;
|
||||
uint8_t solar_maxflow;
|
||||
String board_profile;
|
||||
uint8_t dallas_format;
|
||||
uint8_t bool_format;
|
||||
uint8_t enum_format;
|
||||
|
||||
static void read(WebSettings & settings, JsonObject & root);
|
||||
static StateUpdateResult update(JsonObject & root, WebSettings & settings);
|
||||
|
||||
Reference in New Issue
Block a user