From 45b0c11f1c48489096345c9c085bfed7dab5ec16 Mon Sep 17 00:00:00 2001 From: Frank Bakker Date: Sat, 27 Apr 2024 21:32:07 +0200 Subject: [PATCH] Clean debug code --- src/debug/DebugHost/apps/HelloApp/HelloApp.cs | 39 ++++--------------- src/debug/DebugHost/apps_src/hellow.cs | 2 +- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/debug/DebugHost/apps/HelloApp/HelloApp.cs b/src/debug/DebugHost/apps/HelloApp/HelloApp.cs index 50f6fa28f..c61bb667a 100644 --- a/src/debug/DebugHost/apps/HelloApp/HelloApp.cs +++ b/src/debug/DebugHost/apps/HelloApp/HelloApp.cs @@ -2,27 +2,23 @@ using Microsoft.Extensions.Logging; using NetDaemon.AppModel; using NetDaemon.HassModel; -using NetDaemon.HassModel.Entities; namespace Apps; [NetDaemonApp] [Focus] -public sealed class HelloApp2 : IAsyncDisposable +public sealed class HelloApp : IAsyncDisposable { - private readonly ILogger _logger; + private readonly ILogger _logger; - public HelloApp2(IHaContext ha, ILogger logger, IHaRegistry registry) + public HelloApp(IHaContext ha, ILogger logger) { - var home = new Home(registry); - var x = home.Floors.Downstairs.Areas.SelectMany(a => a.Entities); - _logger = logger; - var boilerConnected = ha.Entity("switch.heating_valve_kitchen"); - var labels = boilerConnected.Registration?.Labels; - var all = registry.Entities; - var criticalEntities = ha.GetAllEntities().Where(e => e.Registration?.Labels.Any(l => l.Name == "critical") ?? false); - //criticalEntities.StateChanges().Where(s => s.New?.State == "unavailable").Subscribe(e => logger.LogCritical("Entity {Entity} became unavailable", e.Entity.EntityId)); + ha.Events.Where(n => n.EventType == "test_event").Subscribe( _ => + { + logger.LogInformation("Hello testevent"); + }); + ha.CallService("notify", "persistent_notification", data: new { message = "Notify me", title = "Hello world!" }); } public async ValueTask DisposeAsync() @@ -32,22 +28,3 @@ public async ValueTask DisposeAsync() //return ValueTask.CompletedTask; } } - -record Home(IHaRegistry HaRegistry) -{ - public MyFloors Floors => new MyFloors(HaRegistry); -} - -record MyFloors(IHaRegistry Registry) -{ - public Floor Downstairs => Registry.GetFloor("downstairs")!; - public Floor Upstairs => Registry.GetFloor("upstairs")!; - public Floor Attic => Registry.GetFloor("upstairs")!; -} - -record AtticFloorAreas(IHaRegistry HaRegistry) -{ - public IEnumerable? Areas { get; } - public Area Study => HaRegistry.GetArea("study")!; - -} diff --git a/src/debug/DebugHost/apps_src/hellow.cs b/src/debug/DebugHost/apps_src/hellow.cs index e936d25f8..0e3d5d569 100644 --- a/src/debug/DebugHost/apps_src/hellow.cs +++ b/src/debug/DebugHost/apps_src/hellow.cs @@ -6,7 +6,7 @@ namespace Apps; [NetDaemonApp] -//[Focus] +[Focus] public sealed class HelloAppSrc : IAsyncDisposable { private readonly ILogger _logger;