Skip to content

Commit a2071de

Browse files
committed
offset: allow decimals
1 parent 83f1376 commit a2071de

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

fs_src/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ function tsSetConfig(c) {
440440
name: name,
441441
unit: parseInt(el(c, "unit").value),
442442
update_interval: parseInt(el(c, "update_interval").value),
443-
offset: Math.round(parseFloat(el(c, "offset").value * 100)),
443+
offset: Math.round(parseFloat(el(c, "offset").value) * 100),
444444
};
445445
setComponentConfig(c, cfg, el(c, "save_spinner"));
446446
}

src/shelly_hap_humidity_sensor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Status HumiditySensor::Init() {
117117
return kHAPError_Busy;
118118
}
119119
float temp = static_cast<float>(tempval.ValueOrDie());
120-
*value = truncf((temp + cfg_->offset / 100) * 10) / 10;
120+
*value = truncf((temp + cfg_->offset / 100.0) * 10) / 10;
121121
return kHAPError_None;
122122
},
123123

@@ -144,7 +144,7 @@ StatusOr<std::string> HumiditySensor::GetInfoJSON() const {
144144
auto tempval = hum_sensor_->GetHumidity();
145145
if (tempval.ok()) {
146146
mgos::JSONAppendStringf(&res, "value: %.1f",
147-
tempval.ValueOrDie() + cfg_->offset / 100);
147+
tempval.ValueOrDie() + cfg_->offset / 100.0);
148148
} else {
149149
mgos::JSONAppendStringf(&res, "error: %.1f", tempval.ValueOrDie());
150150
}

src/shelly_hap_temperature_sensor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Status TemperatureSensor::Init() {
116116
return kHAPError_Busy;
117117
}
118118
float temp = static_cast<float>(tempval.ValueOrDie());
119-
*value = truncf((temp + cfg_->offset / 100) * 10) / 10;
119+
*value = truncf((temp + cfg_->offset / 100.0) * 10) / 10;
120120
return kHAPError_None;
121121
},
122122

@@ -158,7 +158,7 @@ StatusOr<std::string> TemperatureSensor::GetInfoJSON() const {
158158
auto tempval = temp_sensor_->GetTemperature();
159159
if (tempval.ok()) {
160160
mgos::JSONAppendStringf(&res, "value: %.1f",
161-
tempval.ValueOrDie() + cfg_->offset / 100);
161+
tempval.ValueOrDie() + cfg_->offset / 100.0);
162162
} else {
163163
mgos::JSONAppendStringf(&res, "error: %.1f", tempval.ValueOrDie());
164164
}

0 commit comments

Comments
 (0)