From 98584aecc4e578d945e7538da034f0d7e15c22f2 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Mon, 29 Aug 2022 05:29:31 +0300 Subject: [PATCH] settings: clean up after namespace update missing stringview key checks fix template specialization order when building single source update left-over modules that werent using espurna { ... } --- code/espurna/curtain_kingart.cpp | 2 +- code/espurna/domoticz.cpp | 4 +--- code/espurna/light.cpp | 4 ++++ code/espurna/rfbridge.cpp | 2 +- code/espurna/rpnrules.cpp | 2 +- code/espurna/sensors/PZEM004TSensor.h | 4 ++-- code/espurna/sensors/PZEM004TV30Sensor.h | 2 +- code/espurna/system.cpp | 21 ++++++++------------- code/espurna/system.h | 11 +++++++++++ 9 files changed, 30 insertions(+), 22 deletions(-) diff --git a/code/espurna/curtain_kingart.cpp b/code/espurna/curtain_kingart.cpp index 2dc88f96..a0536f21 100644 --- a/code/espurna/curtain_kingart.cpp +++ b/code/espurna/curtain_kingart.cpp @@ -394,7 +394,7 @@ void _curtainWebSocketOnConnected(JsonObject& root) { } //------------------------------------------------------------------------------ -bool _curtainWebSocketOnKeyCheck(const char * key, const JsonVariant& value) { +bool _curtainWebSocketOnKeyCheck(espurna::StringView key, const JsonVariant& value) { return espurna::settings::query::samePrefix(key, STRING_VIEW("curtain")); } diff --git a/code/espurna/domoticz.cpp b/code/espurna/domoticz.cpp index e0baa16c..e81f89ca 100644 --- a/code/espurna/domoticz.cpp +++ b/code/espurna/domoticz.cpp @@ -56,7 +56,6 @@ private: } // namespace } // namespace domoticz -} // namespace espurna namespace settings { namespace internal { @@ -69,7 +68,6 @@ espurna::domoticz::Idx convert(const String& value) { } // namespace internal } // namespace settings -namespace espurna { namespace domoticz { namespace internal { namespace { @@ -434,7 +432,7 @@ namespace { alignas(4) static constexpr char Prefix[] PROGMEM = "dcz"; -bool onKeyCheck(const char* key, const JsonVariant& value) { +bool onKeyCheck(espurna::StringView key, const JsonVariant&) { return espurna::settings::query::samePrefix(key, Prefix); } diff --git a/code/espurna/light.cpp b/code/espurna/light.cpp index 7a4fed86..454c9a5e 100644 --- a/code/espurna/light.cpp +++ b/code/espurna/light.cpp @@ -2446,6 +2446,10 @@ void _lightWebSocketOnAction(uint32_t client_id, const char* action, JsonObject& namespace { +// TODO: at this point we have 3 different state save / restoration +// routines that do *almost* the same thing +// (key point is, almost) + // Special persistance case were we take a snapshot of the boolean // state, brightness and of current input and converted values diff --git a/code/espurna/rfbridge.cpp b/code/espurna/rfbridge.cpp index 18ddcb72..79f68255 100644 --- a/code/espurna/rfbridge.cpp +++ b/code/espurna/rfbridge.cpp @@ -504,7 +504,7 @@ RfbRelayMatch _rfbMatch(const char* code) { // we gather all available options, as the kv store might be defined in any order // scan kvs only once, since we want both ON and OFF options and don't want to depend on the relayCount() - espurna::settings::internal::foreach_prefix( + espurna::settings::foreach_prefix( [codeView, &matched](espurna::StringView prefix, String key, const espurna::settings::kvs_type::ReadResult& value) { if (codeView.length() != value.length()) { return; diff --git a/code/espurna/rpnrules.cpp b/code/espurna/rpnrules.cpp index b501c156..55043343 100644 --- a/code/espurna/rpnrules.cpp +++ b/code/espurna/rpnrules.cpp @@ -144,7 +144,7 @@ size_t countMqttNames() { size_t index { 0 }; for (;;) { auto name = espurna::settings::Key(keys::Name, index); - if (!espurna::settings::internal::has(name.value())) { + if (!espurna::settings::has(name.value())) { break; } diff --git a/code/espurna/sensors/PZEM004TSensor.h b/code/espurna/sensors/PZEM004TSensor.h index c46fb86b..fc145306 100644 --- a/code/espurna/sensors/PZEM004TSensor.h +++ b/code/espurna/sensors/PZEM004TSensor.h @@ -489,7 +489,7 @@ void PZEM004TSensor::registerTerminalCommands() { auto end = _ports.end(); if (ctx.argv.size() == 2) { - auto offset = settings::internal::convert(ctx.argv[1]); + auto offset = espurna::settings::internal::convert(ctx.argv[1]); if (offset >= _ports.size()) { terminalError(ctx, F("Invalid port ID")); return; @@ -536,7 +536,7 @@ void PZEM004TSensor::registerTerminalCommands() { return; } - auto id = settings::internal::convert(ctx.argv[1]); + auto id = espurna::settings::internal::convert(ctx.argv[1]); if (id >= _ports.size()) { terminalError(ctx, F("Invalid port ID")); return; diff --git a/code/espurna/sensors/PZEM004TV30Sensor.h b/code/espurna/sensors/PZEM004TV30Sensor.h index dfb3c034..900826bd 100644 --- a/code/espurna/sensors/PZEM004TV30Sensor.h +++ b/code/espurna/sensors/PZEM004TV30Sensor.h @@ -717,7 +717,7 @@ void PZEM004TV30Sensor::registerTerminalCommands() { return; } - uint8_t updated = settings::internal::convert(ctx.argv[1]); + uint8_t updated = espurna::settings::internal::convert(ctx.argv[1]); _instance->flush(); if (_instance->modbusChangeAddress(updated)) { diff --git a/code/espurna/system.cpp b/code/espurna/system.cpp index 6544c1ec..c0ec4ac3 100644 --- a/code/espurna/system.cpp +++ b/code/espurna/system.cpp @@ -66,7 +66,7 @@ namespace internal { template <> espurna::heartbeat::Mode convert(const String& value) { - return convert(system::settings::options::HeartbeatModeOptions, value, espurna::heartbeat::Mode::Repeat); + return convert(system::settings::options::HeartbeatModeOptions, value, heartbeat::Mode::Repeat); } String serialize(espurna::heartbeat::Mode mode) { @@ -74,19 +74,19 @@ String serialize(espurna::heartbeat::Mode mode) { } template <> -std::chrono::duration convert(const String& value) { - return std::chrono::duration(convert(value)); -} - -template <> -espurna::duration::Milliseconds convert(const String& value) { - return espurna::duration::Milliseconds(convert(value)); +duration::Seconds convert(const String& value) { + return duration::Seconds(convert(value)); } String serialize(espurna::duration::Seconds value) { return serialize(value.count()); } +template <> +duration::Milliseconds convert(const String& value) { + return duration::Milliseconds(convert(value)); +} + String serialize(espurna::duration::Milliseconds value) { return serialize(value.count()); } @@ -95,11 +95,6 @@ String serialize(espurna::duration::ClockCycles value) { return serialize(value.count()); } -template <> -espurna::duration::Seconds convert(const String& value) { - return espurna::duration::Seconds(convert(value)); -} - } // namespace internal } // namespace settings diff --git a/code/espurna/system.h b/code/espurna/system.h index afc5eff7..47083ae0 100644 --- a/code/espurna/system.h +++ b/code/espurna/system.h @@ -277,6 +277,17 @@ Mode currentMode(); namespace settings { namespace internal { +template <> +heartbeat::Mode convert(const String&); + +template <> +duration::Milliseconds convert(const String&); + +template <> +std::chrono::duration convert(const String& value) { + return std::chrono::duration(convert(value)); +} + String serialize(heartbeat::Mode); String serialize(duration::Seconds); String serialize(duration::Milliseconds);