Apply code formatting cleanup across the monitor projects
- Wrap using directives in `#region` blocks across the Battery, Boiler and NordPool sources and tests - Expand single-statement guards and loops into braced blocks - Realign wrapped method arguments, chained calls and continuations - Replace target-typed `new()` with explicit generic construction and empty string literals with `string.Empty` - Flatten the boiler config expression and reindent the remaining touched files
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
#region
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace NordPool.Models;
|
||||
|
||||
public class CheapestIntervalResult
|
||||
{
|
||||
[JsonPropertyName("start")] public DateTime Start { get; init; }
|
||||
[JsonPropertyName("start")]
|
||||
public DateTime Start { get; init; }
|
||||
|
||||
[JsonPropertyName("end")] public DateTime End { get; init; }
|
||||
[JsonPropertyName("end")]
|
||||
public DateTime End { get; init; }
|
||||
|
||||
[JsonPropertyName("price")] public double Price { get; init; }
|
||||
[JsonPropertyName("price")]
|
||||
public double Price { get; init; }
|
||||
|
||||
[JsonPropertyName("rank")] public int Rank { get; init; }
|
||||
[JsonPropertyName("rank")]
|
||||
public int Rank { get; init; }
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
#region
|
||||
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace NordPool.Models;
|
||||
|
||||
[JsonConverter(typeof(CompactNordPoolDayPriceConverter))]
|
||||
@@ -19,11 +23,11 @@ public readonly struct CompactNordPoolDayPrice
|
||||
return new CompactNordPoolDayPrice
|
||||
{
|
||||
Start = dayPrice.Start.HasValue
|
||||
? ToUnixSeconds(dayPrice.Start.Value)
|
||||
: NullTimestampSentinel,
|
||||
? ToUnixSeconds(dayPrice.Start.Value)
|
||||
: NullTimestampSentinel,
|
||||
End = dayPrice.End.HasValue
|
||||
? ToUnixSeconds(dayPrice.End.Value)
|
||||
: NullTimestampSentinel,
|
||||
? ToUnixSeconds(dayPrice.End.Value)
|
||||
: NullTimestampSentinel,
|
||||
Price = dayPrice.Price
|
||||
};
|
||||
}
|
||||
@@ -31,8 +35,8 @@ public readonly struct CompactNordPoolDayPrice
|
||||
private static long ToUnixSeconds(DateTime dateTime)
|
||||
{
|
||||
var utc = dateTime.Kind == DateTimeKind.Utc
|
||||
? dateTime
|
||||
: dateTime.ToUniversalTime();
|
||||
? dateTime
|
||||
: dateTime.ToUniversalTime();
|
||||
|
||||
return new DateTimeOffset(utc, TimeSpan.Zero).ToUnixTimeSeconds();
|
||||
}
|
||||
@@ -40,10 +44,14 @@ public readonly struct CompactNordPoolDayPrice
|
||||
|
||||
internal sealed class CompactNordPoolDayPriceConverter : JsonConverter<CompactNordPoolDayPrice>
|
||||
{
|
||||
public override CompactNordPoolDayPrice Read(ref Utf8JsonReader reader, Type typeToConvert,
|
||||
JsonSerializerOptions options)
|
||||
public override CompactNordPoolDayPrice Read(ref Utf8JsonReader reader,
|
||||
Type typeToConvert,
|
||||
JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.StartArray) throw new JsonException("Expected start of array.");
|
||||
if (reader.TokenType != JsonTokenType.StartArray)
|
||||
{
|
||||
throw new JsonException("Expected start of array.");
|
||||
}
|
||||
|
||||
if (!reader.Read() || reader.TokenType != JsonTokenType.Number)
|
||||
{
|
||||
@@ -69,8 +77,8 @@ internal sealed class CompactNordPoolDayPriceConverter : JsonConverter<CompactNo
|
||||
reader.Read();
|
||||
|
||||
return reader.TokenType == JsonTokenType.EndArray
|
||||
? new CompactNordPoolDayPrice { Start = start, End = end, Price = price }
|
||||
: throw new JsonException("Expected end of array.");
|
||||
? new CompactNordPoolDayPrice { Start = start, End = end, Price = price }
|
||||
: throw new JsonException("Expected end of array.");
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, CompactNordPoolDayPrice value, JsonSerializerOptions options)
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
using System.Text.Json.Serialization;
|
||||
#region
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace NordPool.Models.Dtos;
|
||||
|
||||
public class NordPoolDayPriceDto
|
||||
{
|
||||
[JsonPropertyName("start")] public string? Start { get; init; }
|
||||
[JsonPropertyName("start")]
|
||||
public string? Start { get; init; }
|
||||
|
||||
[JsonPropertyName("end")] public string? End { get; init; }
|
||||
[JsonPropertyName("end")]
|
||||
public string? End { get; init; }
|
||||
|
||||
[JsonPropertyName("price")] public double? Price { get; init; }
|
||||
[JsonPropertyName("price")]
|
||||
public double? Price { get; init; }
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
using System.Text.Json.Serialization;
|
||||
#region
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace NordPool.Models.Dtos;
|
||||
|
||||
public class NordPoolPriceResultDto
|
||||
{
|
||||
[JsonPropertyName("LT")] public List<NordPoolDayPriceDto>? Prices { get; init; }
|
||||
[JsonPropertyName("LT")]
|
||||
public List<NordPoolDayPriceDto>? Prices { get; init; }
|
||||
}
|
||||
@@ -5,7 +5,7 @@ public static class NordPoolDayPriceExtensions
|
||||
public static List<CompactNordPoolDayPrice> ToCompact(this IEnumerable<NordPoolDayPrice>? prices)
|
||||
{
|
||||
return prices is null
|
||||
? []
|
||||
: [.. prices.Select(CompactNordPoolDayPrice.FromDayPrice)];
|
||||
? []
|
||||
: [.. prices.Select(CompactNordPoolDayPrice.FromDayPrice)];
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
#region
|
||||
|
||||
using HomeAssistant.Models;
|
||||
using NetDaemon.Extensions.MqttEntityManager;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace NordPool.Models;
|
||||
|
||||
public class NordPoolEntity : EntityCreateModel
|
||||
@@ -39,8 +43,9 @@ public class NordPoolEntity : EntityCreateModel
|
||||
/// </summary>
|
||||
public static object CreateAdditionalConfig(object extraProperties)
|
||||
{
|
||||
var extras = extraProperties.GetType().GetProperties()
|
||||
.ToDictionary(p => p.Name, p => p.GetValue(extraProperties));
|
||||
var extras = extraProperties.GetType()
|
||||
.GetProperties()
|
||||
.ToDictionary(p => p.Name, p => p.GetValue(extraProperties));
|
||||
|
||||
extras["device"] = DeviceBlock;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user