Apply code formatting cleanup across monitor projects
- Reindent appsettings.json and the MSBuild project files - Collapse single-statement guard blocks and tidy using and member order - Normalize XML doc indentation and file endings - Reorder BatteryMonitor test-data helpers and move the exclusion tests into their own region - Carry the same formatting through the boiler config, control, entity and test files
This commit is contained in:
@@ -25,10 +25,7 @@ public sealed class PowerLimitEnforcementService(
|
||||
|
||||
public void EnforceLimit(double currentPowerWatts)
|
||||
{
|
||||
if (!_options.EnforceLimitEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!_options.EnforceLimitEnabled) return;
|
||||
|
||||
var now = timeProvider.GetUtcNow();
|
||||
|
||||
@@ -67,15 +64,9 @@ public sealed class PowerLimitEnforcementService(
|
||||
|
||||
private void ExecuteEnforce(double currentPowerWatts)
|
||||
{
|
||||
foreach (var entityId in _options.EnforceSwitchOffEntityIds)
|
||||
{
|
||||
TurnOff(entityId);
|
||||
}
|
||||
foreach (var entityId in _options.EnforceSwitchOffEntityIds) TurnOff(entityId);
|
||||
|
||||
foreach (var entityId in _options.PauseAndRestoreEntityIds)
|
||||
{
|
||||
TurnOff(entityId);
|
||||
}
|
||||
foreach (var entityId in _options.PauseAndRestoreEntityIds) TurnOff(entityId);
|
||||
|
||||
NotifyLimitEnforced(currentPowerWatts, _options.PowerLimitWatts);
|
||||
|
||||
@@ -87,10 +78,7 @@ public sealed class PowerLimitEnforcementService(
|
||||
|
||||
private void ExecuteRecover()
|
||||
{
|
||||
foreach (var entityId in _options.PauseAndRestoreEntityIds)
|
||||
{
|
||||
TurnOn(entityId);
|
||||
}
|
||||
foreach (var entityId in _options.PauseAndRestoreEntityIds) TurnOn(entityId);
|
||||
|
||||
DismissLimitNotification();
|
||||
|
||||
@@ -100,22 +88,20 @@ public sealed class PowerLimitEnforcementService(
|
||||
|
||||
private void TryEnforce(double currentPowerWatts, DateTimeOffset now)
|
||||
{
|
||||
if (currentPowerWatts <= _options.PowerLimitWatts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (currentPowerWatts <= _options.PowerLimitWatts) return;
|
||||
|
||||
if (now - _lastActionTime < TimeSpan.FromSeconds(_options.LimitCooldownSeconds))
|
||||
{
|
||||
if (logger.IsEnabled(LogLevel.Debug))
|
||||
{
|
||||
logger.LogDebug("Power limit breach detected ({Power:F0} W > {Limit:F0} W) but cooldown active, skipping", currentPowerWatts, _options.PowerLimitWatts);
|
||||
}
|
||||
logger.LogDebug(
|
||||
"Power limit breach detected ({Power:F0} W > {Limit:F0} W) but cooldown active, skipping",
|
||||
currentPowerWatts, _options.PowerLimitWatts);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
logger.LogWarning("Power limit exceeded: {Power:F0} W > {Limit:F0} W, enforcing turn-off", currentPowerWatts, _options.PowerLimitWatts);
|
||||
logger.LogWarning("Power limit exceeded: {Power:F0} W > {Limit:F0} W, enforcing turn-off", currentPowerWatts,
|
||||
_options.PowerLimitWatts);
|
||||
|
||||
ExecuteEnforce(currentPowerWatts);
|
||||
}
|
||||
@@ -124,28 +110,23 @@ public sealed class PowerLimitEnforcementService(
|
||||
{
|
||||
var elapsed = now - _enforcedAt;
|
||||
|
||||
if (elapsed < TimeSpan.FromSeconds(_options.RecoverySeconds))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (elapsed < TimeSpan.FromSeconds(_options.RecoverySeconds)) return;
|
||||
|
||||
if (currentPowerWatts >= _options.PowerLimitWatts)
|
||||
{
|
||||
logger.LogWarning("Recovery time reached but power still {Power:F0} W >= {Limit:F0} W, staying enforced", currentPowerWatts, _options.PowerLimitWatts);
|
||||
logger.LogWarning("Recovery time reached but power still {Power:F0} W >= {Limit:F0} W, staying enforced",
|
||||
currentPowerWatts, _options.PowerLimitWatts);
|
||||
_enforcedAt = now;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
logger.LogInformation("Power recovered to {Power:F0} W (< {Limit:F0} W) after {Seconds}s, restoring paused monitors", currentPowerWatts, _options.PowerLimitWatts, (int)elapsed.TotalSeconds);
|
||||
}
|
||||
logger.LogInformation(
|
||||
"Power recovered to {Power:F0} W (< {Limit:F0} W) after {Seconds}s, restoring paused monitors",
|
||||
currentPowerWatts, _options.PowerLimitWatts, (int)elapsed.TotalSeconds);
|
||||
|
||||
foreach (var entityId in _options.PauseAndRestoreEntityIds)
|
||||
{
|
||||
TurnOn(entityId);
|
||||
}
|
||||
foreach (var entityId in _options.PauseAndRestoreEntityIds) TurnOn(entityId);
|
||||
|
||||
DismissLimitNotification();
|
||||
|
||||
@@ -155,17 +136,20 @@ public sealed class PowerLimitEnforcementService(
|
||||
|
||||
private void TurnOff(string entityId)
|
||||
{
|
||||
haContext.CallService(PowerMonitorConsts.SwitchDomain, PowerMonitorConsts.TurnOffService, ServiceTarget.FromEntity(entityId));
|
||||
haContext.CallService(PowerMonitorConsts.SwitchDomain, PowerMonitorConsts.TurnOffService,
|
||||
ServiceTarget.FromEntity(entityId));
|
||||
}
|
||||
|
||||
private void TurnOn(string entityId)
|
||||
{
|
||||
haContext.CallService(PowerMonitorConsts.SwitchDomain, PowerMonitorConsts.TurnOnService, ServiceTarget.FromEntity(entityId));
|
||||
haContext.CallService(PowerMonitorConsts.SwitchDomain, PowerMonitorConsts.TurnOnService,
|
||||
ServiceTarget.FromEntity(entityId));
|
||||
}
|
||||
|
||||
private void NotifyLimitEnforced(double currentPowerWatts, double limitWatts)
|
||||
{
|
||||
var message = BuildLimitMessage(currentPowerWatts / PowerMonitorConsts.WattsPerKilowatt, limitWatts / PowerMonitorConsts.WattsPerKilowatt);
|
||||
var message = BuildLimitMessage(currentPowerWatts / PowerMonitorConsts.WattsPerKilowatt,
|
||||
limitWatts / PowerMonitorConsts.WattsPerKilowatt);
|
||||
|
||||
haContext.CallService(
|
||||
PowerMonitorConsts.PersistentNotificationDomain,
|
||||
|
||||
Reference in New Issue
Block a user