-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPhoneDemoNotifications.cs
More file actions
51 lines (45 loc) · 1.95 KB
/
PhoneDemoNotifications.cs
File metadata and controls
51 lines (45 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using NetDaemon.AppModel;
using NetDaemon.HassModel;
using System.Drawing;
using CodeCasa.CustomEntities.Automation.Notifications.Phones;
using CodeCasa.CustomEntities.Core.Events;
using CodeCasa.NetDaemon.Utilities.Extensions;
using CodeCasa.Notifications.Phone.NetDaemon.Config;
namespace CodeCasa.Automations.Apps.Notifications;
[NetDaemonApp]
internal class PhoneDemoNotifications
{
private readonly JasperPhoneNotifications _jasperPhone;
private const string FirstMessage = "This is a test notification";
private const string SecondMessage = "Now my text is different";
private int _notificationCount;
public PhoneDemoNotifications(
IHaContext haContext,
JasperPhoneNotifications jasperPhone)
{
_jasperPhone = jasperPhone;
haContext.Events.Filter(Events.PhoneNotificationDemoEvent).Subscribe(_ =>
{
AddOrUpdatePhoneNotification(null, Color.Yellow, FirstMessage);
});
}
private void AddOrUpdatePhoneNotification(int? optionalId, Color? color, string message)
{
var id = optionalId ?? ++_notificationCount;
var notificationId = $"{nameof(PhoneDemoNotifications)}_Notification_{id}";
_jasperPhone.Notify(new AndroidNotificationConfig
{
Title = $"Demo Notification {id}",
StatusBarIcon = "mdi:creation",
Message = message,
Color = color,
Actions =
[
new(() => AddOrUpdatePhoneNotification(id, color == Color.Yellow ? Color.Blue : Color.Yellow, message), "Change color!"),
new(() => AddOrUpdatePhoneNotification(id, color, message == FirstMessage ? SecondMessage : FirstMessage), "Change message!"),
new(() => AddOrUpdatePhoneNotification(null, Color.Yellow, FirstMessage), "Add notification!")
],
Sticky = true // Prevents notification from closing after clicking a button.
}, notificationId);
}
}