mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-14 20:24:57 +00:00
#742 Updates to room combination interfaces and EssentialsRoomCombiner and EssentialsPartitionController
This commit is contained in:
@@ -0,0 +1,149 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an abstract controller device for a partition dividing rooms that are combinable
|
||||||
|
///
|
||||||
|
/// In Auto mode, it can use a partition sensor to automatically determine whether the partition is present.
|
||||||
|
///
|
||||||
|
/// In Manual mode it accepts user input to tell it whether the partition is present.
|
||||||
|
/// </summary>
|
||||||
|
public class EssentialsPartitionController : IPartitionController
|
||||||
|
{
|
||||||
|
private IPartitionStateProvider _partitionSensor;
|
||||||
|
|
||||||
|
private bool isInAutoMode;
|
||||||
|
|
||||||
|
private bool partitionPresent;
|
||||||
|
|
||||||
|
public EssentialsPartitionController(string key, string name, IPartitionStateProvider sensor, bool defaultToManualMode, List<string> adjacentRoomKeys)
|
||||||
|
{
|
||||||
|
Key = key;
|
||||||
|
|
||||||
|
Name = name;
|
||||||
|
|
||||||
|
AdjacentRoomKeys = adjacentRoomKeys;
|
||||||
|
|
||||||
|
if (sensor != null)
|
||||||
|
{
|
||||||
|
_partitionSensor = sensor;
|
||||||
|
|
||||||
|
if (!defaultToManualMode)
|
||||||
|
{
|
||||||
|
SetAutoMode();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetManualMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetManualMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
PartitionPresentFeedback.FireUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PartitionPresentFeedback_OutputChange(object sender, FeedbackEventArgs e)
|
||||||
|
{
|
||||||
|
if (isInAutoMode)
|
||||||
|
{
|
||||||
|
PartitionPresentFeedback.FireUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IPartitionController Members
|
||||||
|
|
||||||
|
public List<string> AdjacentRoomKeys { get; private set; }
|
||||||
|
|
||||||
|
public void SetAutoMode()
|
||||||
|
{
|
||||||
|
isInAutoMode = true;
|
||||||
|
if (PartitionPresentFeedback != null)
|
||||||
|
{
|
||||||
|
PartitionPresentFeedback.SetValueFunc(() => _partitionSensor.PartitionPresentFeedback.BoolValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PartitionPresentFeedback = new BoolFeedback(() => _partitionSensor.PartitionPresentFeedback.BoolValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_partitionSensor != null)
|
||||||
|
{
|
||||||
|
_partitionSensor.PartitionPresentFeedback.OutputChange += PartitionPresentFeedback_OutputChange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetManualMode()
|
||||||
|
{
|
||||||
|
isInAutoMode = false;
|
||||||
|
if (PartitionPresentFeedback != null)
|
||||||
|
{
|
||||||
|
PartitionPresentFeedback.SetValueFunc(() => partitionPresent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PartitionPresentFeedback = new BoolFeedback(() => partitionPresent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_partitionSensor != null)
|
||||||
|
{
|
||||||
|
_partitionSensor.PartitionPresentFeedback.OutputChange -= PartitionPresentFeedback_OutputChange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void SetPartitionStatePresent()
|
||||||
|
{
|
||||||
|
if (!isInAutoMode)
|
||||||
|
{
|
||||||
|
partitionPresent = true;
|
||||||
|
PartitionPresentFeedback.FireUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPartitionStateNotPresent()
|
||||||
|
{
|
||||||
|
if (!isInAutoMode)
|
||||||
|
{
|
||||||
|
partitionPresent = false;
|
||||||
|
PartitionPresentFeedback.FireUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ToggglePartitionState()
|
||||||
|
{
|
||||||
|
if (!isInAutoMode)
|
||||||
|
{
|
||||||
|
partitionPresent = !partitionPresent;
|
||||||
|
PartitionPresentFeedback.FireUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IPartitionStateProvider Members
|
||||||
|
|
||||||
|
public BoolFeedback PartitionPresentFeedback { get; private set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IKeyName Members
|
||||||
|
|
||||||
|
public string Name { get; private set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IKeyed Members
|
||||||
|
|
||||||
|
public string Key { get; private set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
public StringFeedback NameFeedback { get; private set; }
|
public StringFeedback NameFeedback { get; private set; }
|
||||||
public BoolFeedback EnableFeedback { get; private set; }
|
public BoolFeedback EnableFeedback { get; private set; }
|
||||||
public BoolFeedback PartitionSensedFeedback { get; private set; }
|
public BoolFeedback PartitionPresentFeedback { get; private set; }
|
||||||
public BoolFeedback PartitionNotSensedFeedback { get; private set; }
|
public BoolFeedback PartitionNotSensedFeedback { get; private set; }
|
||||||
public IntFeedback SensitivityFeedback { get; private set; }
|
public IntFeedback SensitivityFeedback { get; private set; }
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
NameFeedback = new StringFeedback(() => Name);
|
NameFeedback = new StringFeedback(() => Name);
|
||||||
EnableFeedback = new BoolFeedback(() => _partitionSensor.EnableFeedback.BoolValue);
|
EnableFeedback = new BoolFeedback(() => _partitionSensor.EnableFeedback.BoolValue);
|
||||||
PartitionSensedFeedback = new BoolFeedback(() => _partitionSensor.PartitionSensedFeedback.BoolValue);
|
PartitionPresentFeedback = new BoolFeedback(() => _partitionSensor.PartitionSensedFeedback.BoolValue);
|
||||||
PartitionNotSensedFeedback = new BoolFeedback(() => _partitionSensor.PartitionNotSensedFeedback.BoolValue);
|
PartitionNotSensedFeedback = new BoolFeedback(() => _partitionSensor.PartitionNotSensedFeedback.BoolValue);
|
||||||
SensitivityFeedback = new IntFeedback(() => _partitionSensor.SensitivityFeedback.UShortValue);
|
SensitivityFeedback = new IntFeedback(() => _partitionSensor.SensitivityFeedback.UShortValue);
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
case (GlsPartCn.PartitionSensedFeedbackEventId):
|
case (GlsPartCn.PartitionSensedFeedbackEventId):
|
||||||
{
|
{
|
||||||
PartitionSensedFeedback.FireUpdate();
|
PartitionPresentFeedback.FireUpdate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case (GlsPartCn.PartitionNotSensedFeedbackEventId):
|
case (GlsPartCn.PartitionNotSensedFeedbackEventId):
|
||||||
@@ -186,7 +186,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
// link output to simpl
|
// link output to simpl
|
||||||
IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
|
IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
|
||||||
EnableFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Enable.JoinNumber]);
|
EnableFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Enable.JoinNumber]);
|
||||||
PartitionSensedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionSensed.JoinNumber]);
|
PartitionPresentFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionSensed.JoinNumber]);
|
||||||
PartitionNotSensedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionNotSensed.JoinNumber]);
|
PartitionNotSensedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionNotSensed.JoinNumber]);
|
||||||
SensitivityFeedback.LinkInputSig(trilist.UShortInput[joinMap.Sensitivity.JoinNumber]);
|
SensitivityFeedback.LinkInputSig(trilist.UShortInput[joinMap.Sensitivity.JoinNumber]);
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
IsOnline.FireUpdate();
|
IsOnline.FireUpdate();
|
||||||
NameFeedback.FireUpdate();
|
NameFeedback.FireUpdate();
|
||||||
EnableFeedback.FireUpdate();
|
EnableFeedback.FireUpdate();
|
||||||
PartitionSensedFeedback.FireUpdate();
|
PartitionPresentFeedback.FireUpdate();
|
||||||
PartitionNotSensedFeedback.FireUpdate();
|
PartitionNotSensedFeedback.FireUpdate();
|
||||||
SensitivityFeedback.FireUpdate();
|
SensitivityFeedback.FireUpdate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,15 +13,24 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IPartitionStateProvider : IKeyName
|
public interface IPartitionStateProvider : IKeyName
|
||||||
{
|
{
|
||||||
BoolFeedback PartitionSensedFeedback { get; }
|
BoolFeedback PartitionPresentFeedback { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IManualPartitionSensor : IPartitionStateProvider
|
/// <summary>
|
||||||
|
/// Describes the functionality of a device that can provide partition state either manually via user input or optionally via a sensor state
|
||||||
|
/// </summary>
|
||||||
|
public interface IPartitionController : IPartitionStateProvider
|
||||||
{
|
{
|
||||||
|
List<string> AdjacentRoomKeys { get; set; }
|
||||||
|
|
||||||
void SetPartitionStatePresent();
|
void SetPartitionStatePresent();
|
||||||
|
|
||||||
void SetPartitionStateNotPresent();
|
void SetPartitionStateNotPresent();
|
||||||
|
|
||||||
void ToggglePartitionState();
|
void ToggglePartitionState();
|
||||||
|
|
||||||
|
void SetManualMode();
|
||||||
|
|
||||||
|
void SetAutoMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,6 +233,7 @@
|
|||||||
<Compile Include="Interfaces\ILogStringsWithLevel.cs" />
|
<Compile Include="Interfaces\ILogStringsWithLevel.cs" />
|
||||||
<Compile Include="Occupancy\GlsOccupancySensorPropertiesConfig.cs" />
|
<Compile Include="Occupancy\GlsOccupancySensorPropertiesConfig.cs" />
|
||||||
<Compile Include="Occupancy\GlsOirOccupancySensorController.cs" />
|
<Compile Include="Occupancy\GlsOirOccupancySensorController.cs" />
|
||||||
|
<Compile Include="PartitionSensor\EssentialsPartitionController.cs" />
|
||||||
<Compile Include="PartitionSensor\IPartitionStateProvider.cs" />
|
<Compile Include="PartitionSensor\IPartitionStateProvider.cs" />
|
||||||
<Compile Include="Queues\ComsMessage.cs" />
|
<Compile Include="Queues\ComsMessage.cs" />
|
||||||
<Compile Include="Queues\ProcessStringMessage.cs" />
|
<Compile Include="Queues\ProcessStringMessage.cs" />
|
||||||
|
|||||||
@@ -42,14 +42,19 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
void CreateScenarios()
|
void CreateScenarios()
|
||||||
{
|
{
|
||||||
|
RoomCombinationScenarios = new List<IRoomCombinationScenario>();
|
||||||
|
|
||||||
foreach (var scenarioConfig in _propertiesConfig.Scenarios)
|
foreach (var scenarioConfig in _propertiesConfig.Scenarios)
|
||||||
{
|
{
|
||||||
var scenario = new RoomCombinationScenario(scenarioConfig);
|
var scenario = new RoomCombinationScenario(scenarioConfig);
|
||||||
|
RoomCombinationScenarios.Add(scenario);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetRooms()
|
void SetRooms()
|
||||||
{
|
{
|
||||||
|
_rooms = new List<IEssentialsRoom>();
|
||||||
|
|
||||||
foreach (var roomKey in _propertiesConfig.RoomKeys)
|
foreach (var roomKey in _propertiesConfig.RoomKeys)
|
||||||
{
|
{
|
||||||
var room = DeviceManager.GetDeviceForKey(roomKey) as IEssentialsRoom;
|
var room = DeviceManager.GetDeviceForKey(roomKey) as IEssentialsRoom;
|
||||||
@@ -62,7 +67,36 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
void SetupPartitionStateProviders()
|
void SetupPartitionStateProviders()
|
||||||
{
|
{
|
||||||
|
foreach (var pConfig in _propertiesConfig.Partitions)
|
||||||
|
{
|
||||||
|
var sensor = DeviceManager.GetDeviceForKey(pConfig.DeviceKey) as IPartitionStateProvider;
|
||||||
|
|
||||||
|
var partition = new EssentialsPartitionController(pConfig.Key, pConfig.Name, sensor, _propertiesConfig.defaultToManualMode, pConfig.AdjacentRoomKeys);
|
||||||
|
|
||||||
|
partition.PartitionPresentFeedback.OutputChange += PartitionPresentFeedback_OutputChange;
|
||||||
|
|
||||||
|
Partitions.Add(partition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PartitionPresentFeedback_OutputChange(object sender, FeedbackEventArgs e)
|
||||||
|
{
|
||||||
|
DetermineRoomCombinationScenario();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines the current room combination scenario based on the state of the partition sensors
|
||||||
|
/// </summary>
|
||||||
|
void DetermineRoomCombinationScenario()
|
||||||
|
{
|
||||||
|
//RoomCombinationScenarios.FirstOrDefault((s) =>
|
||||||
|
//{
|
||||||
|
// foreach (var partitionState in s.PartitionStates)
|
||||||
|
// {
|
||||||
|
// var partition = Partitions.FirstOrDefault(
|
||||||
|
// }
|
||||||
|
//});
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IEssentialsRoomCombiner Members
|
#region IEssentialsRoomCombiner Members
|
||||||
@@ -111,11 +145,11 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
public List<IRoomCombinationScenario> RoomCombinationScenarios { get; private set; }
|
public List<IRoomCombinationScenario> RoomCombinationScenarios { get; private set; }
|
||||||
|
|
||||||
public List<IPartitionStateProvider> PartitionStateProviders { get; private set; }
|
public List<IPartitionStateProvider> Partitions { get; private set; }
|
||||||
|
|
||||||
public void TogglePartitionState(string partitionKey)
|
public void TogglePartitionState(string partitionKey)
|
||||||
{
|
{
|
||||||
var partition = PartitionStateProviders.FirstOrDefault((p) => p.Key.Equals(partitionKey)) as IManualPartitionSensor;
|
var partition = Partitions.FirstOrDefault((p) => p.Key.Equals(partitionKey)) as IPartitionController;
|
||||||
|
|
||||||
if (partition != null)
|
if (partition != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
[JsonProperty("partitionStates")]
|
[JsonProperty("partitionStates")]
|
||||||
public List<PartitionState> PartitionStates { get; set; }
|
public List<PartitionState> PartitionStates { get; set; }
|
||||||
|
|
||||||
[JsonProperty("roomMap")]
|
[JsonProperty("uiMap")]
|
||||||
public Dictionary<string, string> RoomMap { get; set; }
|
public Dictionary<string, string> UiMap { get; set; }
|
||||||
|
|
||||||
[JsonProperty("activationActions")]
|
[JsonProperty("activationActions")]
|
||||||
public List<DeviceActionWrapper> ActivationActions { get; set; }
|
public List<DeviceActionWrapper> ActivationActions { get; set; }
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Describes the functionality for an EssentailsRoomCombiner device
|
/// Describes the functionality for an EssentailsRoomCombiner device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IEssentialsRoomCombiner
|
public interface IEssentialsRoomCombiner : IKeyed
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates that the room combination scenario has changed
|
/// Indicates that the room combination scenario has changed
|
||||||
@@ -51,7 +51,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The partition
|
/// The partition
|
||||||
/// </summary>
|
/// </summary>
|
||||||
List<IPartitionStateProvider> PartitionStateProviders { get; }
|
List<IPartitionStateProvider> Partitions { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Toggles the state of a manual partition sensor
|
/// Toggles the state of a manual partition sensor
|
||||||
@@ -77,6 +77,16 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// Activates this room combination scenario
|
/// Activates this room combination scenario
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Activate();
|
void Activate();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The state of the partitions that would activate this scenario
|
||||||
|
/// </summary>
|
||||||
|
List<PartitionState> PartitionStates { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The mapping of UIs by key to rooms by key
|
||||||
|
/// </summary>
|
||||||
|
Dictionary<string, string> UiMap { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
public List<PartitionState> PartitionStates { get; private set; }
|
public List<PartitionState> PartitionStates { get; private set; }
|
||||||
|
|
||||||
public Dictionary<string, string> EnabledRoomMap { get; set; }
|
public Dictionary<string, string> UiMap { get; set; }
|
||||||
|
|
||||||
private bool _isActive;
|
private bool _isActive;
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
PartitionStates = config.PartitionStates;
|
PartitionStates = config.PartitionStates;
|
||||||
|
|
||||||
EnabledRoomMap = config.RoomMap;
|
UiMap = config.UiMap;
|
||||||
|
|
||||||
activationActions = config.ActivationActions;
|
activationActions = config.ActivationActions;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user