diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-05-07 03:37:53 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-05-07 03:37:53 +0300 |
commit | cb499d4f015d4a9cd252133a3b3f6a52de333255 (patch) | |
tree | 7049e1142e3bab73eb1b72839905710449baf038 /src | |
parent | 8029b8113b0a4209c29bbafde8a282a9b85cf373 (diff) |
fix json representation of enum values
Diffstat (limited to 'src')
-rw-r--r-- | src/p18/response.h | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/p18/response.h b/src/p18/response.h index f9585d3..9dfebb1 100644 --- a/src/p18/response.h +++ b/src/p18/response.h @@ -82,9 +82,29 @@ public: inline json toJSON() const { json j; - std::visit([&j](const auto& elem) { - j = elem; + bool isEnum = + std::holds_alternative<p18::BatteryType>(v_) || + std::holds_alternative<p18::BatteryPowerDirection>(v_) || + std::holds_alternative<p18::ChargerSourcePriority>(v_) || + std::holds_alternative<p18::DC_AC_PowerDirection>(v_) || + std::holds_alternative<p18::InputVoltageRange>(v_) || + std::holds_alternative<p18::LinePowerDirection>(v_) || + std::holds_alternative<p18::MachineType>(v_) || + std::holds_alternative<p18::MPPTChargerStatus>(v_) || + std::holds_alternative<p18::Topology>(v_) || + std::holds_alternative<p18::OutputSourcePriority>(v_) || + std::holds_alternative<p18::OutputModelSetting>(v_) || + std::holds_alternative<p18::ParallelConnectionStatus>(v_) || + std::holds_alternative<p18::SolarPowerPriority>(v_) || + std::holds_alternative<p18::WorkingMode>(v_); + + std::visit([&j, &isEnum](const auto& elem) { + if (isEnum) + j = formatter::to_str(elem); + else + j = elem; }, v_); + return j; } }; |