From 6003eaa6756b7f97ff5c41fb3bc62cc63fcc4648 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Mon, 29 Nov 2021 16:52:27 +0300 Subject: p18/get-p-status: don't output max_temp if inverter doesn't return it --- src/formatter/formatter.h | 4 ++++ src/p18/response.cc | 17 +++++++++++++---- src/p18/response.h | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/formatter/formatter.h b/src/formatter/formatter.h index 2ffa9b2..d9d5629 100644 --- a/src/formatter/formatter.h +++ b/src/formatter/formatter.h @@ -127,6 +127,10 @@ public: explicit Table(Format format, std::vector> v) : Formattable(format), v_(v) {} + void push(TableItem item) { + v_.push_back(item); + } + std::ostream& writeSimpleTable(std::ostream& os) const override { for (const auto& item: v_) { os << item.key << " "; diff --git a/src/p18/response.cc b/src/p18/response.cc index 453272c..e2cd9f4 100644 --- a/src/p18/response.cc +++ b/src/p18/response.cc @@ -742,12 +742,14 @@ void ParallelGeneralStatus::unpack() { battery_power_direction = static_cast(stou(list[25])); dc_ac_power_direction = static_cast(stou(list[26])); line_power_direction = static_cast(stou(list[27])); - if (list.size() >= 29) + if (list.size() >= 29) { + max_temp_present = true; max_temp = stou(list[28]); + } } formattable_ptr ParallelGeneralStatus::format(formatter::Format format) { - RETURN_TABLE({ + auto table = new formatter::Table(format, { LINE("parallel_id_connection_status", "Parallel ID connection status", parallel_id_connection_status), LINE("mode", "Working mode", work_mode), LINE("fault_code", "Fault code", fault_code), @@ -774,8 +776,15 @@ formattable_ptr ParallelGeneralStatus::format(formatter::Format format) { LINE("battery_power_direction", "Battery power direction", battery_power_direction), LINE("dc_ac_power_direction", "DC/AC power direction", dc_ac_power_direction), LINE("line_power_direction", "Line power direction", line_power_direction), - LINE("max_temp", "Max. temperature", max_temp), - }) + }); + + if (max_temp_present) { + table->push( + LINE("max_temp", "Max. temperature", max_temp) + ); + } + + return std::shared_ptr>(table); } diff --git a/src/p18/response.h b/src/p18/response.h index 42b84b8..3ffc6d4 100644 --- a/src/p18/response.h +++ b/src/p18/response.h @@ -484,6 +484,8 @@ public: p18::BatteryPowerDirection battery_power_direction; p18::DC_AC_PowerDirection dc_ac_power_direction; p18::LinePowerDirection line_power_direction; + + bool max_temp_present = false; unsigned max_temp; /* unit: C */ }; -- cgit v1.2.3