Skip to content

Commit

Permalink
disable weather/wordnik by default if no API keys provided
Browse files Browse the repository at this point in the history
if no API keys were provided on build then disable updates on boot
and do not hummer API servers with malformed requests
  • Loading branch information
vortigont committed Dec 19, 2024
1 parent e3f62d0 commit fec2a86
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ ADMIN_LOGIN=\"plasma\"
ADMIN_PASS=\"plasma\"

# OpenWeatherMap configuration
WEATHER_LAT=\"43.0642\"
WEATHER_LON=\"141.3469\"
WEATHER_API_KEY=\"your_OpenWeatherMap_API_Key\"
#WEATHER_LAT=\"43.0642\"
#WEATHER_LON=\"141.3469\"
#WEATHER_API_KEY=\"your_OpenWeatherMap_API_Key\"

# Wordnik configuration
WORDNIK_API_KEY=\"your_Wordnik_API_key\"
#WORDNIK_API_KEY=\"your_Wordnik_API_key\"

# AquesTalk configuration
AQUESTALK_LICENSE_KEY=\"XXX-XXX-XXX\"
Expand Down
11 changes: 8 additions & 3 deletions src/service/owm/weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,14 @@ void weather_start() {

firstRunSemaphore = xSemaphoreCreateBinary();

apiKey = prefs_get_string(PREFS_KEY_WEATHER_APIKEY, String(WEATHER_API_KEY));
latitude = prefs_get_string(PREFS_KEY_WEATHER_LAT, String(WEATHER_LAT));
longitude = prefs_get_string(PREFS_KEY_WEATHER_LON, String(WEATHER_LON));
apiKey = prefs_get_string(PREFS_KEY_WEATHER_APIKEY);
latitude = prefs_get_string(PREFS_KEY_WEATHER_LAT);
longitude = prefs_get_string(PREFS_KEY_WEATHER_LON);

if (!apiKey.length()){
ESP_LOGW(LOG_TAG, "No weather API key, disabling weather updates!");
return;
}

int interval_minutes = prefs_get_int(PREFS_KEY_WEATHER_INTERVAL_MINUTES);
if(interval_minutes == 0) {
Expand Down
7 changes: 6 additions & 1 deletion src/service/wordnik.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ void wotd_start() {
firstRunSemaphore = xSemaphoreCreateBinary();
hasQueries = true;

apiKey = prefs_get_string(PREFS_KEY_WORDNIK_APIKEY, String(WORDNIK_API_KEY));
apiKey = prefs_get_string(PREFS_KEY_WORDNIK_APIKEY);

if (!apiKey.length()){
ESP_LOGW(LOG_TAG, "No wordnik API key, disabling updates!");
return;
}

int interval_minutes = prefs_get_int(PREFS_KEY_WORDNIK_INTERVAL_MINUTES);
if(interval_minutes == 0) {
Expand Down

0 comments on commit fec2a86

Please sign in to comment.