-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDashboardDemoNotifications.cs
More file actions
110 lines (97 loc) · 4.99 KB
/
DashboardDemoNotifications.cs
File metadata and controls
110 lines (97 loc) · 4.99 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using CodeCasa.CustomEntities.Automation.Notifications.Dashboards;
using CodeCasa.CustomEntities.Core.Events;
using CodeCasa.NetDaemon.Utilities.Extensions;
using CodeCasa.Notifications.InputSelect.NetDaemon;
using NetDaemon.AppModel;
using NetDaemon.HassModel;
namespace CodeCasa.Automations.Apps.Notifications;
[NetDaemonApp]
internal class DashboardDemoNotifications
{
private List<InputSelectNotification> _notifications = [];
private int _manuallyAddedIndex;
public DashboardDemoNotifications(
IHaContext haContext,
LivingRoomPanelDashboardNotifications livingRoomPanelNotifications)
{
haContext.Events.Filter(Events.LivingRoomPanelNotificationDemoEvent).Subscribe(_ =>
{
_notifications.Clear();
_manuallyAddedIndex = 0;
var clickToRemoveNotificationId = $"{nameof(DashboardDemoNotifications)}_ClickToRemove";
var clickToUndoRemoveNotificationId = $"{nameof(DashboardDemoNotifications)}_ClickToUndoRemove";
void AddClickToRemoveNotificationAction() =>
_notifications.Add(livingRoomPanelNotifications.Notify(new LivingRoomPanelNotificationConfig
{
Order = 900,
Message = "Demo Notification 1",
SecondaryMessage = "Click to remove me.",
Icon = "Material.Filled.AutoAwesome",
Action = () =>
{
livingRoomPanelNotifications.RemoveNotification(clickToRemoveNotificationId);
_notifications = _notifications.Where(n => n.Id != clickToRemoveNotificationId).ToList();
_notifications.Add(livingRoomPanelNotifications.Notify(new LivingRoomPanelNotificationConfig
{
Message = "Notification removed!",
SecondaryMessage = "Click to undo remove.",
Icon = "Material.Filled.Undo",
Timeout = TimeSpan.FromSeconds(3),
Action = () =>
{
livingRoomPanelNotifications.RemoveNotification(clickToUndoRemoveNotificationId);
_notifications = _notifications.Where(n => n.Id != clickToUndoRemoveNotificationId)
.ToList();
AddClickToRemoveNotificationAction();
}
}, clickToUndoRemoveNotificationId));
}
}, clickToRemoveNotificationId));
AddClickToRemoveNotificationAction();
var addNotificationNotificationId = $"{nameof(DashboardDemoNotifications)}_Add";
void AddNotificationNotificationAction() => _notifications.Add(livingRoomPanelNotifications.Notify(
new LivingRoomPanelNotificationConfig
{
Order = 901,
Message = "Demo Notification 3",
SecondaryMessage = "Click to add notification.",
Icon = "Material.Filled.AutoAwesome",
Action = () =>
{
_manuallyAddedIndex++;
var notificationId = Guid.NewGuid().ToString();
_notifications.Add(livingRoomPanelNotifications.Notify(new LivingRoomPanelNotificationConfig
{
Order = 902,
Message = $"Added Demo Notification ({_manuallyAddedIndex})",
SecondaryMessage = "Click to remove me.",
Icon = "Material.Filled.AutoAwesome",
Action = () =>
{
livingRoomPanelNotifications.RemoveNotification(notificationId);
_notifications = _notifications.Where(n => n.Id != notificationId).ToList();
}
}, notificationId));
AddNotificationNotificationAction();
}
}, addNotificationNotificationId));
AddNotificationNotificationAction();
var clearNotificationId = $"{nameof(DashboardDemoNotifications)}_Clear";
_notifications.Add(livingRoomPanelNotifications.Notify(new LivingRoomPanelNotificationConfig
{
Order = 903,
Message = "Demo Notification 2",
SecondaryMessage = "Click to clear demo notifications.",
Icon = "Material.Filled.AutoAwesome",
Action = () =>
{
foreach (var notification in _notifications)
{
livingRoomPanelNotifications.RemoveNotification(notification);
}
_notifications.Clear();
}
}, clearNotificationId));
});
}
}