Files
Wireless_Eink_HomeScreen/HomeApi/Integration/WeatherService.cs
SocksOnHead 32b136d4cc fix: crash on unavailable source api (#4)
* fix: crash on unavailable source api

the screen not updating because of errors

* Change temperature format if null

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-14 17:55:40 +02:00

28 lines
818 B
C#

using HomeApi.Integration.Client.WeatherClient;
using HomeApi.Models.Configuration;
using HomeApi.Models.Response;
using Microsoft.Extensions.Options;
namespace HomeApi.Integration;
public interface IWeatherService
{
Task<WeatherData> GetWeatherAsync(string lat, string lon);
}
public class WeatherService(IWeatherClient weatherApi, IOptions<ApiConfiguration> options) : IWeatherService
{
private readonly ApiConfiguration _apiConfig = options.Value;
public Task<WeatherData> GetWeatherAsync(string? lat, string? lon)
{
var location = $"{lat},{lon}";
if (string.IsNullOrEmpty(lat) || string.IsNullOrEmpty(lon))
{
location = _apiConfig.DefaultCity;
}
return weatherApi.GetForecastAsync(_apiConfig.Keys.Weather, location);
}
}