-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef47851
commit b7bf500
Showing
23 changed files
with
1,072 additions
and
874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using JoySoftware.HomeAssistant.NetDaemon.Common.Reactive; | ||
using Helto4real.Powertools; | ||
public static class DaemonAppExtensions | ||
{ | ||
|
||
/// <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 Notify(this NetDaemonRxApp app, string message) | ||
{ | ||
app.CallService("notify", "hass_discord", new | ||
{ | ||
message = message, | ||
target = "511278310584746008" | ||
}); | ||
} | ||
|
||
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" | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using JoySoftware.HomeAssistant.NetDaemon.Common; | ||
|
||
// public static class ServiceCallExtensions | ||
// { | ||
// public static Task ToggleAsync(this NetDaemonApp app, string entityId, params (string name, object val)[] attributeNameValuePair) | ||
// { | ||
// // Get the domain if supported, else domain is homeassistant | ||
// string domain = GetDomainFromEntity(entityId); | ||
// // Use it if it is supported else use default "homeassistant" domain | ||
|
||
// // Use expando object as all other methods | ||
// dynamic attributes = attributeNameValuePair.ToDynamic(); | ||
// // and add the entity id dynamically | ||
// attributes.entity_id = entityId; | ||
|
||
// return app.CallService(domain, "toggle", attributes, false); | ||
// } | ||
|
||
// public static Task TurnOffAsync(this NetDaemonApp app, string entityId, params (string name, object val)[] attributeNameValuePair) | ||
// { | ||
// // Get the domain if supported, else domain is homeassistant | ||
// string domain = GetDomainFromEntity(entityId); | ||
// // Use it if it is supported else use default "homeassistant" domain | ||
|
||
// // Use expando object as all other methods | ||
// dynamic attributes = attributeNameValuePair.ToDynamic(); | ||
// // and add the entity id dynamically | ||
// attributes.entity_id = entityId; | ||
|
||
// return app.CallService(domain, "turn_off", attributes, false); | ||
// } | ||
|
||
// public static Task TurnOnAsync(this NetDaemonApp app, string entityId, params (string name, object val)[] attributeNameValuePair) | ||
// { | ||
// // Use default domain "homeassistant" if supported is missing | ||
// string domain = GetDomainFromEntity(entityId); | ||
// // Use it if it is supported else use default "homeassistant" domain | ||
|
||
// // Convert the value pairs to dynamic type | ||
// dynamic attributes = attributeNameValuePair.ToDynamic(); | ||
// // and add the entity id dynamically | ||
// attributes.entity_id = entityId; | ||
|
||
// return app.CallService(domain, "turn_on", attributes, false); | ||
// } | ||
|
||
// private static string GetDomainFromEntity(string entity) | ||
// { | ||
// var entityParts = entity.Split('.'); | ||
// if (entityParts.Length != 2) | ||
// throw new ApplicationException($"entity_id is mal formatted {entity}"); | ||
|
||
// return entityParts[0]; | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using JoySoftware.HomeAssistant.NetDaemon.Common.Reactive; | ||
|
||
// Use unique namespaces for your apps if you going to share with others to avoid | ||
// conflicting names | ||
namespace Helto4real.Powertools | ||
{ | ||
public static class Powertools | ||
{ | ||
/// <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; | ||
} | ||
|
||
/// <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 | ||
}); | ||
} | ||
|
||
/// <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(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.