From 2e4202ccce1f232e96638aede3c855dcd71a43cc Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Thu, 4 Feb 2021 10:52:02 -0700 Subject: [PATCH] adjustments made based on testing with hardware --- .../CenOdtOccupancySensorBaseController.cs | 16 ++++- .../GlsOccupancySensorBaseController.cs | 59 +++++++++++++++++-- .../GlsOdtOccupancySensorController.cs | 14 +++++ 3 files changed, 82 insertions(+), 7 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/CenOdtOccupancySensorBaseController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/CenOdtOccupancySensorBaseController.cs index 68f3f0e9..dcf0b193 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/CenOdtOccupancySensorBaseController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/CenOdtOccupancySensorBaseController.cs @@ -127,8 +127,20 @@ namespace PepperDash.Essentials.Core AddPostActivationAction(() => { - ApplySettingsToSensorFromConfig(); - }); + OccSensor.OnlineStatusChange += (o, a) => + { + if (a.DeviceOnLine) + { + ApplySettingsToSensorFromConfig(); + } + }; + + if (OccSensor.IsOnline) + { + ApplySettingsToSensorFromConfig(); + + } + }); } /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/GlsOccupancySensorBaseController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/GlsOccupancySensorBaseController.cs index 9a9585b6..711197a5 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/GlsOccupancySensorBaseController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/GlsOccupancySensorBaseController.cs @@ -62,8 +62,16 @@ namespace PepperDash.Essentials.Core DeviceConfig config) : base(key, config.Name) { + var props = config.Properties.ToObject(); - PropertiesConfig = config.Properties.ToObject(); + if (props != null) + { + PropertiesConfig = props; + } + else + { + Debug.Console(1, this, "props are null. Unable to deserialize into GlsOccupancySensorPropertiesConfig"); + } AddPreActivationAction(() => { @@ -77,12 +85,36 @@ namespace PepperDash.Essentials.Core AddPostActivationAction(() => { - ApplySettingsToSensorFromConfig(); - }); - + OccSensor.OnlineStatusChange += (o, a) => + { + if (a.DeviceOnLine) + { + ApplySettingsToSensorFromConfig(); + } + }; + }); } - public GlsOccupancySensorBaseController(string key, string name) : base(key, name) { } + public GlsOccupancySensorBaseController(string key, string name) + : base(key, name) + { + AddPostActivationAction(() => + { + OccSensor.OnlineStatusChange += (o, a) => + { + if (a.DeviceOnLine) + { + ApplySettingsToSensorFromConfig(); + } + }; + + if (OccSensor.IsOnline) + { + ApplySettingsToSensorFromConfig(); + + } + }); + } /// @@ -90,20 +122,33 @@ namespace PepperDash.Essentials.Core /// protected virtual void ApplySettingsToSensorFromConfig() { + Debug.Console(1, this, "Attempting to apply settings to sensor from config"); + if (PropertiesConfig.EnablePir != null) { + Debug.Console(1, this, "EnablePir found, attempting to set value from config"); SetPirEnable((bool)PropertiesConfig.EnablePir); } + else + { + Debug.Console(1, this, "EnablePir null, no value specified in config"); + } if (PropertiesConfig.EnableLedFlash != null) { + Debug.Console(1, this, "EnableLedFlash found, attempting to set value from config"); SetLedFlashEnable((bool)PropertiesConfig.EnableLedFlash); } if (PropertiesConfig.RemoteTimeout != null) { + Debug.Console(1, this, "RemoteTimeout found, attempting to set value from config"); SetRemoteTimeout((ushort)PropertiesConfig.RemoteTimeout); } + else + { + Debug.Console(1, this, "RemoteTimeout null, no value specified in config"); + } if (PropertiesConfig.ShortTimeoutState != null) { @@ -247,6 +292,8 @@ namespace PepperDash.Essentials.Core /// public void SetPirEnable(bool state) { + Debug.Console(1, this, "Setting EnablePir to: {0}", state); + if (state) { OccSensor.EnablePir.BoolValue = state; @@ -332,6 +379,8 @@ namespace PepperDash.Essentials.Core public void SetRemoteTimeout(ushort time) { + Debug.Console(1, this, "Setting RemoteTimout to: {0}", time); + OccSensor.RemoteTimeout.UShortValue = time; } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/GlsOdtOccupancySensorController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/GlsOdtOccupancySensorController.cs index 649923f9..e1b82bac 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/GlsOdtOccupancySensorController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Occupancy/GlsOdtOccupancySensorController.cs @@ -65,6 +65,8 @@ namespace PepperDash.Essentials.Core UltrasonicSensitivityInOccupiedStateFeedback = new IntFeedback(() => OccSensor.UsSensitivityInOccupiedStateFeedback.UShortValue); }); + + } protected override void ApplySettingsToSensorFromConfig() @@ -73,13 +75,25 @@ namespace PepperDash.Essentials.Core if (PropertiesConfig.EnableUsA != null) { + Debug.Console(1, this, "EnableUsA found, attempting to set value from config"); SetUsAEnable((bool)PropertiesConfig.EnableUsA); } + else + { + Debug.Console(1, this, "EnableUsA null, no value specified in config"); + } + if (PropertiesConfig.EnableUsB != null) { + Debug.Console(1, this, "EnableUsB found, attempting to set value from config"); SetUsBEnable((bool)PropertiesConfig.EnableUsB); } + else + { + Debug.Console(1, this, "EnablePir null, no value specified in config"); + } + if (PropertiesConfig.OrWhenVacatedState != null) {