Use a single config for weather feed #288

Open
opened 2025-03-15 10:18:25 +00:00 by flattermann · 1 comment
flattermann commented 2025-03-15 10:18:25 +00:00 (Migrated from github.com)

Instead of

// WEATHER CONFIGURATION (ONLY SET ONE FEED TO TRUE)
#define WEATHER_VISUALCROSSING_FEED true
#define WEATHER_OPENWEATHERMAP_FEED false
#define WEATHER_TEMPEST_FEED false

I think an enum would be better, e.g.

enum WeatherFeedType {
  VISUALCROSSING = 0,
  OPENWEATHERMAP,
  TEMPEST
}
// WEATHER CONFIGURATION
#define WEATHER_FEED VISUALCROSSING

This would look cleaner in the config.h.

Instead of ``` // WEATHER CONFIGURATION (ONLY SET ONE FEED TO TRUE) #define WEATHER_VISUALCROSSING_FEED true #define WEATHER_OPENWEATHERMAP_FEED false #define WEATHER_TEMPEST_FEED false ``` I think an enum would be better, e.g. ``` enum WeatherFeedType { VISUALCROSSING = 0, OPENWEATHERMAP, TEMPEST } ``` ``` // WEATHER CONFIGURATION #define WEATHER_FEED VISUALCROSSING ``` This would look cleaner in the config.h.
nconner-06 commented 2025-03-15 12:17:38 +00:00 (Migrated from github.com)

then change the createWeatherFeed function to a 'switch' statement:
switch (WEATHER_FEED){
case (VISUALCROSSING): {
return new VisualCrossingFeed(WEATHER_VISUALCROSSING_API_KEY, weatherUnits);
}
case (OPENWEATHERMAP): {
return new OpenWeatherMapFeed(WEATHER_OPENWEATHERMAP_API_KEY, weatherUnits);
}
case (TEMPEST): {
return new TempestFeed(WEATHER_TEMPEST_API_KEY, weatherUnits);
}
}

then change the createWeatherFeed function to a 'switch' statement: switch (WEATHER_FEED){ case (VISUALCROSSING): { return new VisualCrossingFeed(WEATHER_VISUALCROSSING_API_KEY, weatherUnits); } case (OPENWEATHERMAP): { return new OpenWeatherMapFeed(WEATHER_OPENWEATHERMAP_API_KEY, weatherUnits); } case (TEMPEST): { return new TempestFeed(WEATHER_TEMPEST_API_KEY, weatherUnits); } }
Sign in to join this conversation.
No description provided.