From 144b2707fdb469b717f1276164337c76a5351d9f Mon Sep 17 00:00:00 2001 From: BlueAndi Date: Sun, 26 Nov 2023 22:44:48 +0100 Subject: [PATCH] Variable scope reduced and parameter made const. --- .../src/OpenWeatherPlugin.cpp | 19 ++++++++++--------- lib/OpenWeatherPlugin/src/OpenWeatherPlugin.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/OpenWeatherPlugin/src/OpenWeatherPlugin.cpp b/lib/OpenWeatherPlugin/src/OpenWeatherPlugin.cpp index 40612a26..770d37fc 100644 --- a/lib/OpenWeatherPlugin/src/OpenWeatherPlugin.cpp +++ b/lib/OpenWeatherPlugin/src/OpenWeatherPlugin.cpp @@ -875,7 +875,7 @@ void OpenWeatherPlugin::initHttpClient() ); } -void OpenWeatherPlugin::handleWebResponse(DynamicJsonDocument& jsonDoc) +void OpenWeatherPlugin::handleWebResponse(const DynamicJsonDocument& jsonDoc) { if (nullptr != m_source) { @@ -888,13 +888,11 @@ void OpenWeatherPlugin::prepareDataToShow() { if (nullptr != m_source) { - float temperature = m_source->getTemperature(); - String weatherIconId = m_source->getWeatherIconId(); - float uvIndex = m_source->getUvIndex(); - int humidity = m_source->getHumidity(); - float windSpeed = m_source->getWindSpeed(); - char tempReducedPrecison[6] = { 0 }; - char windReducedPrecison[5] = { 0 }; + float temperature = m_source->getTemperature(); + String weatherIconId = m_source->getWeatherIconId(); + float uvIndex = m_source->getUvIndex(); + int humidity = m_source->getHumidity(); + float windSpeed = m_source->getWindSpeed(); String weatherConditionIconFullPath; /* Generate UV-Index string and adapt color of string accordingly. */ @@ -915,7 +913,8 @@ void OpenWeatherPlugin::prepareDataToShow() } else { - const char* reducePrecision = (temperature < -9.9F) ? "%.0f" : "%.1f"; + const char* reducePrecision = (temperature < -9.9F) ? "%.0f" : "%.1f"; + char tempReducedPrecison[6] = { 0 }; /* Generate temperature string with reduced precision and add unit °C/°F. */ (void)snprintf(tempReducedPrecison, sizeof(tempReducedPrecison), reducePrecision, temperature); @@ -938,6 +937,8 @@ void OpenWeatherPlugin::prepareDataToShow() } else { + char windReducedPrecison[5] = { 0 }; + (void)snprintf(windReducedPrecison, sizeof(windReducedPrecison), "%.1f", windSpeed); m_currentWindspeed = "\\calign"; diff --git a/lib/OpenWeatherPlugin/src/OpenWeatherPlugin.h b/lib/OpenWeatherPlugin/src/OpenWeatherPlugin.h index 3cd8a5d3..a0cd9a45 100644 --- a/lib/OpenWeatherPlugin/src/OpenWeatherPlugin.h +++ b/lib/OpenWeatherPlugin/src/OpenWeatherPlugin.h @@ -592,7 +592,7 @@ class OpenWeatherPlugin : public Plugin, private PluginConfigFsHandler * * @param[in] jsonDoc Web response as JSON document */ - void handleWebResponse(DynamicJsonDocument& jsonDoc); + void handleWebResponse(const DynamicJsonDocument& jsonDoc); /** * Prepares the data to show from the OpenWeather source data.