Skip to content

Commit

Permalink
Pull config out of RunnerService (#158)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
asherw committed Jul 13, 2020
1 parent 657ed80 commit 5801c12
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 330 deletions.
12 changes: 6 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"coverage-gutters.showLineCoverage": true,
},
"remoteEnv": {
"HASS_TOKEN": "${localEnv:HASS_TOKEN}",
"HASS_HOST": "${localEnv:HASS_HOST}",
"HASS_PORT": "${localEnv:HASS_PORT}",
"HASS_LOGLEVEL": "${localEnv:HASS_LOGLEVEL}",
"HASS_GEN_ENTITIES": "${localEnv:HASS_GEN_ENTITIES}",
"HASS_DAEMONAPPFOLDER": "${localEnv:HASS_DAEMONAPPFOLDER}"
"HOMEASSISTANT__TOKEN": "${localEnv:HOMEASSISTANT__TOKEN}",
"HOMEASSISTANT__HOST": "${localEnv:HOMEASSISTANT__HOST}",
"HOMEASSISTANT__PORT": "${localEnv:HOMEASSISTANT__PORT}",
"LOGGING__MINIMUMLEVEL": "${localEnv:LOGGING__MINIMUMLEVEL}",
"NETDAEMON__GENERATEENTITIES": "${localEnv:NETDAEMON__GENERATEENTITIES}",
"NETDAEMON__SOURCEFOLDER": "${localEnv:NETDAEMON__SOURCEFOLDER}"
},
"postCreateCommand": "dotnet restore && .devcontainer/install_prettyprompt.sh",
// Uncomment the next line if you want to publish any ports.
Expand Down
4 changes: 2 additions & 2 deletions Docker/rootfs/etc/services.d/NetDaemon/run
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ set -e
declare runtype="Service"
declare daemondir="/daemon"

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

if [[ "${PWD}" != "${HASS_RUN_PROJECT_FOLDER}" ]]; then
if [[ "${PWD}" != "${NETDAEMON__PROJECTFOLDER}" ]]; then
exit 1
fi

Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ COPY ./Docker/rootfs/etc/services.d/NetDaemon/run /rundaemon
ENV \
DOTNET_NOLOGO=true \
DOTNET_CLI_TELEMETRY_OPTOUT=true \
HASS_RUN_PROJECT_FOLDER=/usr/src/Service \
HASS_HOST=localhost \
NETDAEMON__PROJECTFOLDER=/usr/src/Service \
HOMEASSISTANT__HOST=localhost \
HOMEASSISTANT__PORT=8123 \
HOMEASSISTANT__TOKEN=NOT_SET \
HASSCLIENT_MSGLOGLEVEL=Default \
HASS_PORT=8123 \
HASS_TOKEN=NOT_SET \
HASS_DAEMONAPPFOLDER=/data
NETDAEMON__SOURCEFOLDER=/data


ENTRYPOINT ["bash", "/rundaemon"]
1 change: 0 additions & 1 deletion src/DaemonRunner/DaemonRunner/DaemonRunner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.5" />
<PackageReference Include="YamlDotNet" Version="8.1.2" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
22 changes: 22 additions & 0 deletions src/DaemonRunner/DaemonRunner/NetDaemonExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NetDaemon.Service;
using NetDaemon.Service.Configuration;

namespace NetDaemon
{
public static class NetDaemonExtensions
{
public static IHostBuilder UseNetDaemon(this IHostBuilder hostBuilder)
{
return hostBuilder.ConfigureServices((context, services) =>
{
services.Configure<HomeAssistantSettings>(context.Configuration.GetSection("HomeAssistant"));
services.Configure<NetDaemonSettings>(context.Configuration.GetSection("NetDaemon"));
services.AddHttpClient();
services.AddHostedService<RunnerService>();
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace NetDaemon.Service.Configuration
{
public class HomeAssistantSettings
{
public string Host { get; set; } = "localhost";
public short Port { get; set; } = 8123;
public bool Ssl { get; set; } = false;
public string Token { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NetDaemon.Service.Configuration
{
public class NetDaemonSettings
{
public bool? GenerateEntities { get; set; } = false;
public string? SourceFolder { get; set; } = null;
public string? ProjectFolder { get; set; } = string.Empty;
}
}

This file was deleted.

This file was deleted.

29 changes: 0 additions & 29 deletions src/DaemonRunner/DaemonRunner/Service/HostConfig.cs

This file was deleted.

79 changes: 0 additions & 79 deletions src/DaemonRunner/DaemonRunner/Service/Runner.cs

This file was deleted.

Loading

0 comments on commit 5801c12

Please sign in to comment.