mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-14 13:07:18 +00:00
feat: Adds mechanism to track initialization status of EssentialsDevice as well as an event on DeviceManager to notify when all devices initialized. Room combiner now waits for all initialize before setting current scenario.
This commit is contained in:
parent
f351c036ed
commit
fa38e8a9a8
3 changed files with 55 additions and 2 deletions
|
|
@ -14,6 +14,7 @@ namespace PepperDash.Essentials.Core
|
|||
{
|
||||
public static event EventHandler<EventArgs> AllDevicesActivated;
|
||||
public static event EventHandler<EventArgs> AllDevicesRegistered;
|
||||
public static event EventHandler<EventArgs> AllDevicesInitialized;
|
||||
|
||||
private static readonly CCriticalSection DeviceCriticalSection = new CCriticalSection();
|
||||
private static readonly CEvent AllowAddDevicesCEvent = new CEvent(false, true);
|
||||
|
|
@ -67,7 +68,7 @@ namespace PepperDash.Essentials.Core
|
|||
foreach (var d in Devices.Values)
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
if (d is Device)
|
||||
(d as Device).PreActivate();
|
||||
}
|
||||
|
|
@ -123,6 +124,18 @@ namespace PepperDash.Essentials.Core
|
|||
}
|
||||
}
|
||||
|
||||
private static void DeviceManager_Initialized(object sender, EventArgs e)
|
||||
{
|
||||
var allInitialized = Devices.Values.OfType<EssentialsDevice>().All(d => d.IsInitialized);
|
||||
|
||||
if (allInitialized)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, "****All Devices Initalized****");
|
||||
|
||||
OnAllDevicesInitialized();
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnAllDevicesActivated()
|
||||
{
|
||||
var handler = AllDevicesActivated;
|
||||
|
|
@ -141,6 +154,15 @@ namespace PepperDash.Essentials.Core
|
|||
}
|
||||
}
|
||||
|
||||
private static void OnAllDevicesInitialized()
|
||||
{
|
||||
var handler = AllDevicesInitialized;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(null, new EventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls activate on all Device class items
|
||||
/// </summary>
|
||||
|
|
@ -264,6 +286,9 @@ namespace PepperDash.Essentials.Core
|
|||
Devices.Add(newDev.Key, newDev);
|
||||
//if (!(_Devices.Contains(newDev)))
|
||||
// _Devices.Add(newDev);
|
||||
|
||||
if (newDev is EssentialsDevice essentialsDev)
|
||||
essentialsDev.Initialized += DeviceManager_Initialized;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue