Skip to content

Commit 1bdf08c

Browse files
fix powermeter.power_W is optional
Signed-off-by: Cornelius Claussen <cc@pionix.de>
1 parent 576601b commit 1bdf08c

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

modules/API/API.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ void API::init() {
167167
evse->subscribe_powermeter([this, var_powermeter, &session_info](types::powermeter::Powermeter powermeter) {
168168
json powermeter_json = powermeter;
169169
this->mqtt.publish(var_powermeter, powermeter_json.dump());
170-
session_info->set_latest_energy_wh(powermeter_json.at("energy_Wh_import").at("total"));
171-
session_info->set_latest_total_w(powermeter_json.at("power_W").at("total"));
170+
session_info->set_latest_energy_wh(powermeter.energy_Wh_import.total);
171+
if (powermeter.power_W.has_value())
172+
session_info->set_latest_total_w(powermeter.power_W.value().total);
172173
});
173174

174175
std::string var_limits = var_base + "limits";
@@ -270,17 +271,16 @@ void API::init() {
270271
});
271272
}
272273

273-
this->api_threads.push_back(
274-
std::thread([this, var_connectors, connectors]() {
275-
auto next_tick = std::chrono::steady_clock::now();
276-
while (this->running) {
277-
json connectors_array = connectors;
278-
this->mqtt.publish(var_connectors, connectors_array.dump());
274+
this->api_threads.push_back(std::thread([this, var_connectors, connectors]() {
275+
auto next_tick = std::chrono::steady_clock::now();
276+
while (this->running) {
277+
json connectors_array = connectors;
278+
this->mqtt.publish(var_connectors, connectors_array.dump());
279279

280-
next_tick += NOTIFICATION_PERIOD;
281-
std::this_thread::sleep_until(next_tick);
282-
}
283-
}));
280+
next_tick += NOTIFICATION_PERIOD;
281+
std::this_thread::sleep_until(next_tick);
282+
}
283+
}));
284284
}
285285

286286
void API::ready() {

0 commit comments

Comments
 (0)