-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
245 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
my_app: | ||
class: BatteryManager | ||
# HelloWorldSecret: !secret test_secret | ||
# dependencies: | ||
# - global_app | ||
dependencies: | ||
- global_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/DaemonRunner/DaemonRunner/Service/API/ApiController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using NetDaemon.Common; | ||
using NetDaemon.Daemon; | ||
using NetDaemon.Service.Configuration; | ||
|
||
namespace NetDaemon.Service.Api | ||
{ | ||
|
||
[ApiController] | ||
[Route("api")] | ||
public class ApiController : ControllerBase | ||
{ | ||
private readonly ILogger<ApiController> _logger; | ||
private readonly NetDaemonSettings? _netdaemonSettings; | ||
private readonly HomeAssistantSettings? _homeassistantSettings; | ||
|
||
private readonly NetDaemonHost? _host; | ||
public ApiController( | ||
IOptions<NetDaemonSettings> netDaemonSettings, | ||
IOptions<HomeAssistantSettings> homeAssistantSettings, | ||
ILoggerFactory? loggerFactory = null, | ||
NetDaemonHost? host = null | ||
) | ||
{ | ||
_logger = loggerFactory.CreateLogger<ApiController>(); | ||
_host = host; | ||
_netdaemonSettings = netDaemonSettings.Value; | ||
_homeassistantSettings = homeAssistantSettings.Value; | ||
} | ||
|
||
[Route("settings")] | ||
[HttpGet] | ||
public ApiConfig? Config() | ||
{ | ||
var tempResult = new ApiConfig | ||
{ | ||
DaemonSettings = _netdaemonSettings, | ||
HomeAssistantSettings = _homeassistantSettings | ||
}; | ||
// For first release we do not expose the token | ||
if (tempResult.HomeAssistantSettings is object) | ||
{ | ||
tempResult.HomeAssistantSettings.Token = ""; | ||
} | ||
return tempResult; | ||
} | ||
|
||
[HttpGet] | ||
[Route("apps")] | ||
public IEnumerable<ApiApplication>? Apps() | ||
{ | ||
return _host?.AllAppInstances.Select(n => new ApiApplication() | ||
{ | ||
Id = n.Id, | ||
Dependencies = n.Dependencies, | ||
IsEnabled = n.IsEnabled | ||
}); | ||
} | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.Generic; | ||
using NetDaemon.Service.Configuration; | ||
|
||
namespace NetDaemon.Service.Api | ||
{ | ||
|
||
public class ApiApplication | ||
{ | ||
public string? Id { get; set; } | ||
public IEnumerable<string>? Dependencies { get; set; } | ||
|
||
public bool IsEnabled { get; set; } | ||
|
||
} | ||
|
||
public class ApiConfig | ||
{ | ||
public NetDaemonSettings? DaemonSettings { get; set; } | ||
public HomeAssistantSettings? HomeAssistantSettings { get; set; } | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Reflection; | ||
using JoySoftware.HomeAssistant.Client; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc.ApplicationParts; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NetDaemon.Daemon; | ||
using NetDaemon.Daemon.Storage; | ||
using NetDaemon.Service.Configuration; | ||
using NetDaemon.Service; | ||
using Microsoft.Extensions.Options; | ||
using System.IO; | ||
using Microsoft.Extensions.Hosting; | ||
using NetDaemon.Common; | ||
|
||
namespace NetDaemon.Service | ||
{ | ||
public class ApiStartup | ||
{ | ||
public ApiStartup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
// services.Configure<HomeAssistantSettings>(Context.Configuration.GetSection("HomeAssistant")); | ||
// services.Configure<NetDaemonSettings>(context.Configuration.GetSection("NetDaemon")); | ||
services.AddHostedService<RunnerService>(); | ||
services.AddTransient<IHassClient, HassClient>(); | ||
services.AddTransient<IDataRepository>(n => new DataRepository(Path.Combine(n.GetRequiredService<IOptions<NetDaemonSettings>>().Value.SourceFolder!, ".storage"))); | ||
services.AddTransient<IHttpHandler, NetDaemon.Daemon.HttpHandler>(); | ||
services.AddSingleton<NetDaemonHost>(); | ||
services.AddHttpClient(); | ||
services.AddControllers().PartManager.ApplicationParts.Add(new AssemblyPart(Assembly.GetExecutingAssembly())); | ||
services.AddRouting(); | ||
} | ||
|
||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
// app.UseHttpsRedirection(); | ||
|
||
app.UseRouting(); | ||
|
||
// app.UseAuthorization(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapControllers(); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.