Skip to content

Commit

Permalink
Added support for floors and labels to the ServiceTarget class
Browse files Browse the repository at this point in the history
  • Loading branch information
helto4real committed Apr 28, 2024
1 parent 917adf5 commit 59b8482
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ public record HassTarget
/// </summary>
[JsonPropertyName("area_id")]
public IReadOnlyCollection<string>? AreaIds { get; init; }
}

/// <summary>
/// Zero or more floor ids to target with the service call
/// </summary>
[JsonPropertyName("floor_id")]
public IReadOnlyCollection<string>? FloorIds { get; init; }

/// <summary>
/// Zero or more floor ids to target with the service call
/// </summary>
[JsonPropertyName("label_id")]
public IReadOnlyCollection<string>? LabelIds { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public static StateChange Map(this HassStateChangedEventData source, IHaContext
{
AreaIds = target.AreaIds,
DeviceIds = target.DeviceIds,
EntityIds = target.EntityIds
EntityIds = target.EntityIds,
FloorIds = target.FloorIds,
LabelIds = target.LabelIds
};
}

Expand Down
12 changes: 11 additions & 1 deletion src/HassModel/NetDeamon.HassModel/ServiceTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ public ServiceTarget()
/// Ids of Areas to invoke a service on
/// </summary>
public IReadOnlyCollection<string>? AreaIds { get; init; }
}

/// <summary>
/// Ids of floors to invoke a service on
/// </summary>
public IReadOnlyCollection<string>? FloorIds { get; init; }

/// <summary>
/// Ids of labels to invoke a service on
/// </summary>
public IReadOnlyCollection<string>? LabelIds { get; init; }
}
23 changes: 23 additions & 0 deletions src/debug/DebugHost/apps/HaRegistry/RegistryApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Reactive.Linq;
using Microsoft.Extensions.Logging;
using NetDaemon.AppModel;
using NetDaemon.HassModel;
using NetDaemon.HassModel.Entities;
namespace Apps;

[NetDaemonApp]
[Focus]
public sealed class RegistryApp
{
public RegistryApp(IHaRegistry haRegistry, IHaContext ha)
{
// var floor = haRegistry.GetFloor("upstairs");
// var upstairsAreas = floor.Areas;
// var upstairsBooleans = upstairsAreas
// .SelectMany(n => n.Entities
// .Where(x => x.EntityId.StartsWith("input_boolean.")));
//
// upstairsBooleans.ToList().ForEach(x => x.CallService("toggle"));
ha.CallService("input_boolean", "toggle", new ServiceTarget{ FloorIds = new string[] { "upstairs" } });

Check failure on line 21 in src/debug/DebugHost/apps/HaRegistry/RegistryApp.cs

View workflow job for this annotation

GitHub Actions / 🔨 Build sources (CI)

Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1861) [/home/runner/work/netdaemon/netdaemon/src/debug/DebugHost/DebugHost.csproj]

Check failure on line 21 in src/debug/DebugHost/apps/HaRegistry/RegistryApp.cs

View workflow job for this annotation

GitHub Actions / 🔨 Build sources (CI)

Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1861) [/home/runner/work/netdaemon/netdaemon/src/debug/DebugHost/DebugHost.csproj]
}
}
2 changes: 1 addition & 1 deletion src/debug/DebugHost/apps/HelloApp/HelloApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Apps;

[NetDaemonApp]
[Focus]
//[Focus]
public sealed class HelloApp : IAsyncDisposable
{
private readonly ILogger<HelloApp> _logger;
Expand Down
2 changes: 1 addition & 1 deletion src/debug/DebugHost/apps_src/hellow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Apps;

[NetDaemonApp]
[Focus]
//[Focus]
public sealed class HelloAppSrc : IAsyncDisposable
{
private readonly ILogger<HelloAppSrc> _logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Debug.apps.HassModel.MyInterfaceAutomation;

[NetDaemonApp]
[Focus]
//[Focus]
public class InterfaceUsage
{
public InterfaceUsage(IHaContext haContext, ILogger<InterfaceUsage> logger, IScheduler scheduler)
Expand Down

0 comments on commit 59b8482

Please sign in to comment.