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:
@@ -11,7 +11,8 @@ public static class CustomLoggingProvider
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Production"}.json", optional: true)
|
||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Production"}.json",
|
||||
true)
|
||||
.Build();
|
||||
|
||||
var logger = new LoggerConfiguration()
|
||||
@@ -20,4 +21,4 @@ public static class CustomLoggingProvider
|
||||
|
||||
return builder.UseSerilog(logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,11 @@
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</None>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="appsettings.development.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
|
||||
</None>
|
||||
<None Update="$(MSBuildProjectDir)appsettings.Production.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
@@ -33,35 +33,35 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Target Name="AfterPublishMessage" AfterTargets="Publish">
|
||||
<Message Text="Publish done! Copy all content in directory: $(PublishDir) to the `/config/netdaemon4' folder for add-on or your custom folder to deploy." Importance="high" />
|
||||
<Message Text="Publish done! Copy all content in directory: $(PublishDir) to the `/config/netdaemon4' folder for add-on or your custom folder to deploy." Importance="high"/>
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="17.0.0" />
|
||||
<PackageReference Include="NetDaemon.AppModel" Version="26.43.1" />
|
||||
<PackageReference Include="NetDaemon.Runtime" Version="26.43.1" />
|
||||
<PackageReference Include="NetDaemon.HassModel" Version="26.43.1" />
|
||||
<PackageReference Include="NetDaemon.Client" Version="26.43.1" />
|
||||
<PackageReference Include="NetDaemon.Extensions.Scheduling" Version="26.43.1" />
|
||||
<PackageReference Include="NetDaemon.Extensions.Logging" Version="26.43.1" />
|
||||
<PackageReference Include="NetDaemon.Extensions.Tts" Version="26.43.1" />
|
||||
<PackageReference Include="AutoMapper" Version="17.0.0"/>
|
||||
<PackageReference Include="NetDaemon.AppModel" Version="26.43.1"/>
|
||||
<PackageReference Include="NetDaemon.Runtime" Version="26.43.1"/>
|
||||
<PackageReference Include="NetDaemon.HassModel" Version="26.43.1"/>
|
||||
<PackageReference Include="NetDaemon.Client" Version="26.43.1"/>
|
||||
<PackageReference Include="NetDaemon.Extensions.Scheduling" Version="26.43.1"/>
|
||||
<PackageReference Include="NetDaemon.Extensions.Logging" Version="26.43.1"/>
|
||||
<PackageReference Include="NetDaemon.Extensions.Tts" Version="26.43.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BoilerMonitor.Manager\BoilerMonitor.Manager.csproj" />
|
||||
<ProjectReference Include="..\BoilerMonitor.Models\BoilerMonitor.Models.csproj" />
|
||||
<ProjectReference Include="..\HomeAssistant.Entities\HomeAssistant.Entities.csproj" />
|
||||
<ProjectReference Include="..\Mappings\Mappings.csproj" />
|
||||
<ProjectReference Include="..\NordPool.Manager\NordPool.Manager.csproj" />
|
||||
<ProjectReference Include="..\NordPool.Models\NordPool.Models.csproj" />
|
||||
<ProjectReference Include="..\PowerMonitor.Manager\PowerMonitor.Manager.csproj" />
|
||||
<ProjectReference Include="..\PowerMonitor.Models\PowerMonitor.Models.csproj" />
|
||||
<ProjectReference Include="..\ShowerMonitor.Manager\ShowerMonitor.Manager.csproj" />
|
||||
<ProjectReference Include="..\ShowerMonitor.Models\ShowerMonitor.Models.csproj" />
|
||||
<ProjectReference Include="..\LightMonitor.Manager\LightMonitor.Manager.csproj" />
|
||||
<ProjectReference Include="..\LightMonitor.Models\LightMonitor.Models.csproj" />
|
||||
<ProjectReference Include="..\BatteryMonitor.Manager\BatteryMonitor.Manager.csproj" />
|
||||
<ProjectReference Include="..\BatteryMonitor.Models\BatteryMonitor.Models.csproj" />
|
||||
<ProjectReference Include="..\LeakMonitor.Manager\LeakMonitor.Manager.csproj" />
|
||||
<ProjectReference Include="..\BoilerMonitor.Manager\BoilerMonitor.Manager.csproj"/>
|
||||
<ProjectReference Include="..\BoilerMonitor.Models\BoilerMonitor.Models.csproj"/>
|
||||
<ProjectReference Include="..\HomeAssistant.Entities\HomeAssistant.Entities.csproj"/>
|
||||
<ProjectReference Include="..\Mappings\Mappings.csproj"/>
|
||||
<ProjectReference Include="..\NordPool.Manager\NordPool.Manager.csproj"/>
|
||||
<ProjectReference Include="..\NordPool.Models\NordPool.Models.csproj"/>
|
||||
<ProjectReference Include="..\PowerMonitor.Manager\PowerMonitor.Manager.csproj"/>
|
||||
<ProjectReference Include="..\PowerMonitor.Models\PowerMonitor.Models.csproj"/>
|
||||
<ProjectReference Include="..\ShowerMonitor.Manager\ShowerMonitor.Manager.csproj"/>
|
||||
<ProjectReference Include="..\ShowerMonitor.Models\ShowerMonitor.Models.csproj"/>
|
||||
<ProjectReference Include="..\LightMonitor.Manager\LightMonitor.Manager.csproj"/>
|
||||
<ProjectReference Include="..\LightMonitor.Models\LightMonitor.Models.csproj"/>
|
||||
<ProjectReference Include="..\BatteryMonitor.Manager\BatteryMonitor.Manager.csproj"/>
|
||||
<ProjectReference Include="..\BatteryMonitor.Models\BatteryMonitor.Models.csproj"/>
|
||||
<ProjectReference Include="..\LeakMonitor.Manager\LeakMonitor.Manager.csproj"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -25,9 +25,9 @@ public sealed class MqttRecreateApp
|
||||
private static readonly string[] AppDaemonIdentifiers = ["appdaemon"];
|
||||
|
||||
private readonly IHaContext _haContext;
|
||||
private readonly ILogger<MqttRecreateApp> _logger;
|
||||
private readonly IMqttEntityManager _mqttEntityManager;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly ILogger<MqttRecreateApp> _logger;
|
||||
|
||||
public MqttRecreateApp(
|
||||
IHaContext haContext,
|
||||
@@ -69,9 +69,7 @@ public sealed class MqttRecreateApp
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
if (_logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
_logger.LogInformation("Recreate-all button created: {EntityId}", RecreateButtonEntityId);
|
||||
}
|
||||
|
||||
var button = new Entity(_haContext, RecreateButtonEntityId);
|
||||
button.StateChanges()
|
||||
@@ -204,21 +202,17 @@ public sealed class MqttRecreateApp
|
||||
var state = _haContext.GetState(NordPoolPriceEntityId);
|
||||
if (state?.Attributes is IDictionary<string, object> attributes &&
|
||||
attributes.TryGetValue("unit_of_measurement", out var value))
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
string s => s,
|
||||
JsonElement { ValueKind: JsonValueKind.String } je => je.GetString(),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_logger.IsEnabled(LogLevel.Debug))
|
||||
{
|
||||
_logger.LogDebug(ex, "Could not read unit_of_measurement for {EntityId}", NordPoolPriceEntityId);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -1,21 +1,28 @@
|
||||
# Project template for binary deploy
|
||||
|
||||
This is the project template for binary deploy. This allows you to build a binary package and deploy it to NetDaemon.
|
||||
|
||||
This is generated using NetDaemon runtime version 5 and .NET 9.
|
||||
|
||||
## Getting started
|
||||
Please see [netdaemon.xyz](https://netdaemon.xyz/docs) more information about getting starting developing apps for Home Assistant using NetDaemon.
|
||||
|
||||
Please see [netdaemon.xyz](https://netdaemon.xyz/docs) more information about getting starting developing apps for Home
|
||||
Assistant using NetDaemon.
|
||||
|
||||
Please add code generation features in `program.cs` when using code generation features by removing comments!
|
||||
|
||||
## Use the code generator
|
||||
|
||||
See https://netdaemon.xyz/docs/hass_model/hass_model_codegen
|
||||
|
||||
## Issues
|
||||
|
||||
- If you have issues or suggestions of improvements to this template, please [add an issue](https://github.com/net-daemon/netdaemon-app-template)
|
||||
- If you have issues or suggestions of improvements to NetDaemon, please [add an issue](https://github.com/net-daemon/netdaemon/issues)
|
||||
- If you have issues or suggestions of improvements to this template,
|
||||
please [add an issue](https://github.com/net-daemon/netdaemon-app-template)
|
||||
- If you have issues or suggestions of improvements to NetDaemon,
|
||||
please [add an issue](https://github.com/net-daemon/netdaemon/issues)
|
||||
|
||||
## Discuss the NetDaemon
|
||||
|
||||
Please [join the Discord server](https://discord.gg/K3xwfcX) to get support or if you want to contribute and help others.
|
||||
Please [join the Discord server](https://discord.gg/K3xwfcX) to get support or if you want to contribute and help
|
||||
others.
|
||||
|
||||
@@ -1,84 +1,87 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Warning"
|
||||
},
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Console"
|
||||
}
|
||||
]
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Warning"
|
||||
},
|
||||
"NetDaemon": {
|
||||
"ApplicationConfigurationFolder": "./apps"
|
||||
},
|
||||
"CodeGeneration": {
|
||||
"Namespace": "HomeAssistantGenerated",
|
||||
"OutputFile": "HomeAssistantGenerated.cs",
|
||||
"UseAttributeBaseClasses" : "false"
|
||||
},
|
||||
"NordPool": {
|
||||
"CleanupEntitiesOnStartup": false
|
||||
},
|
||||
"BoilerMonitor": {
|
||||
"Enabled": true,
|
||||
"CleanupEntitiesOnStartup": false
|
||||
},
|
||||
"ShowerMonitor": {
|
||||
"Enabled": true,
|
||||
"CleanupEntitiesOnStartup": false,
|
||||
"BathroomHumidityEntityId": "sensor.bathroom_humidity",
|
||||
"MainHomeHumidityEntityId": "sensor.main_home_humidity",
|
||||
"BathroomTemperatureEntityId": "sensor.bathroom_temperature",
|
||||
"ExhaustFanEntityId": "switch.exhaust_fan",
|
||||
"PollIntervalSeconds": 5,
|
||||
"SpikeRateThreshold": 4.0,
|
||||
"MinDifferentialHumidity": 8.0,
|
||||
"PeakHumidityThreshold": 58.0,
|
||||
"ConfirmationWindowMinutes": 2,
|
||||
"RecoveryDifferentialThreshold": 5.0,
|
||||
"MaxShowerDurationMinutes": 60,
|
||||
"FanRunAfterShowerMinutes": 10,
|
||||
"RateWindowSize": 5
|
||||
},
|
||||
"LightMonitor": {
|
||||
"Enabled": true,
|
||||
"LightEntityId": "light.sonoff_1002214d40",
|
||||
"SunEntityId": "sun.sun",
|
||||
"PersonEntityIds": ["person.marius", "person.erika"]
|
||||
},
|
||||
"BatteryMonitor": {
|
||||
"Enabled": true,
|
||||
"BatteryThresholdPercent": 5
|
||||
},
|
||||
"LeakMonitor": {
|
||||
"Enabled": true,
|
||||
"SensorEntityIds": [
|
||||
"binary_sensor.aquarium_leak_sensor",
|
||||
"binary_sensor.boiler_moisture"
|
||||
],
|
||||
"NotificationCooldownMinutes": 5
|
||||
},
|
||||
"PowerMonitor": {
|
||||
"Enabled": false,
|
||||
"MainMeterEntityId": "sensor.sonoff_100267d63f_power",
|
||||
"PollIntervalSeconds": 1,
|
||||
"SmoothingWindowSize": 10,
|
||||
"AnomalyThresholdWatts": 500,
|
||||
"HighPowerThresholdWatts": 6000,
|
||||
"EnforceLimitEnabled": false,
|
||||
"PowerLimitWatts": 5500,
|
||||
"RecoverySeconds": 600,
|
||||
"LimitCooldownSeconds": 30,
|
||||
"EnforceSwitchOffEntityIds": [
|
||||
"switch.sonoff_1002230e32"
|
||||
],
|
||||
"PauseAndRestoreEntityIds": [
|
||||
"switch.boilermonitor_auto_management"
|
||||
],
|
||||
"ExcludedSensorPatterns": [
|
||||
"sensor.nordpool_*",
|
||||
"sensor.powermonitor_*"
|
||||
]
|
||||
}
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Console"
|
||||
}
|
||||
]
|
||||
},
|
||||
"NetDaemon": {
|
||||
"ApplicationConfigurationFolder": "./apps"
|
||||
},
|
||||
"CodeGeneration": {
|
||||
"Namespace": "HomeAssistantGenerated",
|
||||
"OutputFile": "HomeAssistantGenerated.cs",
|
||||
"UseAttributeBaseClasses": "false"
|
||||
},
|
||||
"NordPool": {
|
||||
"CleanupEntitiesOnStartup": false
|
||||
},
|
||||
"BoilerMonitor": {
|
||||
"Enabled": true,
|
||||
"CleanupEntitiesOnStartup": false
|
||||
},
|
||||
"ShowerMonitor": {
|
||||
"Enabled": true,
|
||||
"CleanupEntitiesOnStartup": false,
|
||||
"BathroomHumidityEntityId": "sensor.bathroom_humidity",
|
||||
"MainHomeHumidityEntityId": "sensor.main_home_humidity",
|
||||
"BathroomTemperatureEntityId": "sensor.bathroom_temperature",
|
||||
"ExhaustFanEntityId": "switch.exhaust_fan",
|
||||
"PollIntervalSeconds": 5,
|
||||
"SpikeRateThreshold": 4.0,
|
||||
"MinDifferentialHumidity": 8.0,
|
||||
"PeakHumidityThreshold": 58.0,
|
||||
"ConfirmationWindowMinutes": 2,
|
||||
"RecoveryDifferentialThreshold": 5.0,
|
||||
"MaxShowerDurationMinutes": 60,
|
||||
"FanRunAfterShowerMinutes": 10,
|
||||
"RateWindowSize": 5
|
||||
},
|
||||
"LightMonitor": {
|
||||
"Enabled": true,
|
||||
"LightEntityId": "light.sonoff_1002214d40",
|
||||
"SunEntityId": "sun.sun",
|
||||
"PersonEntityIds": [
|
||||
"person.marius",
|
||||
"person.erika"
|
||||
]
|
||||
},
|
||||
"BatteryMonitor": {
|
||||
"Enabled": true,
|
||||
"BatteryThresholdPercent": 5
|
||||
},
|
||||
"LeakMonitor": {
|
||||
"Enabled": true,
|
||||
"SensorEntityIds": [
|
||||
"binary_sensor.aquarium_leak_sensor",
|
||||
"binary_sensor.boiler_moisture"
|
||||
],
|
||||
"NotificationCooldownMinutes": 5
|
||||
},
|
||||
"PowerMonitor": {
|
||||
"Enabled": false,
|
||||
"MainMeterEntityId": "sensor.sonoff_100267d63f_power",
|
||||
"PollIntervalSeconds": 1,
|
||||
"SmoothingWindowSize": 10,
|
||||
"AnomalyThresholdWatts": 500,
|
||||
"HighPowerThresholdWatts": 6000,
|
||||
"EnforceLimitEnabled": false,
|
||||
"PowerLimitWatts": 5500,
|
||||
"RecoverySeconds": 600,
|
||||
"LimitCooldownSeconds": 30,
|
||||
"EnforceSwitchOffEntityIds": [
|
||||
"switch.sonoff_1002230e32"
|
||||
],
|
||||
"PauseAndRestoreEntityIds": [
|
||||
"switch.boilermonitor_auto_management"
|
||||
],
|
||||
"ExcludedSensorPatterns": [
|
||||
"sensor.nordpool_*",
|
||||
"sensor.powermonitor_*"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using BatteryMonitorManager;
|
||||
using BatteryMonitorManager.Models;
|
||||
using BoilerMonitor.Models;
|
||||
using BoilerMonitorManager;
|
||||
using BoilerMonitorManager.Models;
|
||||
using HomeAssistant.Entities;
|
||||
using HomeAssistant.Entities.Interfaces;
|
||||
using HomeAssistantGenerated;
|
||||
using HomeAssistantServer;
|
||||
using LeakMonitorManager;
|
||||
using LeakMonitorManager.Models;
|
||||
using LightMonitor.Models;
|
||||
using LightMonitorManager;
|
||||
using Mappings;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@@ -13,19 +21,12 @@ using NetDaemon.Extensions.MqttEntityManager;
|
||||
using NetDaemon.Extensions.Scheduler;
|
||||
using NetDaemon.Extensions.Tts;
|
||||
using NetDaemon.Runtime;
|
||||
using BoilerMonitorManager;
|
||||
using BoilerMonitorManager.Models;
|
||||
using NordPoolManager;
|
||||
using NordPoolManager.Models;
|
||||
using PowerMonitorManager;
|
||||
using PowerMonitorManager.Models;
|
||||
using ShowerMonitorManager;
|
||||
using ShowerMonitorManager.Models;
|
||||
using LightMonitorManager;
|
||||
using BatteryMonitorManager;
|
||||
using BatteryMonitorManager.Models;
|
||||
using LeakMonitorManager;
|
||||
using LeakMonitorManager.Models;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -51,7 +52,7 @@ try
|
||||
})
|
||||
.AddTransient<IEntityManager, EntityManager>()
|
||||
.AddSingleton(TimeProvider.System)
|
||||
.AddScoped<BoilerMonitor.Models.IBoilerConfigReader, BoilerConfigReader>()
|
||||
.AddScoped<IBoilerConfigReader, BoilerConfigReader>()
|
||||
.Configure<NordPoolOptions>(context.Configuration.GetSection(NordPoolOptions.SectionName))
|
||||
.AddNordPool()
|
||||
.Configure<PowerMonitorOptions>(context.Configuration.GetSection(PowerMonitorOptions.SectionName))
|
||||
|
||||
Reference in New Issue
Block a user