Skip to content

Commit 5801c12

Browse files
authored
Pull config out of RunnerService (#158)
* Context * Post merge clean. * Update client. Add support for context. Move things around a little. * Fix name, also in an attempt to re-run tests on build server. * Pull config out of runner service, use .net core built-in configuration. Environment variables take preference over daemon_config. * * Break apart HA settings from NetDaemon settings * Remove HostBuilderExtensions - No need to generate a sample config file. It now comes with one (appsettings.json) - No need to add json or env variables as generic host add these automatically Runner.cs * Pulled HassIO config file to environment variables out and into its own method (readability) - Comment out HASSCLIENT_MSGLOGLEVEL, couldn't see any usages - Comment out HASS_RUN_PROJECT_FOLDER, couldn't see any usages * Register HA and ND settings in IOC RunnerService.cs * Inject settings * Extract generate entities code into its own method (readability) * PR comments. Default config host value should be localhost. * PR comments. * PR comments. * Move hosting code to Service. * PR comments. These are used by hass client. * Update some docker variables. * Allow changing of minimum log level by config or environment variables. * Update project folder variable.
1 parent 657ed80 commit 5801c12

File tree

18 files changed

+233
-330
lines changed

18 files changed

+233
-330
lines changed

.devcontainer/devcontainer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
"coverage-gutters.showLineCoverage": true,
1818
},
1919
"remoteEnv": {
20-
"HASS_TOKEN": "${localEnv:HASS_TOKEN}",
21-
"HASS_HOST": "${localEnv:HASS_HOST}",
22-
"HASS_PORT": "${localEnv:HASS_PORT}",
23-
"HASS_LOGLEVEL": "${localEnv:HASS_LOGLEVEL}",
24-
"HASS_GEN_ENTITIES": "${localEnv:HASS_GEN_ENTITIES}",
25-
"HASS_DAEMONAPPFOLDER": "${localEnv:HASS_DAEMONAPPFOLDER}"
20+
"HOMEASSISTANT__TOKEN": "${localEnv:HOMEASSISTANT__TOKEN}",
21+
"HOMEASSISTANT__HOST": "${localEnv:HOMEASSISTANT__HOST}",
22+
"HOMEASSISTANT__PORT": "${localEnv:HOMEASSISTANT__PORT}",
23+
"LOGGING__MINIMUMLEVEL": "${localEnv:LOGGING__MINIMUMLEVEL}",
24+
"NETDAEMON__GENERATEENTITIES": "${localEnv:NETDAEMON__GENERATEENTITIES}",
25+
"NETDAEMON__SOURCEFOLDER": "${localEnv:NETDAEMON__SOURCEFOLDER}"
2626
},
2727
"postCreateCommand": "dotnet restore && .devcontainer/install_prettyprompt.sh",
2828
// Uncomment the next line if you want to publish any ports.

Docker/rootfs/etc/services.d/NetDaemon/run

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ set -e
99
declare runtype="Service"
1010
declare daemondir="/daemon"
1111

12-
cd "${HASS_RUN_PROJECT_FOLDER}" || echo -e "\\033[31mCould not change directory to run project\\033[0m" >&2
12+
cd "${NETDAEMON__PROJECTFOLDER}" || echo -e "\\033[31mCould not change directory to run project\\033[0m" >&2
1313

14-
if [[ "${PWD}" != "${HASS_RUN_PROJECT_FOLDER}" ]]; then
14+
if [[ "${PWD}" != "${NETDAEMON__PROJECTFOLDER}" ]]; then
1515
exit 1
1616
fi
1717

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ COPY ./Docker/rootfs/etc/services.d/NetDaemon/run /rundaemon
1313
ENV \
1414
DOTNET_NOLOGO=true \
1515
DOTNET_CLI_TELEMETRY_OPTOUT=true \
16-
HASS_RUN_PROJECT_FOLDER=/usr/src/Service \
17-
HASS_HOST=localhost \
16+
NETDAEMON__PROJECTFOLDER=/usr/src/Service \
17+
HOMEASSISTANT__HOST=localhost \
18+
HOMEASSISTANT__PORT=8123 \
19+
HOMEASSISTANT__TOKEN=NOT_SET \
1820
HASSCLIENT_MSGLOGLEVEL=Default \
19-
HASS_PORT=8123 \
20-
HASS_TOKEN=NOT_SET \
21-
HASS_DAEMONAPPFOLDER=/data
21+
NETDAEMON__SOURCEFOLDER=/data
2222

2323

2424
ENTRYPOINT ["bash", "/rundaemon"]

src/DaemonRunner/DaemonRunner/DaemonRunner.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.5" />
2727
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.5" />
2828
<PackageReference Include="YamlDotNet" Version="8.1.2" />
29-
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
3029
</ItemGroup>
3130

3231
<ItemGroup>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Microsoft.Extensions.Hosting;
3+
using NetDaemon.Service;
4+
using NetDaemon.Service.Configuration;
5+
6+
namespace NetDaemon
7+
{
8+
public static class NetDaemonExtensions
9+
{
10+
public static IHostBuilder UseNetDaemon(this IHostBuilder hostBuilder)
11+
{
12+
return hostBuilder.ConfigureServices((context, services) =>
13+
{
14+
services.Configure<HomeAssistantSettings>(context.Configuration.GetSection("HomeAssistant"));
15+
services.Configure<NetDaemonSettings>(context.Configuration.GetSection("NetDaemon"));
16+
17+
services.AddHttpClient();
18+
services.AddHostedService<RunnerService>();
19+
});
20+
}
21+
}
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace NetDaemon.Service.Configuration
2+
{
3+
public class HomeAssistantSettings
4+
{
5+
public string Host { get; set; } = "localhost";
6+
public short Port { get; set; } = 8123;
7+
public bool Ssl { get; set; } = false;
8+
public string Token { get; set; } = string.Empty;
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace NetDaemon.Service.Configuration
2+
{
3+
public class NetDaemonSettings
4+
{
5+
public bool? GenerateEntities { get; set; } = false;
6+
public string? SourceFolder { get; set; } = null;
7+
public string? ProjectFolder { get; set; } = string.Empty;
8+
}
9+
}

src/DaemonRunner/DaemonRunner/Service/Extensions/HostBuilderExtensions.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/DaemonRunner/DaemonRunner/Service/Extensions/ServiceCollectionExtensions.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/DaemonRunner/DaemonRunner/Service/HostConfig.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)