diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index 5ea7dffac..147440e82 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -89,7 +89,7 @@ void AnalogSensor::reload() { it++; } // add new sensors from list - for (auto & sensor : sensors) { + for (auto & sensor : sensors) { bool found = false; for (auto & sensor_ : sensors_) { if (sensor_.id() == sensor.id) { @@ -229,7 +229,7 @@ void AnalogSensor::measure() { } else if (!sensor.poll_) { // falling edge if (sensor.type() == AnalogType::COUNTER) { sensor.set_value(old_value + sensor.factor()); - } else if (sensor.type() == AnalogType::RATE) { // dafault uom: Hz (1/sec) with factor 1 + } else if (sensor.type() == AnalogType::RATE) { // dafault uom: Hz (1/sec) with factor 1 sensor.set_value(sensor.factor() * 1000 / (sensor.polltime_ - sensor.last_polltime_)); } else if (sensor.type() == AnalogType::TIMER) { // default seconds with factor 1 sensor.set_value(sensor.factor() * (sensor.polltime_ - sensor.last_polltime_) / 1000); diff --git a/src/dallassensor.cpp b/src/dallassensor.cpp index fe7846a5b..d8e9722ba 100644 --- a/src/dallassensor.cpp +++ b/src/dallassensor.cpp @@ -361,10 +361,10 @@ bool DallasSensor::command_info(const char * value, const int8_t id, JsonObject JsonObject dataSensor = output.createNestedObject(sensor.name()); dataSensor["id_str"] = sensor.id_str(); if (Helpers::hasValue(sensor.temperature_c)) { - dataSensor["temp"] = (float)(sensor.temperature_c) / 10; + dataSensor["temp"] = Helpers::round2((float)(sensor.temperature_c), 10, EMSESP::system_.fahrenheit() ? 2 : 0); } } else if (Helpers::hasValue(sensor.temperature_c)) { - output[sensor.name()] = (float)(sensor.temperature_c) / 10; + output[sensor.name()] = Helpers::round2((float)(sensor.temperature_c), 10, EMSESP::system_.fahrenheit() ? 2 : 0); } } @@ -378,11 +378,11 @@ bool DallasSensor::get_value_info(JsonObject & output, const char * cmd, const i output["id_str"] = sensor.id_str(); output["name"] = sensor.name(); if (Helpers::hasValue(sensor.temperature_c)) { - output["value"] = (float)(sensor.temperature_c) / 10; + output["value"] = Helpers::round2((float)(sensor.temperature_c), 10, EMSESP::system_.fahrenheit() ? 2 : 0); } output["type"] = F_(number); - output["min"] = -55; - output["max"] = 125; + output["min"] = Helpers::round2(-55, 0, EMSESP::system_.fahrenheit() ? 2 : 0); + output["max"] = Helpers::round2(125, 0, EMSESP::system_.fahrenheit() ? 2 : 0); output["unit"] = EMSdevice::uom_to_string(DeviceValueUOM::DEGREES); output["writeable"] = false; return true; @@ -444,10 +444,10 @@ void DallasSensor::publish_values(const bool force) { JsonObject dataSensor = doc.createNestedObject(sensor.id_str()); dataSensor["name"] = sensor.name(); if (has_value) { - dataSensor["temp"] = (float)(sensor.temperature_c) / 10; + dataSensor["temp"] = Helpers::round2((float)(sensor.temperature_c), 10, EMSESP::system_.fahrenheit() ? 2 : 0); } } else if (has_value) { - doc[sensor.name()] = (float)(sensor.temperature_c) / 10; + doc[sensor.name()] = Helpers::round2((float)(sensor.temperature_c), 10, EMSESP::system_.fahrenheit() ? 2 : 0); } // create the HA MQTT config @@ -463,11 +463,7 @@ void DallasSensor::publish_values(const bool force) { snprintf(stat_t, sizeof(stat_t), "%s/dallassensor_data", Mqtt::base().c_str()); config["stat_t"] = stat_t; - if (EMSESP::system_.fahrenheit()) { - config["unit_of_meas"] = FJSON("°F"); - } else { - config["unit_of_meas"] = FJSON("°C"); - } + config["unit_of_meas"] = EMSdevice::uom_to_string(DeviceValueUOM::DEGREES); char str[50]; snprintf(str, sizeof(str), "{{value_json['%s'].temp}}", sensor.id_str().c_str()); diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 0306e4b10..17a0f4434 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -52,6 +52,9 @@ const std::string EMSdevice::tag_to_mqtt(uint8_t tag) { } const std::string EMSdevice::uom_to_string(uint8_t uom) { + if (EMSESP::system_.fahrenheit() && (uom == DeviceValueUOM::DEGREES || uom == DeviceValueUOM::DEGREES_R)) { + return read_flash_string(DeviceValue::DeviceValueUOM_s[DeviceValueUOM::FAHRENHEIT]); + } return read_flash_string(DeviceValue::DeviceValueUOM_s[uom]); } @@ -306,11 +309,7 @@ void EMSdevice::list_device_entries(JsonObject & output) { // add uom if (!uom_to_string(dv.uom).empty() && uom_to_string(dv.uom) != " ") { - if (EMSESP::system_.fahrenheit() && (dv.uom == DeviceValueUOM::DEGREES || dv.uom == DeviceValueUOM::DEGREES_R)) { - details.add(EMSdevice::uom_to_string(DeviceValueUOM::FAHRENHEIT)); - } else { - details.add(EMSdevice::uom_to_string(dv.uom)); - } + details.add(EMSdevice::uom_to_string(dv.uom)); } } } @@ -1024,7 +1023,7 @@ bool EMSdevice::get_value_info(JsonObject & output, const char * cmd, const int8 // add uom if it's not a " " (single space) if (!uom_to_string(dv.uom).empty() && uom_to_string(dv.uom) != " ") { - json["uom"] = fahrenheit ? "°F" : uom_to_string(dv.uom); + json["uom"] = uom_to_string(dv.uom); } json["writeable"] = dv.has_cmd;