analogsensor float->double #789

This commit is contained in:
MichaelDvP
2022-12-05 18:26:18 +01:00
parent 0c9d0a4d15
commit 3878a3ee0b
7 changed files with 27 additions and 27 deletions

View File

@@ -2,6 +2,11 @@
# [3.5.0] # [3.5.0]
## **IMPORTANT! BREAKING CHANGES**
- When upgrading to v3.5 for the first time from v3.4 on a BBQKees Gateway board you will need to use the [EMS-EPS Flasher](https://github.com/emsesp/EMS-ESP-Flasher/releases) to correctly re-partition the flash. Make sure you backup the settings and customizations from the WebUI (System->Upload/Download) and restore after the upgrade.
- Since 3.5.0b11 we added support for multiple EMS-ESPs [#759] so they can co-exist with MQTT Discovery. The mqtt base is now included in each of the entity names to make them unique. Unfortunately this means in Home Assistant the entity IDs have also been renamed (for example from `number.boiler_burnminperiod` to `number.ems_esp_boiler_burnminperiod`) and any dashboards and automation scripts need to be adjusted accordingly.
## Added ## Added
- Translations in Web UI and all device entity names (DE, NL, SE, PL, NO) [#22](https://github.com/emsesp/EMS-ESP32/issues/22) - Translations in Web UI and all device entity names (DE, NL, SE, PL, NO) [#22](https://github.com/emsesp/EMS-ESP32/issues/22)
@@ -35,8 +40,3 @@
- analog/dallas values command as list like ems-devices - analog/dallas values command as list like ems-devices
- analog/dallas HA-entities based on id - analog/dallas HA-entities based on id
- MQTT Base is a mandatory field. Removed MQTT topic length from settings. - MQTT Base is a mandatory field. Removed MQTT topic length from settings.
## **BREAKING CHANGES:**
- When upgrading for the first time from 3.4.x on a BBQKees Gateway board you will need to use the [EMS-EPS Flasher](https://github.com/emsesp/EMS-ESP-Flasher/releases). Make sure you make a backup of the settings and customizations via the WebUI (System->Upload/Download).
- Because of #759 the Home Assistant entity IDs have been renamed

View File

@@ -296,7 +296,7 @@ void AnalogSensor::loop() {
} }
// update analog information name and offset // update analog information name and offset
bool AnalogSensor::update(uint8_t gpio, const std::string & name, float offset, float factor, uint8_t uom, int8_t type) { bool AnalogSensor::update(uint8_t gpio, const std::string & name, double offset, double factor, uint8_t uom, int8_t type) {
boolean found_sensor = false; // see if we can find the sensor in our customization list boolean found_sensor = false; // see if we can find the sensor in our customization list
EMSESP::webCustomizationService.update( EMSESP::webCustomizationService.update(
@@ -375,7 +375,7 @@ void AnalogSensor::publish_sensor(const Sensor & sensor) const {
snprintf(topic, sizeof(topic), "%s%s/%s", F_(analogsensor), "_data", sensor.name().c_str()); snprintf(topic, sizeof(topic), "%s%s/%s", F_(analogsensor), "_data", sensor.name().c_str());
} }
char payload[10]; char payload[10];
Mqtt::publish(topic, Helpers::render_value(payload, sensor.value(), 2)); // always publish as floats Mqtt::publish(topic, Helpers::render_value(payload, sensor.value(), 2)); // always publish as doubles
} }
} }
@@ -422,7 +422,7 @@ void AnalogSensor::publish_values(const bool force) {
case AnalogType::PWM_0: case AnalogType::PWM_0:
case AnalogType::PWM_1: case AnalogType::PWM_1:
case AnalogType::PWM_2: case AnalogType::PWM_2:
dataSensor["value"] = serialized(Helpers::render_value(s, sensor.value(), 2)); // float dataSensor["value"] = serialized(Helpers::render_value(s, sensor.value(), 2)); // double
break; break;
default: default:
dataSensor["value"] = (uint8_t)sensor.value(); // convert to char for 1 or 0 dataSensor["value"] = (uint8_t)sensor.value(); // convert to char for 1 or 0
@@ -581,7 +581,7 @@ bool AnalogSensor::command_info(const char * value, const int8_t id, JsonObject
} }
// this creates the sensor, initializing everything // this creates the sensor, initializing everything
AnalogSensor::Sensor::Sensor(const uint8_t gpio, const std::string & name, const float offset, const float factor, const uint8_t uom, const int8_t type) AnalogSensor::Sensor::Sensor(const uint8_t gpio, const std::string & name, const double offset, const double factor, const uint8_t uom, const int8_t type)
: gpio_(gpio) : gpio_(gpio)
, name_(name) , name_(name)
, offset_(offset) , offset_(offset)

View File

@@ -35,10 +35,10 @@ class AnalogSensor {
public: public:
class Sensor { class Sensor {
public: public:
Sensor(const uint8_t gpio, const std::string & name, const float offset, const float factor, const uint8_t uom, const int8_t type); Sensor(const uint8_t gpio, const std::string & name, const double offset, const double factor, const uint8_t uom, const int8_t type);
~Sensor() = default; ~Sensor() = default;
void set_offset(const float offset) { void set_offset(const double offset) {
offset_ = offset; offset_ = offset;
} }
@@ -52,23 +52,23 @@ class AnalogSensor {
return gpio_; return gpio_;
} }
float value() const { double value() const {
return value_; return value_;
} }
void set_value(float value) { void set_value(const double value) {
value_ = value; value_ = value;
} }
float factor() const { double factor() const {
return factor_; return factor_;
} }
void set_factor(float factor) { void set_factor(const double factor) {
factor_ = factor; factor_ = factor;
} }
float offset() const { double offset() const {
return offset_; return offset_;
} }
@@ -84,7 +84,7 @@ class AnalogSensor {
return type_; return type_;
} }
void set_type(int8_t type) { void set_type(const int8_t type) {
type_ = type; type_ = type;
} }
@@ -101,10 +101,10 @@ class AnalogSensor {
private: private:
uint8_t gpio_; uint8_t gpio_;
std::string name_; std::string name_;
float offset_; double offset_;
float factor_; double factor_;
uint8_t uom_; uint8_t uom_;
float value_; // float because of the factor is a float double value_; // double because of the factor is a double
int8_t type_; int8_t type_;
}; };
@@ -157,7 +157,7 @@ class AnalogSensor {
return sensors_.size(); return sensors_.size();
} }
bool update(uint8_t gpio, const std::string & name, float offset, float factor, uint8_t uom, int8_t type); bool update(uint8_t gpio, const std::string & name, double offset, double factor, uint8_t uom, int8_t type);
bool get_value_info(JsonObject & output, const char * cmd, const int8_t id) const; bool get_value_info(JsonObject & output, const char * cmd, const int8_t id) const;
#ifdef EMSESP_DEBUG #ifdef EMSESP_DEBUG

View File

@@ -244,7 +244,7 @@ char * Helpers::render_value(char * result, uint8_t value, int8_t format, const
// float: convert float to char // float: convert float to char
// format is the precision, 0 to 8 // format is the precision, 0 to 8
char * Helpers::render_value(char * result, const float value, const int8_t format) { char * Helpers::render_value(char * result, const double value, const int8_t format) {
if (format > 8) { if (format > 8) {
return nullptr; return nullptr;
} }

View File

@@ -27,7 +27,7 @@ namespace emsesp {
class Helpers { class Helpers {
public: public:
static char * render_value(char * result, const float value, const int8_t format); // format is the precision static char * render_value(char * result, const double value, const int8_t format); // format is the precision
static char * render_value(char * result, const uint8_t value, const int8_t format, const uint8_t fahrenheit = 0); static char * render_value(char * result, const uint8_t value, const int8_t format, const uint8_t fahrenheit = 0);
static char * render_value(char * result, const int8_t value, const int8_t format, const uint8_t fahrenheit = 0); static char * render_value(char * result, const int8_t value, const int8_t format, const uint8_t fahrenheit = 0);
static char * render_value(char * result, const uint16_t value, const int8_t format, const uint8_t fahrenheit = 0); static char * render_value(char * result, const uint16_t value, const int8_t format, const uint8_t fahrenheit = 0);

View File

@@ -44,8 +44,8 @@ class AnalogCustomization {
public: public:
uint8_t gpio; uint8_t gpio;
std::string name; std::string name;
float offset; double offset;
float factor; double factor;
uint8_t uom; // 0 is none uint8_t uom; // 0 is none
int8_t type; // -1 is for deletion int8_t type; // -1 is for deletion

View File

@@ -284,8 +284,8 @@ void WebDataService::write_analog(AsyncWebServerRequest * request, JsonVariant &
uint8_t gpio = analog["gpio"]; // this is the unique key, the GPIO uint8_t gpio = analog["gpio"]; // this is the unique key, the GPIO
std::string name = analog["name"]; std::string name = analog["name"];
float factor = analog["factor"]; double factor = analog["factor"];
float offset = analog["offset"]; double offset = analog["offset"];
uint8_t uom = analog["uom"]; uint8_t uom = analog["uom"];
int8_t type = analog["type"]; int8_t type = analog["type"];
ok = EMSESP::analogsensor_.update(gpio, name, offset, factor, uom, type); ok = EMSESP::analogsensor_.update(gpio, name, offset, factor, uom, type);