mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-11 19:44:52 +00:00
fix: Fix typos and enhance item selection handling
Corrected parameter name in GenericUdpServer constructor. Added new action for item selection in ISelectableItemsMessenger with error handling for missing or invalid keys. Updated SetItems method to improve clarity and ensure proper clearing and re-adding of item actions.
This commit is contained in:
@@ -131,14 +131,14 @@ namespace PepperDash.Core
|
||||
/// <param name="key"></param>
|
||||
/// <param name="address"></param>
|
||||
/// <param name="port"></param>
|
||||
/// <param name="buffefSize"></param>
|
||||
public GenericUdpServer(string key, string address, int port, int buffefSize)
|
||||
/// <param name="bufferSize"></param>
|
||||
public GenericUdpServer(string key, string address, int port, int bufferSize)
|
||||
: base(key)
|
||||
{
|
||||
StreamDebugging = new CommunicationStreamDebugging(key);
|
||||
Hostname = address;
|
||||
Port = port;
|
||||
BufferSize = buffefSize;
|
||||
BufferSize = bufferSize;
|
||||
|
||||
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
||||
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
|
||||
|
||||
@@ -41,6 +41,32 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
|
||||
AddAction("/itemsStatus", (id, content) => SendFullStatus(id));
|
||||
|
||||
AddAction("/selectItem", (id, content) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var key = content.ToObject<TKey>();
|
||||
|
||||
if (key == null)
|
||||
{
|
||||
this.LogError("No key specified to select");
|
||||
return;
|
||||
}
|
||||
if (itemDevice.Items.ContainsKey((TKey)Convert.ChangeType(key, typeof(TKey))))
|
||||
{
|
||||
itemDevice.Items[(TKey)Convert.ChangeType(key, typeof(TKey))].Select();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.LogError("Key {0} not found in items", key);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.LogError("Error selecting item: {0}", e.Message);
|
||||
}
|
||||
});
|
||||
|
||||
itemDevice.ItemsUpdated += (sender, args) =>
|
||||
{
|
||||
SetItems();
|
||||
@@ -59,18 +85,21 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
/// </summary>
|
||||
private void SetItems()
|
||||
{
|
||||
/// Clear out any existing item actions
|
||||
foreach (var item in _itemKeys)
|
||||
if (_itemKeys != null && _itemKeys.Count > 0)
|
||||
{
|
||||
RemoveAction($"/{item}");
|
||||
/// Clear out any existing item actions
|
||||
foreach (var item in _itemKeys)
|
||||
{
|
||||
RemoveAction($"/{item}");
|
||||
}
|
||||
|
||||
_itemKeys.Clear();
|
||||
}
|
||||
|
||||
_itemKeys.Clear();
|
||||
|
||||
foreach (var input in itemDevice.Items)
|
||||
foreach (var item in itemDevice.Items)
|
||||
{
|
||||
var key = input.Key;
|
||||
var localItem = input.Value;
|
||||
var key = item.Key;
|
||||
var localItem = item.Value;
|
||||
|
||||
AddAction($"/{key}", (id, content) =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user