aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-11-29 16:52:27 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-11-29 16:52:27 +0300
commit6003eaa6756b7f97ff5c41fb3bc62cc63fcc4648 (patch)
treed1cc5a9b0564bad1d07d4614f93ae95f085c5a53 /src
parentd74a2a3e78a631aa46ec6c1d6049a04d4bd5a4ba (diff)
p18/get-p-status: don't output max_temp if inverter doesn't return it
Diffstat (limited to 'src')
-rw-r--r--src/formatter/formatter.h4
-rw-r--r--src/p18/response.cc17
-rw-r--r--src/p18/response.h2
3 files changed, 19 insertions, 4 deletions
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<TableItem<T>> v)
: Formattable(format), v_(v) {}
+ void push(TableItem<T> 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<BatteryPowerDirection>(stou(list[25]));
dc_ac_power_direction = static_cast<DC_AC_PowerDirection>(stou(list[26]));
line_power_direction = static_cast<LinePowerDirection>(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<VariantHolder>(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<formatter::Table<VariantHolder>>(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 */
};