mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 12:44:58 +00:00
Merge pull request #1239 from PepperDash/mc-fixes
This commit is contained in:
@@ -43,7 +43,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||||||
protected override void RegisterActions()
|
protected override void RegisterActions()
|
||||||
|
|
||||||
{
|
{
|
||||||
AddAction("/presets/fullStatus", (id, content) =>
|
AddAction("/fullStatus", (id, content) =>
|
||||||
{
|
{
|
||||||
this.LogInformation("getting full status for client {id}", id);
|
this.LogInformation("getting full status for client {id}", id);
|
||||||
try
|
try
|
||||||
@@ -56,7 +56,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAction("/presets/recall", (id, content) =>
|
AddAction("/recall", (id, content) =>
|
||||||
{
|
{
|
||||||
var p = content.ToObject<PresetChannelMessage>();
|
var p = content.ToObject<PresetChannelMessage>();
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||||||
RecallPreset(dev, p.Preset.Channel);
|
RecallPreset(dev, p.Preset.Channel);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAction("/presets/save", (id, content) =>
|
AddAction("/save", (id, content) =>
|
||||||
{
|
{
|
||||||
var presets = content.ToObject<List<PresetChannel>>();
|
var presets = content.ToObject<List<PresetChannel>>();
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
|
using PepperDash.Core.Logging;
|
||||||
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
|
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.AppServer.Messengers
|
namespace PepperDash.Essentials.AppServer.Messengers
|
||||||
{
|
{
|
||||||
@@ -56,10 +59,32 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||||||
|
|
||||||
private void SendFullStatus()
|
private void SendFullStatus()
|
||||||
{
|
{
|
||||||
var stateObject = new JObject();
|
try
|
||||||
stateObject[_propName] = JToken.FromObject(itemDevice, serializer);
|
{
|
||||||
PostStatusMessage(stateObject);
|
this.LogInformation("Sending full status");
|
||||||
|
|
||||||
|
var stateObject = new ISelectableItemsStateMessage<TKey>
|
||||||
|
{
|
||||||
|
Items = itemDevice.Items,
|
||||||
|
CurrentItem = itemDevice.CurrentItem
|
||||||
|
};
|
||||||
|
|
||||||
|
PostStatusMessage(stateObject);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
this.LogError("Error sending full status: {0}", e.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ISelectableItemsStateMessage<TKey> : DeviceStateMessageBase
|
||||||
|
{
|
||||||
|
[JsonProperty("items")]
|
||||||
|
public Dictionary<TKey, ISelectableItem> Items { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("currentItem")]
|
||||||
|
public TKey CurrentItem { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1133,7 +1133,11 @@ namespace PepperDash.Essentials
|
|||||||
|
|
||||||
_messengers.Add(messenger.Key, messenger);
|
_messengers.Add(messenger.Key, messenger);
|
||||||
|
|
||||||
messenger.RegisterWithAppServer(this);
|
if (_initialized)
|
||||||
|
{
|
||||||
|
this.LogDebug("Registering messenger {messengerKey} AFTER initialization", messenger.Key);
|
||||||
|
messenger.RegisterWithAppServer(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddDefaultDeviceMessenger(IMobileControlMessenger messenger)
|
private void AddDefaultDeviceMessenger(IMobileControlMessenger messenger)
|
||||||
@@ -2230,16 +2234,14 @@ Mobile Control Direct Server Infromation:
|
|||||||
// /room/roomAB
|
// /room/roomAB
|
||||||
|
|
||||||
// Can't do direct comparison because it will match /room/roomA with /room/roomA/xxx instead of /room/roomAB/xxx
|
// Can't do direct comparison because it will match /room/roomA with /room/roomA/xxx instead of /room/roomAB/xxx
|
||||||
var handlersKv = _actionDictionary.FirstOrDefault(kv => message.Type.StartsWith(kv.Key + "/")); // adds trailing slash to ensure above case is handled
|
var handlers = _actionDictionary.Where(kv => message.Type.StartsWith(kv.Key + "/")).SelectMany(kv => kv.Value).ToList(); // adds trailing slash to ensure above case is handled
|
||||||
|
|
||||||
|
|
||||||
if (handlersKv.Key == null)
|
if (handlers.Count == 0)
|
||||||
{
|
{
|
||||||
this.LogInformation("-- Warning: Incoming message has no registered handler {type}", message.Type);
|
this.LogInformation("-- Warning: Incoming message has no registered handler {type}", message.Type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var handlers = handlersKv.Value;
|
|
||||||
|
|
||||||
foreach (var handler in handlers)
|
foreach (var handler in handlers)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user