Skip to content

Commit

Permalink
ThermHygroMeter (and all thermometers): add setApplyCorrections method
Browse files Browse the repository at this point in the history
  which disables applying corrections on SD side.
  • Loading branch information
klew committed Dec 31, 2024
1 parent 64a3226 commit f3e87d1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/supla/sensor/therm_hygro_meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,21 @@ void Supla::Sensor::ThermHygroMeter::onLoadConfig(SuplaDeviceClass *sdc) {
return;
}

// set temperature correction
auto cfgTempCorrection = getConfiguredTemperatureCorrection();
double correction = 1.0 * cfgTempCorrection / 10.0;
getChannel()->setCorrection(correction);
SUPLA_LOG_DEBUG("Channel[%d] temperature correction %.2f",
getChannelNumber(), correction);

// set humidity correction
auto cfgHumCorrection = getConfiguredHumidityCorrection();
correction = 1.0 * cfgHumCorrection / 10.0;
getChannel()->setCorrection(correction, true);
SUPLA_LOG_DEBUG("Channel[%d] humidity correction %.2f",
getChannelNumber(), correction);
if (applyCorrections) {
// set temperature correction
auto cfgTempCorrection = getConfiguredTemperatureCorrection();
double correction = 1.0 * cfgTempCorrection / 10.0;
getChannel()->setCorrection(correction);
SUPLA_LOG_DEBUG("Channel[%d] temperature correction %.2f",
getChannelNumber(), correction);

// set humidity correction
auto cfgHumCorrection = getConfiguredHumidityCorrection();
correction = 1.0 * cfgHumCorrection / 10.0;
getChannel()->setCorrection(correction, true);
SUPLA_LOG_DEBUG("Channel[%d] humidity correction %.2f",
getChannelNumber(), correction);
}

// load config changed offline flags
loadConfigChangeFlag();
Expand Down Expand Up @@ -269,3 +271,7 @@ void Supla::Sensor::ThermHygroMeter::fillChannelConfig(void *channelConfig,
config->AdjustmentAppliedByDevice = 1;
}

void Supla::Sensor::ThermHygroMeter::setApplyCorrections(
bool applyCorrections) {
this->applyCorrections = applyCorrections;
}
11 changes: 11 additions & 0 deletions src/supla/sensor/therm_hygro_meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ class ThermHygroMeter : public ChannelElement {
int32_t humidityCorrection,
bool local = false);

// By default temperature and humidity corrections are applied on Channel
// level, so raw value is read from sensor, then it is corrected and
// send to server.
// However correction may be applied by a sensor device itself. In this
// case, correciton is send to that device and value read from sensor is
// already corrected.
//
// This function sets whether correction should be applied or not.
void setApplyCorrections(bool applyCorrections);

protected:
int16_t readCorrectionFromIndex(int index);
void setCorrectionAtIndex(int32_t correction, int index);
Expand All @@ -60,6 +70,7 @@ class ThermHygroMeter : public ChannelElement {

uint32_t lastReadTime = 0;
uint16_t refreshIntervalMs = 10000;
bool applyCorrections = true;
};

}; // namespace Sensor
Expand Down

0 comments on commit f3e87d1

Please sign in to comment.