Skip to content

Commit

Permalink
API new feature "EntityIds"
Browse files Browse the repository at this point in the history
  • Loading branch information
helto4real committed Dec 6, 2020
1 parent 9db6ab4 commit 6558b13
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions exampleapps/apps/test2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public override async Task InitializeAsync()

// SetState("sensor.testing", "on", new { attributeobject = new { aobject = "hello" } });
RunEvery(TimeSpan.FromSeconds(5), () => Log("Hello world!"));
// foreach(var entity in EntityIds)
// {
// Log(entity);
// }
// RunDaily("13:00:00", () => Log("Hello world!"));
// RunIn(TimeSpan.FromSeconds(5), () => Entity("light.tomas_rum").TurnOn());
// Entity("light.tomas_rum")
Expand Down
4 changes: 2 additions & 2 deletions exampleapps/apps/test2.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
my_app:
class: NStest.BatteryManager
# HelloWorldSecret: !secret test_secret
dependencies:
- global_app
# dependencies:
# - global_app
4 changes: 4 additions & 0 deletions src/App/NetDaemon.App/Common/INetDaemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ public interface INetDaemonAppBase :
/// </summary>
public AppRuntimeInfo RuntimeInfo { get; }

/// <summary>
/// Returns all entities (EntityId) that are currently registered
/// </summary>
public IEnumerable<string> EntityIds { get; }
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions src/App/NetDaemon.App/Common/NetDaemonAppBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ public async Task RestoreAppStateAsync()
/// <inheritdoc/>
public AppRuntimeInfo RuntimeInfo => _runtimeInfo;

/// <inheritdoc/>
public IEnumerable<string> EntityIds => _daemon?.State.Select(n => n.EntityId) ??
throw new NullReferenceException("Deamon not expected to be null");

/// <inheritdoc/>
public void SaveAppState()
{
Expand Down
14 changes: 14 additions & 0 deletions tests/NetDaemon.Daemon.Tests/Reactive/RxAppTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@ public async Task StatesShouldReturnCorrectEntity()
Assert.Equal("binary_sensor.pir", entity?.EntityId);
}

[Fact]
public async Task EntityIdsShouldReturnCorrectItems()
{
// ARRANGE
var daemonTask = await GetConnectedNetDaemonTask();
// ACT
var entities = DefaultDaemonRxApp.EntityIds.ToList();

await daemonTask.ConfigureAwait(false);
// ASSERT
Assert.NotNull(entities);
Assert.Equal(8, entities.Count());
}

[Fact]
public async Task UsingEntitiesLambdaNewEventShouldCallFunction()
{
Expand Down

0 comments on commit 6558b13

Please sign in to comment.