diff --git a/src/Server/BatteryService/AmpValQueue.cs b/src/Server/BatteryService/AmpValQueue.cs index b45aaa9..cfceb33 100644 --- a/src/Server/BatteryService/AmpValQueue.cs +++ b/src/Server/BatteryService/AmpValQueue.cs @@ -1,9 +1,15 @@ namespace InverterMon.Server.BatteryService; -public sealed class AmpValQueue(int fixedCapacity) +public sealed class AmpValQueue { readonly Queue _queue = new(); bool _lastChargingState; + readonly int _fixedCapacity; + + public AmpValQueue(int fixedCapacity) + { + _fixedCapacity = fixedCapacity; + } public void Store(float ampReading, bool chargingState) { @@ -18,7 +24,7 @@ public void Store(float ampReading, bool chargingState) _lastChargingState = chargingState; _queue.Enqueue(ampReading); - if (_queue.Count > fixedCapacity) + if (_queue.Count > _fixedCapacity) _queue.Dequeue(); } diff --git a/src/Server/InverterMon.Server.csproj b/src/Server/InverterMon.Server.csproj index 5db8ae1..e299f6f 100644 --- a/src/Server/InverterMon.Server.csproj +++ b/src/Server/InverterMon.Server.csproj @@ -2,11 +2,12 @@ net7.0 + 11 + enable enable CS8618;CA2016 MIT - 12 @@ -27,23 +28,23 @@ - - - - + + + + - - + + - - - - - + + + + + \ No newline at end of file diff --git a/src/Server/InverterService/StatusRetriever.cs b/src/Server/InverterService/StatusRetriever.cs index 237b330..ef547ab 100644 --- a/src/Server/InverterService/StatusRetriever.cs +++ b/src/Server/InverterService/StatusRetriever.cs @@ -3,22 +3,33 @@ namespace InverterMon.Server.InverterService; -class StatusRetriever(CommandQueue queue, Database db, UserSettings userSettings) : BackgroundService +class StatusRetriever : BackgroundService { + readonly CommandQueue _queue; + readonly Database _db; + readonly UserSettings _userSettings; + + public StatusRetriever(CommandQueue queue, Database db, UserSettings userSettings) + { + _queue = queue; + _db = db; + _userSettings = userSettings; + } + protected override async Task ExecuteAsync(CancellationToken c) { - var cmd = queue.StatusCommand; + var cmd = _queue.StatusCommand; while (!c.IsCancellationRequested) { - if (queue.IsAcceptingCommands) + if (_queue.IsAcceptingCommands) { //feels hacky. find a better solution. - cmd.Result.BatteryCapacity = userSettings.BatteryCapacity; - cmd.Result.PV_MaxCapacity = userSettings.PV_MaxCapacity; + cmd.Result.BatteryCapacity = _userSettings.BatteryCapacity; + cmd.Result.PV_MaxCapacity = _userSettings.PV_MaxCapacity; - queue.AddCommands(cmd); - _ = db.UpdateTodaysPvGeneration(cmd, c); + _queue.AddCommands(cmd); + _ = _db.UpdateTodaysPvGeneration(cmd, c); } await Task.Delay(Constants.StatusPollingFrequencyMillis); } diff --git a/src/Server/Persistance/Settings/UserSettings.cs b/src/Server/Persistance/Settings/UserSettings.cs index 6c0fc90..7893466 100644 --- a/src/Server/Persistance/Settings/UserSettings.cs +++ b/src/Server/Persistance/Settings/UserSettings.cs @@ -10,7 +10,7 @@ public class UserSettings public int BatteryCapacity { get; set; } = 100; public int SunlightStartHour { get; set; } = 6; public int SunlightEndHour { get; set; } = 18; - public int[] PVGraphRange => [0, (SunlightEndHour - SunlightStartHour) * 60]; + public int[] PVGraphRange => new[] { 0, (SunlightEndHour - SunlightStartHour) * 60 }; public int PVGraphTickCount => PVGraphRange[1] / (int)PVGenExtensions.BucketDuration.TotalMinutes; public SystemSpec ToSystemSpec()