Add braces to single-statement guards and refactor NordPool price fetching
- Expand inline guard, return and logger blocks across the monitor services, init classes and tests - Have INordPoolPriceService take a per-date fetch delegate and expose ParseAndAdjust, moving the HA fetch call into NordPoolInit so the service can be registered singleton - Record the NordPool and boiler service lifetimes in AGENTS.md - Drop the unused persisted-state argument from the boiler test data helper
This commit is contained in:
@@ -55,7 +55,9 @@ public sealed class ExhaustFanControlService(
|
||||
var fanState = haContext.GetState(_options.ExhaustFanEntityId)?.State;
|
||||
|
||||
if (string.Equals(fanState, "on", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
haContext.CallService("switch", "turn_off", ServiceTarget.FromEntity(_options.ExhaustFanEntityId));
|
||||
}
|
||||
}
|
||||
|
||||
_fanTurnedOnByUs = false;
|
||||
|
||||
@@ -140,7 +140,9 @@ public sealed class ShowerDetectionService(
|
||||
if (_suspectedSince.HasValue && timestamp - _suspectedSince.Value >= confirmationWindow
|
||||
&& humidity >= _options.PeakHumidityThreshold
|
||||
&& differential >= _options.MinDifferentialHumidity)
|
||||
{
|
||||
return ShowerState.Active;
|
||||
}
|
||||
|
||||
var showerAbandoned = rate < 0 && differential < _options.MinDifferentialHumidity;
|
||||
if (!showerAbandoned) return ShowerState.Suspected;
|
||||
|
||||
@@ -155,8 +155,10 @@ public sealed class ShowerMonitorInit
|
||||
if (!bathroomHumidity.HasValue || !mainHomeHumidity.HasValue)
|
||||
{
|
||||
if (_logger.IsEnabled(LogLevel.Debug))
|
||||
{
|
||||
_logger.LogDebug("Humidity sensor data unavailable (bathroom={Bathroom}, home={Home})",
|
||||
bathroomHumidity, mainHomeHumidity);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -179,8 +181,10 @@ public sealed class ShowerMonitorInit
|
||||
await _entityService.UpdateEntitiesAsync(context);
|
||||
|
||||
if (_logger.IsEnabled(LogLevel.Debug))
|
||||
{
|
||||
_logger.LogDebug("Poll: bathroom={Bath}%, home={Home}%, diff={Diff}%, state={State}",
|
||||
bathroomHumidity.Value, mainHomeHumidity.Value, Math.Round(differential, 1), state);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user