Skip to content

Commit

Permalink
Readded RunScript
Browse files Browse the repository at this point in the history
  • Loading branch information
helto4real committed May 11, 2020
1 parent 01bd40e commit 8e7104b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/App/NetDaemon.App/Common/Reactive/AppDaemonRxApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ public void SetState(string entityId, dynamic state, dynamic? attributes = null)
_daemon.SetState(entityId, state, attributes);
}

/// <inheritdoc/>
public void RunScript(params string[] script)
{
_ = _daemon ?? throw new NullReferenceException($"{nameof(_daemon)} cant be null!");

foreach (var scriptName in script)
{
var name = scriptName;
if (scriptName.Contains('.'))
name = scriptName[(scriptName.IndexOf('.') + 1)..];

_daemon.CallService("script", name);
}

}

/// <inheritdoc/>
public async override Task StartUpAsync(INetDaemon daemon)
{
Expand Down
14 changes: 13 additions & 1 deletion src/App/NetDaemon.App/Common/Reactive/INetDaemonReactive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,22 @@ public interface ICallService
void CallService(string domain, string service, dynamic? data);
}

/// <summary>
/// Interface for objects that implements CallService
/// </summary>
public interface IRunScript
{
/// <summary>
/// Calls service in Home Assistant
/// </summary>
/// <param name="script">Script to call</param>
void RunScript(params string[] script);
}

/// <summary>
/// Implements the System.Reactive pattern for NetDaemon Apps
/// </summary>
public interface INetDaemonReactive : INetDaemonAppBase, ICallService, IRxEntity
public interface INetDaemonReactive : INetDaemonAppBase, ICallService, IRxEntity, IRunScript
{
/// <summary>
/// The observable events
Expand Down

0 comments on commit 8e7104b

Please sign in to comment.