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>
This commit was merged in pull request #4.
This commit is contained in:
2025-08-14 17:55:40 +02:00
committed by GitHub
parent 8284ae9695
commit 32b136d4cc
11 changed files with 338 additions and 96 deletions

View File

@@ -2,6 +2,6 @@ namespace HomeApi.Models;
public class Image
{
public WeatherInformation Weather { get; set; }
public List<TimeTable> TimeTable { get; set; }
public WeatherInformation? Weather { get; set; }
public List<TimeTable>? TimeTable { get; set; }
}

View File

@@ -0,0 +1,153 @@
using System.Text.Json.Serialization;
namespace HomeApi.Models.Response;
public class Data
{
[JsonPropertyName("instant")]
public Instant Instant { get; set; }
[JsonPropertyName("next_12_hours")]
public Next12Hours Next12Hours { get; set; }
[JsonPropertyName("next_1_hours")]
public Next1Hours Next1Hours { get; set; }
[JsonPropertyName("next_6_hours")]
public Next6Hours Next6Hours { get; set; }
}
public class Details
{
[JsonPropertyName("air_pressure_at_sea_level")]
public double AirPressureAtSeaLevel { get; set; }
[JsonPropertyName("air_temperature")]
public double AirTemperature { get; set; }
[JsonPropertyName("cloud_area_fraction")]
public double CloudAreaFraction { get; set; }
[JsonPropertyName("relative_humidity")]
public double RelativeHumidity { get; set; }
[JsonPropertyName("wind_from_direction")]
public double WindFromDirection { get; set; }
[JsonPropertyName("wind_speed")]
public double WindSpeed { get; set; }
[JsonPropertyName("precipitation_amount")]
public double PrecipitationAmount { get; set; }
}
public class Geometry
{
[JsonPropertyName("type")]
public string Type { get; set; }
[JsonPropertyName("coordinates")]
public List<double> Coordinates { get; set; }
}
public class Instant
{
[JsonPropertyName("details")]
public Details Details { get; set; }
}
public class Meta
{
[JsonPropertyName("updated_at")]
public DateTime UpdatedAt { get; set; }
[JsonPropertyName("units")]
public Units Units { get; set; }
}
public class Next12Hours
{
[JsonPropertyName("summary")]
public Summary Summary { get; set; }
[JsonPropertyName("details")]
public Details Details { get; set; }
}
public class Next1Hours
{
[JsonPropertyName("summary")]
public Summary Summary { get; set; }
[JsonPropertyName("details")]
public Details Details { get; set; }
}
public class Next6Hours
{
[JsonPropertyName("summary")]
public Summary Summary { get; set; }
[JsonPropertyName("details")]
public Details Details { get; set; }
}
public class Properties
{
[JsonPropertyName("meta")]
public Meta Meta { get; set; }
[JsonPropertyName("timeseries")]
public List<Timeseries> Timeseries { get; set; }
}
public class YrWeatherForecastResponse
{
[JsonPropertyName("type")]
public string Type { get; set; }
[JsonPropertyName("geometry")]
public Geometry Geometry { get; set; }
[JsonPropertyName("properties")]
public Properties Properties { get; set; }
}
public class Summary
{
[JsonPropertyName("symbol_code")]
public string SymbolCode { get; set; }
}
public class Timeseries
{
[JsonPropertyName("time")]
public DateTime Time { get; set; }
[JsonPropertyName("data")]
public Data Data { get; set; }
}
public class Units
{
[JsonPropertyName("air_pressure_at_sea_level")]
public string AirPressureAtSeaLevel { get; set; }
[JsonPropertyName("air_temperature")]
public string AirTemperature { get; set; }
[JsonPropertyName("cloud_area_fraction")]
public string CloudAreaFraction { get; set; }
[JsonPropertyName("precipitation_amount")]
public string PrecipitationAmount { get; set; }
[JsonPropertyName("relative_humidity")]
public string RelativeHumidity { get; set; }
[JsonPropertyName("wind_from_direction")]
public string WindFromDirection { get; set; }
[JsonPropertyName("wind_speed")]
public string WindSpeed { get; set; }
}

View File

@@ -1,24 +1,26 @@
#nullable disable
using HomeApi.Models.Response;
namespace HomeApi.Models;
public class WeatherInformation
{
public string CityName { get; set; } = string.Empty;
public string CityName { get; set; } = "Not defined";
public Current Current { get; set; } = new();
public List<Forecast> Forecast { get; set; }
}
public class Current
{
public string Date { get; set; }
public double Feelslike { get; set; }
public int IsDay { get; set; }
public string Date { get; set; } = string.Empty;
public double Feelslike { get; set; } = 0;
public int IsDay { get; set; } = 1;
public double WindPerMeterSecond { get; set; } = 0;
public double WindGustPerMeterSecond { get; set; } = 0;
public double Temperature { get; set; } = 0;
public string LastUpdated { get; set; } = string.Empty;
public int Cloud { get; set; }
public int Cloud { get; set; } = 0;
public string WindDirection { get; set; } = string.Empty;
public Location WeatherDataLocation { get; set; } = new();
public AirQuality AirQuality { get; set; }
@@ -28,72 +30,72 @@ public class Current
public class Location
{
public string Name { get; set; }
public string Region { get; set; }
public string Country { get; set; }
public double Lat { get; set; }
public double Lon { get; set; }
public string Name { get; set; } = string.Empty;
public string Region { get; set; } = string.Empty;
public string Country { get; set; } = string.Empty;
public double Lat { get; set; } = 0;
public double Lon { get; set; } = 0;
}
public class Probability
{
public DateTime Date { get; set; }
public CalculatedProbability Calculated { get; set; } // my location?
public string Colour { get; set; }
public int Value { get; set; }
public Highest HighestProbability { get; set; }
public DateTime Date { get; set; } = DateTime.Now;
public CalculatedProbability Calculated { get; set; } = new();
public string Colour { get; set; } = string.Empty;
public string Value { get; set; } = string.Empty;
public Highest HighestProbability { get; set; } = new();
}
public class Highest
{
public DateTime Date { get; set; }
public string Colour { get; set; }
public double Lat { get; set; }
public double Long { get; set; }
public int Value { get; set; }
public DateTime Date { get; set; } = DateTime.Now;
public string Colour { get; set; } = string.Empty;
public double Lat { get; set; } = 0;
public double Long { get; set; } = 0;
public int Value { get; set; } = 0;
}
public class Forecast
{
public string Date { get; set; }
public double MinTempC { get; set; }
public double MaxTempC { get; set; }
public string DayIcon { get; set; }
public WeatherSummary? Day { get; set; }
public WeatherSummary? Night { get; set; }
public Astro Astro { get; set; }
public int IconCode { get; set; }
public string Date { get; set; } = string.Empty;
public double MinTempC { get; set; } = 0;
public double MaxTempC { get; set; } = 0;
public string DayIcon { get; set; } = string.Empty;
public WeatherSummary? Day { get; set; } = null;
public WeatherSummary? Night { get; set; } = null;
public Astro Astro { get; set; } = new();
public int IconCode { get; set; } = 0;
public int ChanceOfRain { get; set; }
public int ChanceOfRain { get; set; } = 0;
}
public class Astro
{
public string Sunrise { get; set; }
public string Sunset { get; set; }
public string Moonrise { get; set; }
public string Moonset { get; set; }
public string Moon_Phase { get; set; }
public string Sunrise { get; set; } = string.Empty;
public string Sunset { get; set; } = string.Empty;
public string Moonrise { get; set; } = string.Empty;
public string Moonset { get; set; } = string.Empty;
public string Moon_Phase { get; set; } = string.Empty;
public double? Moon_Illumination { get; set; }
}
public class AirQuality
{
public double Co { get; set; }
public double No2 { get; set; }
public double O3 { get; set; }
public double So2 { get; set; }
public double Pm2_5 { get; set; }
public double Pm10 { get; set; }
public int Us_Epa_Index { get; set; }
public int Gb_Defra_Index { get; set; }
public double Co { get; set; } = 0;
public double No2 { get; set; } = 0;
public double O3 { get; set; } = 0;
public double So2 { get; set; } = 0;
public double Pm2_5 { get; set; } = 0;
public double Pm10 { get; set; } = 0;
public int Us_Epa_Index { get; set; } = 0;
public int Gb_Defra_Index { get; set; } = 0;
}
public class WeatherSummary
{
public string ConditionText { get; set; }
public string ConditionIcon { get; set; }
public double AvgTempC { get; set; }
public double AvgFeelslikeC { get; set; }
public int TotalChanceOfRain { get; set; }
public int TotalChanceOfSnow { get; set; }
public string ConditionText { get; set; } = string.Empty;
public string ConditionIcon { get; set; } = string.Empty;
public double AvgTempC { get; set; } = 0;
public double AvgFeelslikeC { get; set; } = 0;
public int TotalChanceOfRain { get; set; } = 0;
public int TotalChanceOfSnow { get; set; } = 0;
}