Add shared test data builders and Qodana configuration
- Extract per-monitor *TestData helper classes and rework tests to use them - Add boiler run-time tracker abstraction (implementation pending) - Drop unused NordPool init/update-result types and stale PLAN.md - Add qodana.yaml with the inspection set to keep the analysis focused
This commit is contained in:
@@ -64,7 +64,7 @@ public sealed class PowerMonitorEntityService(
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var entities = sensors.SelectMany(GetDeviceEntities).ToList();
|
||||
var entities = sensors.SelectMany(GetPowerDeviceEntitiesNames).ToList();
|
||||
var tasks = entities.Select(async entity =>
|
||||
{
|
||||
try
|
||||
@@ -139,14 +139,16 @@ public sealed class PowerMonitorEntityService(
|
||||
logger.LogInformation("All PowerMonitor entity states reset to defaults");
|
||||
}
|
||||
|
||||
public async Task CleanupEntitiesAsync(CancellationToken cancellationToken = default)
|
||||
public async Task RemoveSystemEntitiesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
try
|
||||
{
|
||||
var tasks = SystemEntityIds.Select(id => entityManager.RemoveEntity(id));
|
||||
var tasks = SystemEntityIds.Select(entityManager.RemoveEntity);
|
||||
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
|
||||
logger.LogInformation("PowerMonitor system entities cleaned up");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -156,16 +158,19 @@ public sealed class PowerMonitorEntityService(
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CleanupDeviceEntitiesAsync(IReadOnlyList<string> removedDeviceNames, CancellationToken cancellationToken = default)
|
||||
public async Task RemoveDeviceEntitiesAsync(IReadOnlyList<string> removedDeviceNames, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var entityIds = removedDeviceNames.SelectMany(GetDeviceCostEntityIds).ToList();
|
||||
|
||||
var tasks = entityIds.Select(async id =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await entityManager.RemoveEntity(id).ConfigureAwait(false);
|
||||
|
||||
logger.LogDebug("Entity removed: {EntityId}", id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -175,6 +180,7 @@ public sealed class PowerMonitorEntityService(
|
||||
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
internal ICollection<PowerMonitorEntity> GetSystemEntitiesList()
|
||||
{
|
||||
@@ -222,27 +228,27 @@ public sealed class PowerMonitorEntityService(
|
||||
};
|
||||
}
|
||||
|
||||
internal static IEnumerable<PowerMonitorEntity> GetDeviceEntities(PowerSensorInfo sensor)
|
||||
internal static IEnumerable<PowerMonitorEntity> GetPowerDeviceEntitiesNames(PowerSensorInfo sensor)
|
||||
{
|
||||
var deviceName = PowerSensorDiscoveryService.ExtractDeviceName(sensor.EntityId);
|
||||
return new[]
|
||||
{
|
||||
return
|
||||
[
|
||||
CreateCostEntity($"powermonitor_{deviceName}_cost_15min", $"{sensor.FriendlyName} cost (15 min)"),
|
||||
CreateCostEntity($"powermonitor_{deviceName}_cost_1h", $"{sensor.FriendlyName} cost (1h)"),
|
||||
CreateCostEntity($"powermonitor_{deviceName}_cost_daily", $"{sensor.FriendlyName} cost (daily)"),
|
||||
CreateCostEntity($"powermonitor_{deviceName}_cost_monthly", $"{sensor.FriendlyName} cost (monthly)")
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
internal static IEnumerable<string> GetDeviceCostEntityIds(string deviceName)
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
return
|
||||
[
|
||||
$"sensor.powermonitor_{deviceName}_cost_15min",
|
||||
$"sensor.powermonitor_{deviceName}_cost_1h",
|
||||
$"sensor.powermonitor_{deviceName}_cost_daily",
|
||||
$"sensor.powermonitor_{deviceName}_cost_monthly"
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
private async Task UpdateTotalPowerAsync(PowerUpdateContext context, string timestamp)
|
||||
|
||||
Reference in New Issue
Block a user