From 10129b81782513de98f5cd8ab271c01affc4b25c Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 19 Jul 2021 15:09:37 -0600 Subject: [PATCH] feat: Add post activation action for aggregator --- .../IOccupancyStatusProviderAggregator.cs | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/IOccupancyStatusProviderAggregator.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/IOccupancyStatusProviderAggregator.cs index 601edf67..3da9c0dc 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/IOccupancyStatusProviderAggregator.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/IOccupancyStatusProviderAggregator.cs @@ -35,9 +35,38 @@ namespace PepperDash.Essentials.Core } public IOccupancyStatusProviderAggregator(string key, string name, OccupancyAggregatorConfig config) - : this(dc.Key, dc.Name) + : this(key, name) { - + AddPostActivationAction(() => + { + if (config.DeviceKeys.Count == 0) + { + return; + } + + foreach (var deviceKey in config.DeviceKeys) + { + var device = DeviceManager.GetDeviceForKey(deviceKey); + + if (device == null) + { + Debug.Console(0, this, Debug.ErrorLogLevel.Notice, + "Unable to retrieve Occupancy provider with key {0}", deviceKey); + continue; + } + + var provider = device as IOccupancyStatusProvider; + + if (provider == null) + { + Debug.Console(0, this, Debug.ErrorLogLevel.Notice, + "Device with key {0} does NOT implement IOccupancyStatusProvider. Please check configuration."); + continue; + } + + AddOccupancyStatusProvider(provider); + } + }); } /// @@ -52,6 +81,11 @@ namespace PepperDash.Essentials.Core public void RemoveOccupancyStatusProvider(IOccupancyStatusProvider statusProvider) { _aggregatedOccupancyStatus.RemoveOutputIn(statusProvider.RoomIsOccupiedFeedback); + } + + public void ClearOccupancyStatusProviders() + { + _aggregatedOccupancyStatus.ClearOutputs(); } } @@ -59,7 +93,7 @@ namespace PepperDash.Essentials.Core { public OccupancyAggregatorFactory() { - TypeNames = new List { "glsodtccn" }; + TypeNames = new List { "occupancyAggregator", "occAggregate" }; }