Skip to content

Commit

Permalink
Merge 0a485da into ef57a53
Browse files Browse the repository at this point in the history
  • Loading branch information
helto4real committed Apr 4, 2020
2 parents ef57a53 + 0a485da commit 94f2fea
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/DaemonRunner/DaemonRunner/Service/RunnerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
var storageFolder = Path.Combine(config.SourceFolder!, ".storage");
_daemonHost = new NetDaemonHost(new HassClient(_loggerFactory), new DataRepository(storageFolder), _loggerFactory);

sourceFolder ??= Path.Combine(config.SourceFolder!, "apps");
sourceFolder = Path.Combine(config.SourceFolder!, "apps");

// Automatically create source directories
if (!System.IO.Directory.Exists(sourceFolder))
System.IO.Directory.CreateDirectory(sourceFolder);

while (!stoppingToken.IsCancellationRequested)
{
Expand All @@ -85,20 +89,16 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
try
{
// Generate code if requested
var envGenEntities = Environment.GetEnvironmentVariable("HASS_GEN_ENTITIES");
var envGenEntities = Environment.GetEnvironmentVariable("HASS_GEN_ENTITIES") ?? config.GenerateEntitiesOnStartup?.ToString();
if (envGenEntities is object)
{
if (envGenEntities == "True")
{
var codeGen = new CodeGenerator();
var source = codeGen.GenerateCode("Netdaemon.Generated.Extensions",
_daemonHost.State.Select(n => n.EntityId).Distinct());
var genDirectory = System.IO.Path.Combine(sourceFolder, ".generated");

if (!System.IO.Directory.Exists(genDirectory))
System.IO.Directory.CreateDirectory(genDirectory);

System.IO.File.WriteAllText(System.IO.Path.Combine(genDirectory, "EntityExtensions.cs"), source);
System.IO.File.WriteAllText(System.IO.Path.Combine(sourceFolder, "_EntityExtensions.cs"), source);
}
}
using (var codeManager = new CodeManager(sourceFolder, _daemonHost.Logger))
Expand Down

0 comments on commit 94f2fea

Please sign in to comment.