feat: add PowerMonitor service registration and default configuration tests
This commit is contained in:
@@ -6,6 +6,7 @@ public sealed class PowerMonitorOptions
|
||||
{
|
||||
public const string SectionName = "PowerMonitor";
|
||||
|
||||
public bool Enabled { get; set; } = true;
|
||||
public string MainMeterEntityId { get; set; } = string.Empty;
|
||||
public int PollIntervalSeconds { get; set; } = PowerMonitorConsts.DefaultPollIntervalSeconds;
|
||||
public int SmoothingWindowSize { get; set; } = PowerMonitorConsts.DefaultSmoothingWindowSize;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NetDaemon.AppModel;
|
||||
using PowerMonitorManager.Interface;
|
||||
using PowerMonitorManager.Models;
|
||||
|
||||
namespace PowerMonitorManager;
|
||||
|
||||
public static class PowerMonitorServiceRegistration
|
||||
{
|
||||
public static IServiceCollection AddPowerMonitor(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var options = configuration
|
||||
.GetSection(PowerMonitorOptions.SectionName)
|
||||
.Get<PowerMonitorOptions>() ?? new PowerMonitorOptions();
|
||||
|
||||
if (!options.Enabled)
|
||||
{
|
||||
return services;
|
||||
}
|
||||
|
||||
services
|
||||
.AddNetDaemonApp<PowerMonitorInit>()
|
||||
.AddScoped<IPowerSensorDiscoveryService, PowerSensorDiscoveryService>()
|
||||
.AddSingleton<IOtherPowerCalculationService, OtherPowerCalculationService>()
|
||||
.AddSingleton<IPowerCostCalculationService, PowerCostCalculationService>()
|
||||
.AddTransient<IPowerMonitorEntityService, PowerMonitorEntityService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user