This commit is contained in:
2026-06-28 13:58:35 +03:00
parent 8f45028715
commit e6bf8258bb
114 changed files with 4365 additions and 874 deletions
+23 -1
View File
@@ -24,9 +24,11 @@ public sealed class PowerMonitorInit : IPowerMonitorInit
private readonly IOtherPowerCalculationService _calculationService;
private readonly IPowerCostCalculationService _costService;
private readonly IPowerMonitorEntityService _entityService;
private readonly IPowerNotificationService _notificationService;
private int _mainMeterConsecutiveFailures;
private DateTime? _anomalyStartTime;
private bool _highPowerNotificationActive;
public PowerMonitorInit(
IHaContext haContext,
@@ -36,7 +38,8 @@ public sealed class PowerMonitorInit : IPowerMonitorInit
IPowerSensorDiscoveryService discoveryService,
IOtherPowerCalculationService calculationService,
IPowerCostCalculationService costService,
IPowerMonitorEntityService entityService)
IPowerMonitorEntityService entityService,
IPowerNotificationService notificationService)
{
_haContext = haContext;
_logger = logger;
@@ -46,6 +49,7 @@ public sealed class PowerMonitorInit : IPowerMonitorInit
_calculationService = calculationService;
_costService = costService;
_entityService = entityService;
_notificationService = notificationService;
_ = InitializeAndScheduleAsync();
}
@@ -230,6 +234,8 @@ public sealed class PowerMonitorInit : IPowerMonitorInit
await _entityService.UpdateEntitiesAsync(context);
EvaluateHighPowerNotification(calculation.TotalPowerWatts);
_logger.LogDebug(
"Poll complete: total={Total}W, other={Other}W (smoothed), devices={Devices}, price={Price}",
calculation.TotalPowerWatts,
@@ -261,6 +267,22 @@ public sealed class PowerMonitorInit : IPowerMonitorInit
return 0;
}
private void EvaluateHighPowerNotification(double totalPowerWatts)
{
var isAboveThreshold = totalPowerWatts > _options.HighPowerThresholdWatts;
if (isAboveThreshold && !_highPowerNotificationActive)
{
_notificationService.NotifyHighPowerUsage(totalPowerWatts, _options.HighPowerThresholdWatts);
_highPowerNotificationActive = true;
}
else if (!isAboveThreshold && _highPowerNotificationActive)
{
_notificationService.DismissHighPowerNotification();
_highPowerNotificationActive = false;
}
}
private double? ReadMainMeterPower()
{
var state = _haContext.GetState(_options.MainMeterEntityId);