-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Summary:** This pull request upgrades the Flurl library used in the project and includes necessary adjustments to ensure compatibility with the new version. Because Flurl v4 move to `System.text.Json` we need to change here the serializer.
- Loading branch information
Showing
67 changed files
with
415 additions
and
429 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,19 +1,18 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Flurl.Http.Configuration; | ||
using Netatmo.Converters; | ||
using Newtonsoft.Json; | ||
|
||
namespace Netatmo; | ||
|
||
public static class Configuration | ||
{ | ||
public static JsonSerializerSettings JsonSerializer() => | ||
new() { NullValueHandling = NullValueHandling.Ignore, Converters = [new TimestampToInstantConverter(), new StringToDateTimeZoneConverter()] }; | ||
public static JsonSerializerOptions JsonSerializerOptions => | ||
new() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, Converters = { new TimestampToInstantConverter(), new StringToDateTimeZoneConverter() } }; | ||
|
||
public static void ConfigureRequest(FlurlHttpSettings settings) | ||
{ | ||
var jsonSettings = JsonSerializer(); | ||
|
||
//jsonSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb); | ||
settings.JsonSerializer = new NewtonsoftJsonSerializer(jsonSettings); | ||
// something like maybe miss : jsonSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb); | ||
settings.JsonSerializer = new DefaultJsonSerializer(JsonSerializerOptions); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,23 +1,13 @@ | ||
using Flurl.Util; | ||
using Newtonsoft.Json; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using NodaTime; | ||
|
||
namespace Netatmo.Converters; | ||
|
||
public class StringToDateTimeZoneConverter : JsonConverter<DateTimeZone> | ||
{ | ||
public override void WriteJson(JsonWriter writer, DateTimeZone value, JsonSerializer serializer) | ||
{ | ||
writer.WriteValue(value?.ToInvariantString()); | ||
} | ||
public override DateTimeZone Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => | ||
DateTimeZoneProviders.Tzdb.GetZoneOrNull(reader.GetString()!); | ||
|
||
public override DateTimeZone ReadJson(JsonReader reader, Type objectType, DateTimeZone existingValue, bool hasExistingValue, JsonSerializer serializer) | ||
{ | ||
if (reader.Value == null) | ||
{ | ||
return null; | ||
} | ||
|
||
return DateTimeZoneProviders.Tzdb[reader.Value.ToString()]; | ||
} | ||
public override void Write(Utf8JsonWriter writer, DateTimeZone value, JsonSerializerOptions options) => writer.WriteStringValue(value?.Id); | ||
} |
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 |
---|---|---|
@@ -1,27 +1,12 @@ | ||
using Newtonsoft.Json; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using NodaTime; | ||
|
||
namespace Netatmo.Converters; | ||
|
||
public class TimestampToInstantConverter : JsonConverter<Instant?> | ||
public class TimestampToInstantConverter : JsonConverter<Instant> | ||
{ | ||
public override void WriteJson(JsonWriter writer, Instant? value, JsonSerializer serializer) | ||
{ | ||
if (value.HasValue) | ||
{ | ||
writer.WriteValue(value.Value.ToUnixTimeSeconds().ToString()); | ||
} | ||
} | ||
public override Instant Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => Instant.FromUnixTimeSeconds(reader.GetInt64()); | ||
|
||
public override Instant? ReadJson(JsonReader reader, Type objectType, Instant? existingValue, bool hasExistingValue, JsonSerializer serializer) | ||
{ | ||
if (reader.Value == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var value = long.Parse(reader.Value.ToString()); | ||
|
||
return Instant.FromUnixTimeSeconds(value); | ||
} | ||
public override void Write(Utf8JsonWriter writer, Instant value, JsonSerializerOptions options) => writer.WriteNumberValue(value.ToUnixTimeSeconds()); | ||
} |
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,17 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Netatmo.Converters; | ||
|
||
public class ZoneIdConverter : JsonConverter<string> | ||
{ | ||
public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => | ||
reader.TokenType switch | ||
{ | ||
JsonTokenType.String => reader.GetString(), | ||
JsonTokenType.Number => reader.GetInt32().ToString(), | ||
_ => throw new JsonException("Zone.Id must be a string or an integer.") | ||
}; | ||
|
||
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) => writer.WriteNumberValue(int.Parse(value)); | ||
} |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
using System.Text.Json.Serialization; | ||
using Netatmo.Models.Client.Air.HomesCoachs; | ||
using Newtonsoft.Json; | ||
|
||
namespace Netatmo.Models.Client.Air; | ||
|
||
public class GetHomeCoachsData | ||
{ | ||
[JsonProperty("devices")] | ||
[JsonPropertyName("devices")] | ||
public Devices[] Devices { get; set; } | ||
|
||
[JsonProperty("user")] | ||
[JsonPropertyName("user")] | ||
public User User { get; set; } | ||
} |
26 changes: 13 additions & 13 deletions
26
src/Netatmo/Models/Client/Air/HomesCoachs/DashBoardData.cs
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 |
---|---|---|
@@ -1,43 +1,43 @@ | ||
using Newtonsoft.Json; | ||
using System.Text.Json.Serialization; | ||
using NodaTime; | ||
|
||
namespace Netatmo.Models.Client.Air.HomesCoachs; | ||
|
||
public class DashBoardData | ||
{ | ||
[JsonProperty("time_utc")] | ||
[JsonPropertyName("time_utc")] | ||
public Instant TimeUtc { get; set; } | ||
|
||
[JsonProperty("Temperature")] | ||
[JsonPropertyName("Temperature")] | ||
public double Temperature { get; set; } | ||
|
||
[JsonProperty("CO2")] | ||
[JsonPropertyName("CO2")] | ||
public int CO2 { get; set; } | ||
|
||
[JsonProperty("Humidity")] | ||
[JsonPropertyName("Humidity")] | ||
public int HumidityPercent { get; set; } | ||
|
||
[JsonProperty("Noise")] | ||
[JsonPropertyName("Noise")] | ||
public double Noise { get; set; } | ||
|
||
[JsonProperty("Pressure")] | ||
[JsonPropertyName("Pressure")] | ||
public double Pressure { get; set; } | ||
|
||
[JsonProperty("AbsolutePressure")] | ||
[JsonPropertyName("AbsolutePressure")] | ||
public double AbsolutePressure { get; set; } | ||
|
||
[JsonProperty("health_idx")] | ||
[JsonPropertyName("health_idx")] | ||
public HealthIdx HealthIdx { get; set; } | ||
|
||
[JsonProperty("min_temp")] | ||
[JsonPropertyName("min_temp")] | ||
public decimal MinTemp { get; set; } | ||
|
||
[JsonProperty("max_temp")] | ||
[JsonPropertyName("max_temp")] | ||
public decimal MaxTemp { get; set; } | ||
|
||
[JsonProperty("date_min_temp")] | ||
[JsonPropertyName("date_min_temp")] | ||
public Instant DateMinTemp { get; set; } | ||
|
||
[JsonProperty("date_max_temp")] | ||
[JsonPropertyName("date_max_temp")] | ||
public Instant DateMaxTemp { get; set; } | ||
} |
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
Oops, something went wrong.