-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Weather Provider Refactoring * Changes - Implemented a modular weather provider system supporting multiple data sources - Added Yr.no as a new weather data provider - Set Yr.no as the default provider (no API key required) - Maintained OpenWeatherMap as an optional provider * Key Features - Provider Interface: Created a common interface for weather providers, making it easy to add new sources - Automatic Fallback: System defaults to Yr.no if no provider is specified - Configuration Flexibility: Users can switch between providers via settings - Enhanced Accuracy: Yr.no typically provides more accurate forecasts for many locations * Technical Details - Implemented provider-specific data models and API clients - Added standardized weather icon mapping system - Added proper error handling and retry logic
- Loading branch information
Showing
20 changed files
with
1,038 additions
and
651 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// internal/httpcontroller/weather_icons.go | ||
package handlers | ||
|
||
import ( | ||
"html/template" | ||
"time" | ||
|
||
"github.com/tphakala/birdnet-go/internal/suncalc" | ||
"github.com/tphakala/birdnet-go/internal/weather" | ||
) | ||
|
||
// GetWeatherIconFunc returns a function that returns an SVG icon for a given weather main | ||
func (h *Handlers) GetWeatherIconFunc() func(weatherCode string, timeOfDay weather.TimeOfDay) template.HTML { | ||
return func(weatherCode string, timeOfDay weather.TimeOfDay) template.HTML { | ||
// Strip 'd' or 'n' suffix if present | ||
if len(weatherCode) > 2 { | ||
weatherCode = weatherCode[:2] | ||
} | ||
iconCode := weather.IconCode(weatherCode) | ||
|
||
return weather.GetWeatherIcon(iconCode, timeOfDay) | ||
} | ||
} | ||
|
||
// GetSunPositionIconFunc returns a function that returns an SVG icon for a given time of day | ||
func (h *Handlers) GetSunPositionIconFunc() func(timeOfDay weather.TimeOfDay) template.HTML { | ||
return func(timeOfDay weather.TimeOfDay) template.HTML { | ||
return weather.GetTimeOfDayIcon(timeOfDay) | ||
} | ||
} | ||
|
||
// CalculateTimeOfDay determines the time of day based on the note time and sun events | ||
func (h *Handlers) CalculateTimeOfDay(noteTime time.Time, sunEvents suncalc.SunEventTimes) weather.TimeOfDay { | ||
return weather.CalculateTimeOfDay(noteTime, sunEvents) | ||
} | ||
|
||
// TimeOfDayToInt converts a string representation of a time of day to a TimeOfDay value | ||
func (h *Handlers) TimeOfDayToInt(s string) weather.TimeOfDay { | ||
return weather.StringToTimeOfDay(s) | ||
} | ||
|
||
// GetWeatherDescriptionFunc returns a function that returns a description for a given weather code | ||
func (h *Handlers) GetWeatherDescriptionFunc() func(weatherCode string) string { | ||
return func(weatherCode string) string { | ||
// Strip 'd' or 'n' suffix if present | ||
if len(weatherCode) > 2 { | ||
weatherCode = weatherCode[:2] | ||
} | ||
iconCode := weather.IconCode(weatherCode) | ||
return weather.GetIconDescription(iconCode) | ||
} | ||
} |
Oops, something went wrong.