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:
Neil Dorin
2025-10-09 09:40:46 -06:00
parent 419177ccd5
commit 0418f8a7cc
2 changed files with 40 additions and 11 deletions

View File

@@ -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);

View File

@@ -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) =>
{