Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
markirb committed Oct 15, 2024
1 parent 171a6ef commit da38303
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions fs_src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,8 @@ <h1 id="head">Sensor</h1>
<input type="number" id="update_interval" min="1" max="1000" class="short"><span>&nbsp; s</span>
</div>
<div class="form-control">
<label for="offset">Offset (for calibration):</label>
<input type="text" id="offset">
<label for="offset">Offset:</label>
<input type="text" id="offset" class="short">
</div>
<div class="button-container">
<button id="save_btn">
Expand Down
4 changes: 2 additions & 2 deletions fs_src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ function tsSetConfig(c) {
name: name,
unit: parseInt(el(c, "unit").value),
update_interval: parseInt(el(c, "update_interval").value),
offset: parseFloat(el(c, "offset").value),
offset: Math.round(parseFloat(el(c, "offset").value * 100)),
};
setComponentConfig(c, cfg, el(c, "save_spinner"));
}
Expand Down Expand Up @@ -795,7 +795,7 @@ function updateComponent(cd) {
updateInnerText(el(c, "value"), v);
selectIfNotModified(el(c, "unit"), cd.unit);
setValueIfNotModified(el(c, "update_interval"), cd.update_interval);
setValueIfNotModified(el(c, "offset"), cd.offset);
setValueIfNotModified(el(c, "offset"), cd.offset / 100.0);
break;
}
case Component_Type.kStatelessSwitch:
Expand Down
2 changes: 1 addition & 1 deletion mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ config_schema:
- ["ts.name", "s", "", {title: "Name of the sensor"}]
- ["ts.unit", "i", 0, {title: "Display unit of the Sensor"}] # 0 - Celsius, 1 - Farenheit
- ["ts.update_interval", "i", 1, {title: "Update Interval of the sensor in seconds, minimum 1s"}]
- ["ts.offset", "f", 0, {title: "Offset value can be used for calibration"}]
- ["ts.offset", "i", 0, {title: "Offset value can be used for calibration in unit*100 e.g. centigrade"}]

- ["sw", "o", {title: "Switch settings", abstract: true}]
- ["sw.name", "s", "", {title: "Name of the switch"}]
Expand Down
2 changes: 1 addition & 1 deletion src/shelly_hap_garage_door_opener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ void CreateHAPGDO(int id, Input *in_close, Input *in_open, Output *out_close,
Output *out_open, const struct mgos_config_gdo *gdo_cfg,
std::vector<std::unique_ptr<Component>> *comps,
std::vector<std::unique_ptr<mgos::hap::Accessory>> *accs,
HAPAccessoryServerRef *svr, bool to_pri_acc) {
HAPAccessoryServerRef *svr UNUSED_ARG, bool to_pri_acc) {
struct mgos_config_gdo *gdo2_cfg = (struct mgos_config_gdo *) gdo_cfg;

if (gdo_cfg->sensor_swap) {
Expand Down
8 changes: 4 additions & 4 deletions src/shelly_hap_humidity_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Status HumiditySensor::SetConfig(const std::string &config_json,
struct mgos_config_ts cfg = *cfg_;
cfg.name = nullptr;
json_scanf(config_json.c_str(), config_json.size(),
"{name: %Q, unit: %d, update_interval: %d, offset: %f}", &cfg.name,
"{name: %Q, unit: %d, update_interval: %d, offset: %d", &cfg.name,
&cfg.unit, &cfg.update_interval, &cfg.offset);

mgos::ScopedCPtr name_owner((void *) cfg.name);
Expand Down Expand Up @@ -118,7 +118,7 @@ Status HumiditySensor::Init() {
return kHAPError_Busy;
}
float temp = static_cast<float>(tempval.ValueOrDie());
*value = truncf((temp + cfg_->offset) * 10) / 10;
*value = truncf((temp + cfg_->offset / 100) * 10) / 10;
return kHAPError_None;
},

Expand All @@ -141,11 +141,11 @@ StatusOr<std::string> HumiditySensor::GetInfo() const {
StatusOr<std::string> HumiditySensor::GetInfoJSON() const {
std::string res = mgos::JSONPrintStringf(
"{id: %d, type: %d, name: %Q, unit: %d, "
"update_interval: %d, offset: %f, ",
"update_interval: %d, offset: %d, ",
id(), type(), cfg_->name, 2, cfg_->update_interval, cfg_->offset);
auto tempval = hum_sensor_->GetHumidity();
if (tempval.ok()) {
mgos::JSONAppendStringf(&res, "value: %.1f", tempval.ValueOrDie());
mgos::JSONAppendStringf(&res, "value: %.1f", tempval.ValueOrDie() + cfg_->offset / 100);
} else {
mgos::JSONAppendStringf(&res, "error: %.1f", tempval.ValueOrDie());
}
Expand Down
8 changes: 4 additions & 4 deletions src/shelly_hap_temperature_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Status TemperatureSensor::SetConfig(const std::string &config_json,
struct mgos_config_ts cfg = *cfg_;
cfg.name = nullptr;
json_scanf(config_json.c_str(), config_json.size(),
"{name: %Q, unit: %d, update_interval: %d, offset: %f}", &cfg.name,
"{name: %Q, unit: %d, update_interval: %d, offset: %d", &cfg.name,
&cfg.unit, &cfg.update_interval, &cfg.offset);

mgos::ScopedCPtr name_owner((void *) cfg.name);
Expand Down Expand Up @@ -116,7 +116,7 @@ Status TemperatureSensor::Init() {
return kHAPError_Busy;
}
float temp = static_cast<float>(tempval.ValueOrDie());
*value = truncf((temp + cfg_->offset) * 10) / 10;
*value = truncf((temp + cfg_->offset / 100) * 10) / 10;
return kHAPError_None;
},

Expand Down Expand Up @@ -152,13 +152,13 @@ StatusOr<std::string> TemperatureSensor::GetInfo() const {
StatusOr<std::string> TemperatureSensor::GetInfoJSON() const {
std::string res = mgos::JSONPrintStringf(
"{id: %d, type: %d, name: %Q, unit: %d, "
"update_interval: %d, offset: %f",
"update_interval: %d, offset: %d, ",
id(), type(), cfg_->name, cfg_->unit, cfg_->update_interval,
cfg_->offset);
auto tempval = temp_sensor_->GetTemperature();
if (tempval.ok()) {
mgos::JSONAppendStringf(&res, "value: %.1f",
tempval.ValueOrDie() + cfg_->offset);
tempval.ValueOrDie() + cfg_->offset / 100);
} else {
mgos::JSONAppendStringf(&res, "error: %.1f", tempval.ValueOrDie());
}
Expand Down

0 comments on commit da38303

Please sign in to comment.