public static bool AnyoneJustArrived(this NetDaemonRxApp app) { try { var isa_location = app.State(Isa.PersonEntity)?.State?.ToString()?.ToLower(); var stefan_location = app.State(Stefan.PersonEntity)?.State?.ToString()?.ToLower(); if (isa_location != null || stefan_location != null) { if (stefan_location == PresenceStatus.JustArrived || isa_location == PresenceStatus.JustArrived) { return(true); } else { return(false); } } // return true if null, assume someone could be home app.Log($"A person returned null as location state, assuming someone is home."); return(true); } catch (System.Exception e) { // return true if something goes wrong, assume someone could be home app.Log($"Error: {e}"); return(true); } }
public static void Notify(this NetDaemonRxApp app, string message) { app.CallService("notify", "hass_discord", new { message = message, target = "511278310584746008" }); }
/// <summary> /// Takes a snapshot of given entity id of camera and sends to private discord server /// </summary> /// <param name="app">NetDaemonApp to extend</param> /// <param name="camera">Unique id of the camera</param> public static void CameraSnapshot(this NetDaemonRxApp app, string camera, string snapshotPath) { app.CallService("camera", "snapshot", new { entity_id = camera, filename = snapshotPath }); }
public static void NotifyDiscord( this NetDaemonRxApp app, string channel, string message, bool mention = false) { app.CallService("notify", "hass_discord", new { message = message, target = channel }); }
/// <summary> /// Takes a snapshot of given entity id of camera and sends to private discord server /// </summary> /// <param name="app">NetDaemonApp to extend</param> /// <param name="camera">Unique id of the camera</param> /// <returns>The path to the snapshot</returns> public static string CameraSnapshot(this NetDaemonRxApp app, string camera) { var resultingFilename = $"/config/www/motion/{camera}_latest.jpg"; app.CallService("camera", "snapshot", new { entity_id = camera, filename = resultingFilename }); return(resultingFilename); }
public static void NotifyDiscord( this NetDaemonRxApp app, string channel, string message, Dictionary <string, IEnumerable <string> > data, bool mention = false) { app.CallService("notify", "hass_discord", new { data = data, message = message, target = channel }); }
/// <summary> /// Prints the contents from a IDictionary to a string /// </summary> /// <param name="app">NetDaemonApp to extend</param> /// <param name="dict">The dict to print from, typically from dynamic result</param> /// <returns></returns> public static string PrettyPrintDictData(this NetDaemonRxApp app, IDictionary <string, object>?dict) { if (dict == null) { return(string.Empty); } var builder = new StringBuilder(100); foreach (var key in dict.Keys) { builder.AppendLine($"{key}:{dict[key]}"); } return(builder.ToString()); }
public ApiFakeStartup(IConfiguration configuration) { Configuration = configuration; _loggerMock = new LoggerMock(); _defaultHassClientMock = HassClientMock.DefaultMock; _defaultDataRepositoryMock = new Mock <IDataRepository>(); _defaultHttpHandlerMock = new HttpHandlerMock(); var hassClientFactoryMock = new HassClientFactoryMock(_defaultHassClientMock); _defaultDaemonHost = new NetDaemonHost( hassClientFactoryMock.Object, _defaultDataRepositoryMock.Object, _loggerMock.LoggerFactory, _defaultHttpHandlerMock.Object); _defaultDaemonApp = new BaseTestApp { Id = "app_id", IsEnabled = true }; _defaultDaemonHost.AddRunningApp(_defaultDaemonApp); _defaultDaemonApp2 = new BaseTestApp { Id = "app_id2" }; _defaultDaemonApp2.RuntimeInfo.NextScheduledEvent = DateTime.Now; _defaultDaemonApp2.IsEnabled = false; _defaultDaemonHost.AddRunningApp(_defaultDaemonApp2); _defaultDaemonRxApp = new BaseTestRxApp { Id = "app_rx_id", IsEnabled = true }; _defaultDaemonRxApp.RuntimeInfo.NextScheduledEvent = DateTime.Now; _defaultDaemonHost.AddRunningApp(_defaultDaemonRxApp); _defaultMockedRxApp = new Mock <NetDaemonRxApp>() { CallBase = true }; _defaultMockedRxApp.Object.Id = "app_rx_mock_id"; _defaultMockedRxApp.Object.IsEnabled = true; _defaultMockedRxApp.Setup(n => n.CreateObservableIntervall(It.IsAny <TimeSpan>(), It.IsAny <Action>())).Returns(new Mock <IDisposable>().Object); _defaultDaemonHost.AddRunningApp(_defaultMockedRxApp.Object); }
public static void NotifyImage(this NetDaemonRxApp app, string message, string imagePath) { var dict = new Dictionary <string, IEnumerable <string> > { ["images"] = new List <string> { imagePath } }; app.CallService("notify", "hass_discord", new { data = dict, message = message, target = "511278310584746008" }); }
public static async Task HandleAttributeInitialization(this NetDaemonRxApp netDaemonApp, INetDaemon daemon) { _ = daemon ?? throw new NetDaemonArgumentNullException(nameof(daemon)); _ = netDaemonApp ?? throw new NetDaemonArgumentNullException(nameof(netDaemonApp)); var netDaemonAppType = netDaemonApp.GetType(); foreach (var method in netDaemonAppType.GetMethods()) { if (method.GetCustomAttribute <HomeAssistantServiceCallAttribute>(false) != null) { await HandleServiceCallAttribute(daemon, netDaemonApp, method, false).ConfigureAwait(false); } } }
public ApiFakeStartup(IConfiguration configuration) { Configuration = configuration; _loggerMock = new LoggerMock(); _defaultHassClientMock = HassClientMock.DefaultMock; _defaultDataRepositoryMock = new Mock <IDataRepository>(); _defaultHttpHandlerMock = new HttpHandlerMock(); var hassClientFactoryMock = new HassClientFactoryMock(_defaultHassClientMock); _defaultDaemonHost = new NetDaemonHost( hassClientFactoryMock.Object, _defaultDataRepositoryMock.Object, _loggerMock.LoggerFactory, _defaultHttpHandlerMock.Object); _defaultDaemonApp = new BaseTestApp { Id = "app_id", IsEnabled = true }; _defaultDaemonHost.InternalRunningAppInstances[_defaultDaemonApp.Id !] = _defaultDaemonApp;
public static void Tts(this NetDaemonRxApp app, string entityId, string message) { app.CallService("tts", "google_translate_say", new { entity_id = entityId, message = message }); }
/// <summary> /// Takes a snapshot of given entity id of camera and sends to private discord server /// </summary> /// <param name="app">NetDaemonApp to extend</param> /// <param name="camera">Unique id of the camera</param> public static void CameraTakeSnapshotAndNotify(this NetDaemonRxApp app, string camera) { var imagePath = app.CameraSnapshot(camera); app.NotifyImage(camera, imagePath); }
public static void NotifyIos( this NetDaemonRxApp app, string title, string message, string notifier = "", bool onlyIfHome = false, string threadId = "home-assistant", string category = "", bool critical = false, string imageUrl = "") { var isHome = app.State("person.isa")?.State?.ToString()?.ToLower() == "home" || app.State("person.isa")?.State?.ToString()?.ToLower() == "just arrived"; if (!onlyIfHome || (onlyIfHome && isHome)) { // object sound = ""; var contentType = ""; var hideThumbnail = ""; var entityId = ""; if (!string.IsNullOrWhiteSpace(entityId)) { contentType = "jpeg"; category = "camera"; hideThumbnail = ""; } // if (critical) // { // sound = new Dictionary<string, object> // { // ["name"] = "default", // ["critical"] = 1, // ["volume"] = 1.0 // }; // } var data = new Dictionary <string, object> { ["title"] = title, ["message"] = message, ["data"] = new Dictionary <string, object> { ["attachment"] = new Dictionary <string, object> { ["url"] = imageUrl, ["content-type"] = contentType, ["hide-thumbnail"] = hideThumbnail }, ["push"] = new Dictionary <string, object> { ["thread-id"] = threadId, ["badge"] = 0, // ["sound"] = sound, ["category"] = category }, ["entity_id"] = entityId } }; if (string.IsNullOrWhiteSpace(notifier)) { app.CallService("notify", Isa.IosNotifier, data); } else { app.CallService("notify", notifier, data); } } }
public ZoneEntities(NetDaemonRxApp app) { _app = app; }
public BinarySensorEntities(NetDaemonRxApp app) { _app = app; }
public PersistentNotificationEntities(NetDaemonRxApp app) { _app = app; }
public InputSelectEntities(NetDaemonRxApp app) { _app = app; }
public MediaPlayerEntities(NetDaemonRxApp app) { _app = app; }
public SunEntities(NetDaemonRxApp app) { _app = app; }
public NetdaemonEntities(NetDaemonRxApp app) { _app = app; }
public CameraEntities(NetDaemonRxApp app) { _app = app; }
public LightEntities(NetDaemonRxApp app) { _app = app; }
public SwitchEntities(NetDaemonRxApp app) { _app = app; }
public WeatherEntities(NetDaemonRxApp app) { _app = app; }
public PersonEntities(NetDaemonRxApp app) { _app = app; }