Merge pull request #322 from PepperDash/release/1.5.7

Release/1.5.7
This commit is contained in:
Andrew Welker
2020-07-10 08:51:25 -07:00
committed by GitHub

View File

@@ -1,315 +1,317 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.Gateways; using Crestron.SimplSharpPro.Gateways;
using Crestron.SimplSharpPro.Remotes; using Crestron.SimplSharpPro.Remotes;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharp.Reflection; using Crestron.SimplSharp.Reflection;
using Newtonsoft.Json; using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Bridges;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
[Description("Wrapper class for all HR-Series remotes")] [Description("Wrapper class for all HR-Series remotes")]
public class Hrxx0WirelessRemoteController : EssentialsBridgeableDevice, IHasFeedback public class Hrxx0WirelessRemoteController : EssentialsBridgeableDevice, IHasFeedback
{ {
private CenRfgwController _gateway; private CenRfgwController _gateway;
private GatewayBase _gatewayBase;
private GatewayBase _gatewayBase;
private Hr1x0WirelessRemoteBase _remote;
public FeedbackCollection<Feedback> Feedbacks { get; set; } private Hr1x0WirelessRemoteBase _remote;
public CrestronCollection<Button> Buttons { get { return _remote.Button; } } public FeedbackCollection<Feedback> Feedbacks { get; set; }
private DeviceConfig _config; public CrestronCollection<Button> Buttons { get { return _remote.Button; } }
public Hrxx0WirelessRemoteController(string key, Func<DeviceConfig, Hr1x0WirelessRemoteBase> preActivationFunc, private DeviceConfig _config;
DeviceConfig config)
: base(key, config.Name) public Hrxx0WirelessRemoteController(string key, Func<DeviceConfig, Hr1x0WirelessRemoteBase> preActivationFunc,
{ DeviceConfig config)
Feedbacks = new FeedbackCollection<Feedback>(); : base(key, config.Name)
{
var props = JsonConvert.DeserializeObject<CrestronRemotePropertiesConfig>(config.Properties.ToString()); Feedbacks = new FeedbackCollection<Feedback>();
var type = config.Type; var props = JsonConvert.DeserializeObject<CrestronRemotePropertiesConfig>(config.Properties.ToString());
var rfId = (uint)props.Control.InfinetIdInt;
_config = config; var type = config.Type;
var rfId = (uint)props.Control.InfinetIdInt;
if (props.GatewayDeviceKey == "processor") _config = config;
{
{ if (props.GatewayDeviceKey == "processor")
AddPreActivationAction(() => {
{ {
_remote = preActivationFunc(config); AddPreActivationAction(() =>
RegisterEvents(); {
}); _remote = preActivationFunc(config);
RegisterEvents();
return; });
}
} return;
}
}
var gatewayDev = DeviceManager.GetDeviceForKey(props.GatewayDeviceKey) as CenRfgwController;
if (gatewayDev == null)
{ var gatewayDev = DeviceManager.GetDeviceForKey(props.GatewayDeviceKey) as CenRfgwController;
Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is not a valid device", props.GatewayDeviceKey); if (gatewayDev == null)
} {
if (gatewayDev != null) Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is not a valid device", props.GatewayDeviceKey);
{ }
Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is a valid device", props.GatewayDeviceKey); if (gatewayDev != null)
_gateway = gatewayDev; {
} Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is a valid device", props.GatewayDeviceKey);
_gateway = gatewayDev;
}
if (_gateway == null) return;
_gateway.IsReadyEvent += _gateway_IsReadyEvent; if (_gateway == null) return;
if (_gateway.IsReady)
{ _gateway.IsReadyEvent += _gateway_IsReadyEvent;
AddPreActivationAction(() => if (_gateway.IsReady)
{ {
_remote = preActivationFunc(config); AddPreActivationAction(() =>
{
RegisterEvents(); _remote = preActivationFunc(config);
});
} RegisterEvents();
} });
}
void _gateway_IsReadyEvent(object sender, PepperDash_Essentials_Core.IsReadyEventArgs e) }
{
if (e.IsReady != true) return; void _gateway_IsReadyEvent(object sender, PepperDash_Essentials_Core.IsReadyEventArgs e)
_remote = GetHr1x0WirelessRemote(_config); {
if (e.IsReady != true) return;
RegisterEvents(); _remote = GetHr1x0WirelessRemote(_config);
}
RegisterEvents();
void _remote_BaseEvent(GenericBase device, BaseEventArgs args) }
{
if(args.EventId == Hr1x0EventIds.BatteryCriticalFeedbackEventId) void _remote_BaseEvent(GenericBase device, BaseEventArgs args)
Feedbacks["BatteryCritical"].FireUpdate(); {
if(args.EventId == Hr1x0EventIds.BatteryLowFeedbackEventId) if(args.EventId == Hr1x0EventIds.BatteryCriticalFeedbackEventId)
Feedbacks["BatteryLow"].FireUpdate(); Feedbacks["BatteryCritical"].FireUpdate();
if(args.EventId == Hr1x0EventIds.BatteryVoltageFeedbackEventId) if(args.EventId == Hr1x0EventIds.BatteryLowFeedbackEventId)
Feedbacks["BatteryVoltage"].FireUpdate(); Feedbacks["BatteryLow"].FireUpdate();
} if(args.EventId == Hr1x0EventIds.BatteryVoltageFeedbackEventId)
Feedbacks["BatteryVoltage"].FireUpdate();
private void RegisterEvents() }
{
_remote.ButtonStateChange += _remote_ButtonStateChange; private void RegisterEvents()
{
Feedbacks.Add(new BoolFeedback("BatteryCritical", () => _remote.BatteryCriticalFeedback.BoolValue)); _remote.ButtonStateChange += _remote_ButtonStateChange;
Feedbacks.Add(new BoolFeedback("BatteryLow", () => _remote.BatteryLowFeedback.BoolValue));
Feedbacks.Add(new IntFeedback("BatteryVoltage", () => _remote.BatteryVoltageFeedback.UShortValue)); Feedbacks.Add(new BoolFeedback("BatteryCritical", () => _remote.BatteryCriticalFeedback.BoolValue));
Feedbacks.Add(new BoolFeedback("BatteryLow", () => _remote.BatteryLowFeedback.BoolValue));
_remote.BaseEvent += _remote_BaseEvent; Feedbacks.Add(new IntFeedback("BatteryVoltage", () => _remote.BatteryVoltageFeedback.UShortValue));
}
_remote.BaseEvent += _remote_BaseEvent;
void _remote_ButtonStateChange(GenericBase device, ButtonEventArgs args) }
{
try void _remote_ButtonStateChange(GenericBase device, ButtonEventArgs args)
{ {
var handler = args.Button.UserObject; try
{
if (handler == null) return; var handler = args.Button.UserObject;
Debug.Console(1, this, "Executing Action: {0}", handler.ToString()); if (handler == null) return;
if (handler is Action<bool>) Debug.Console(1, this, "Executing Action: {0}", handler.ToString());
{
(handler as Action<bool>)(args.Button.State == eButtonState.Pressed ? true : false); if (handler is Action<bool>)
} {
} (handler as Action<bool>)(args.Button.State == eButtonState.Pressed ? true : false);
catch (Exception e) }
{ }
Debug.Console(2, this, "Error in ButtonStateChange handler: {0}", e); catch (Exception e)
} {
} Debug.Console(2, this, "Error in ButtonStateChange handler: {0}", e);
}
}
#region Preactivation
private static Hr1x0WirelessRemoteBase GetHr1x0WirelessRemote(DeviceConfig config) #region Preactivation
{
var props = JsonConvert.DeserializeObject<CrestronRemotePropertiesConfig>(config.Properties.ToString()); private static Hr1x0WirelessRemoteBase GetHr1x0WirelessRemote(DeviceConfig config)
{
var type = config.Type; var props = JsonConvert.DeserializeObject<CrestronRemotePropertiesConfig>(config.Properties.ToString());
var rfId = (uint)props.Control.InfinetIdInt;
var type = config.Type;
GatewayBase gateway; var rfId = (uint)props.Control.InfinetIdInt;
if (props.GatewayDeviceKey == "processor") GatewayBase gateway;
{
gateway = Global.ControlSystem.ControllerRFGatewayDevice; if (props.GatewayDeviceKey == "processor")
} {
else gateway = Global.ControlSystem.ControllerRFGatewayDevice;
{ }
var gatewayDev = DeviceManager.GetDeviceForKey(props.GatewayDeviceKey) as CenRfgwController; else
if (gatewayDev == null) {
{ var gatewayDev = DeviceManager.GetDeviceForKey(props.GatewayDeviceKey) as CenRfgwController;
Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is not a valid device", props.GatewayDeviceKey); if (gatewayDev == null)
return null; {
} Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is not a valid device", props.GatewayDeviceKey);
Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is a valid device", props.GatewayDeviceKey); return null;
gateway = gatewayDev.GateWay; }
} Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is a valid device", props.GatewayDeviceKey);
gateway = gatewayDev.GateWay;
if (gateway == null) }
{
Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is not a valid gateway", props.GatewayDeviceKey); if (gateway == null)
return null; {
} Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is not a valid gateway", props.GatewayDeviceKey);
return null;
Hr1x0WirelessRemoteBase remoteBase; }
switch (type)
{ Hr1x0WirelessRemoteBase remoteBase;
case ("hr100"): switch (type)
remoteBase = new Hr100(rfId, gateway); {
break; case ("hr100"):
case ("hr150"): remoteBase = new Hr100(rfId, gateway);
remoteBase = new Hr150(rfId, gateway); break;
break; case ("hr150"):
case ("hr310"): remoteBase = new Hr150(rfId, gateway);
remoteBase = new Hr310(rfId, gateway); break;
break; case ("hr310"):
default: remoteBase = new Hr310(rfId, gateway);
return null; break;
} default:
return null;
// register the device when using an internal RF gateway }
if (props.GatewayDeviceKey == "processor")
{ // register the device when using an internal RF gateway
remoteBase.RegisterWithLogging(config.Key); if (props.GatewayDeviceKey == "processor")
} {
remoteBase.RegisterWithLogging(config.Key);
return remoteBase; }
}
return remoteBase;
#endregion }
#region Factory #endregion
public class Hrxx0WirelessRemoteControllerFactory : EssentialsDeviceFactory<Hrxx0WirelessRemoteController>
{ #region Factory
public Hrxx0WirelessRemoteControllerFactory() public class Hrxx0WirelessRemoteControllerFactory : EssentialsDeviceFactory<Hrxx0WirelessRemoteController>
{ {
TypeNames = new List<string>() { "hr100", "hr150", "hr310" }; public Hrxx0WirelessRemoteControllerFactory()
} {
TypeNames = new List<string>() { "hr100", "hr150", "hr310" };
public override EssentialsDevice BuildDevice(DeviceConfig dc) }
{
Debug.Console(1, "Factory Attempting to create new HR-x00 Remote Device"); public override EssentialsDevice BuildDevice(DeviceConfig dc)
{
return new Hrxx0WirelessRemoteController(dc.Key, GetHr1x0WirelessRemote, dc); Debug.Console(1, "Factory Attempting to create new HR-x00 Remote Device");
}
} return new Hrxx0WirelessRemoteController(dc.Key, GetHr1x0WirelessRemote, dc);
#endregion }
}
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) #endregion
{
var joinMap = new Hrxxx0WirelessRemoteControllerJoinMap(joinStart); public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
{
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey); var joinMap = new Hrxxx0WirelessRemoteControllerJoinMap(joinStart);
if (!string.IsNullOrEmpty(joinMapSerialized)) var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
joinMap = JsonConvert.DeserializeObject<Hrxxx0WirelessRemoteControllerJoinMap>(joinMapSerialized);
if (!string.IsNullOrEmpty(joinMapSerialized))
if (bridge != null) joinMap = JsonConvert.DeserializeObject<Hrxxx0WirelessRemoteControllerJoinMap>(joinMapSerialized);
{
bridge.AddJoinMap(Key, joinMap); if (bridge != null)
} {
else bridge.AddJoinMap(Key, joinMap);
{ }
Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device."); else
} {
Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device.");
//List<string> ExcludedKeys = new List<string>(); }
foreach (var feedback in Feedbacks)
{ //List<string> ExcludedKeys = new List<string>();
var myFeedback = feedback; foreach (var feedback in Feedbacks)
{
var joinData = var myFeedback = feedback;
joinMap.Joins.FirstOrDefault(
x => var joinData =
x.Key.Equals(myFeedback.Key, StringComparison.InvariantCultureIgnoreCase)); joinMap.Joins.FirstOrDefault(
x =>
if (string.IsNullOrEmpty((joinData.Key))) continue; x.Key.Equals(myFeedback.Key, StringComparison.InvariantCultureIgnoreCase));
var name = joinData.Key; if (string.IsNullOrEmpty((joinData.Key))) continue;
var join = joinData.Value;
var name = joinData.Key;
if (join.Metadata.JoinType == eJoinType.Digital) var join = joinData.Value;
{
Debug.Console(0, this, "Linking Bool Feedback '{0}' to join {1}", name, join.JoinNumber); if (join.Metadata.JoinType == eJoinType.Digital)
var someFeedback = myFeedback as BoolFeedback; {
if(someFeedback == null) continue; Debug.Console(0, this, "Linking Bool Feedback '{0}' to join {1}", name, join.JoinNumber);
someFeedback.LinkInputSig(trilist.BooleanInput[join.JoinNumber]); var someFeedback = myFeedback as BoolFeedback;
} if(someFeedback == null) continue;
if (join.Metadata.JoinType == eJoinType.Analog) someFeedback.LinkInputSig(trilist.BooleanInput[join.JoinNumber]);
{ }
Debug.Console(0, this, "Linking Analog Feedback '{0}' to join {1}", name, join.JoinNumber); if (join.Metadata.JoinType == eJoinType.Analog)
var someFeedback = myFeedback as IntFeedback; {
if (someFeedback == null) continue; Debug.Console(0, this, "Linking Analog Feedback '{0}' to join {1}", name, join.JoinNumber);
someFeedback.LinkInputSig(trilist.UShortInput[join.JoinNumber]); var someFeedback = myFeedback as IntFeedback;
} if (someFeedback == null) continue;
if (join.Metadata.JoinType == eJoinType.Serial) someFeedback.LinkInputSig(trilist.UShortInput[join.JoinNumber]);
{ }
Debug.Console(0, this, "Linking Serial Feedback '{0}' to join {1}", name, join.JoinNumber); if (join.Metadata.JoinType == eJoinType.Serial)
var someFeedback = myFeedback as StringFeedback; {
if (someFeedback == null) continue; Debug.Console(0, this, "Linking Serial Feedback '{0}' to join {1}", name, join.JoinNumber);
someFeedback.LinkInputSig(trilist.StringInput[join.JoinNumber]); var someFeedback = myFeedback as StringFeedback;
} if (someFeedback == null) continue;
} someFeedback.LinkInputSig(trilist.StringInput[join.JoinNumber]);
}
//var newJoinKeys = joinMap.Joins.Keys.Except(ExcludedKeys).ToList(); }
//var newJoinMap = newJoinKeys.Where(k => joinMap.Joins.ContainsKey(k)).Select(k => joinMap.Joins[k]); //var newJoinKeys = joinMap.Joins.Keys.Except(ExcludedKeys).ToList();
//var newJoinMap = newJoinKeys.Where(k => joinMap.Joins.ContainsKey(k)).Select(k => joinMap.Joins[k]);
Debug.Console(2, this, "There are {0} remote buttons", _remote.Button.Count);
for (uint i = 1; i <= _remote.Button.Count; i++)
{ Debug.Console(2, this, "There are {0} remote buttons", _remote.Button.Count);
Debug.Console(2, this, "Attempting to link join index {0}", i); for (uint i = 1; i <= _remote.Button.Count; i++)
var index = i; {
var joinData = Debug.Console(2, this, "Attempting to link join index {0}", i);
joinMap.Joins.FirstOrDefault( var index = i;
o => var joinData =
o.Key.Equals(_remote.Button[index].Name.ToString(), joinMap.Joins.FirstOrDefault(
StringComparison.InvariantCultureIgnoreCase)); o =>
o.Key.Equals(_remote.Button[index].Name.ToString(),
if (string.IsNullOrEmpty((joinData.Key))) continue; StringComparison.InvariantCultureIgnoreCase));
var join = joinData.Value; if (string.IsNullOrEmpty((joinData.Key))) continue;
var name = joinData.Key;
var join = joinData.Value;
Debug.Console(2, this, "Setting User Object for '{0}'", name); var name = joinData.Key;
if (join.Metadata.JoinType == eJoinType.Digital)
{ Debug.Console(2, this, "Setting User Object for '{0}'", name);
_remote.Button[i].SetButtonAction((b) => trilist.BooleanInput[join.JoinNumber].BoolValue = b); if (join.Metadata.JoinType == eJoinType.Digital)
} {
} _remote.Button[i].SetButtonAction((b) => trilist.BooleanInput[join.JoinNumber].BoolValue = b);
}
trilist.OnlineStatusChange += (d, args) => }
{
if (!args.DeviceOnLine) return; trilist.OnlineStatusChange += (d, args) =>
{
foreach (var feedback in Feedbacks) if (!args.DeviceOnLine) return;
{
feedback.FireUpdate(); foreach (var feedback in Feedbacks)
} {
feedback.FireUpdate();
}; }
}
public void SetTrilistBool(BasicTriList trilist, uint join, bool b) };
{ }
trilist.BooleanInput[join].BoolValue = b; public void SetTrilistBool(BasicTriList trilist, uint join, bool b)
} {
} trilist.BooleanInput[join].BoolValue = b;
} }
}
}