Skip to content

Commit

Permalink
Variable scope reduced and parameter made const.
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueAndi committed Nov 26, 2023
1 parent 35712bd commit 144b270
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions lib/OpenWeatherPlugin/src/OpenWeatherPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ void OpenWeatherPlugin::initHttpClient()
);
}

void OpenWeatherPlugin::handleWebResponse(DynamicJsonDocument& jsonDoc)
void OpenWeatherPlugin::handleWebResponse(const DynamicJsonDocument& jsonDoc)
{
if (nullptr != m_source)
{
Expand All @@ -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. */
Expand All @@ -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);
Expand All @@ -938,6 +937,8 @@ void OpenWeatherPlugin::prepareDataToShow()
}
else
{
char windReducedPrecison[5] = { 0 };

(void)snprintf(windReducedPrecison, sizeof(windReducedPrecison), "%.1f", windSpeed);

m_currentWindspeed = "\\calign";
Expand Down
2 changes: 1 addition & 1 deletion lib/OpenWeatherPlugin/src/OpenWeatherPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 144b270

Please sign in to comment.