Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void SavePresets(List<PresetChannel> presets)
protected override void RegisterActions()

{
AddAction("/presets/fullStatus", (id, content) =>
AddAction("/fullStatus", (id, content) =>
{
this.LogInformation("getting full status for client {id}", id);
try
Expand All @@ -56,7 +56,7 @@ protected override void RegisterActions()
}
});

AddAction("/presets/recall", (id, content) =>
AddAction("/recall", (id, content) =>
{
var p = content.ToObject<PresetChannelMessage>();

Expand All @@ -70,7 +70,7 @@ protected override void RegisterActions()
RecallPreset(dev, p.Preset.Channel);
});

AddAction("/presets/save", (id, content) =>
AddAction("/save", (id, content) =>
{
var presets = content.ToObject<List<PresetChannel>>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using System;
using System.Collections.Generic;

namespace PepperDash.Essentials.AppServer.Messengers
{
Expand Down Expand Up @@ -56,10 +59,32 @@ protected override void RegisterActions()

private void SendFullStatus()
{
var stateObject = new JObject();
stateObject[_propName] = JToken.FromObject(itemDevice, serializer);
PostStatusMessage(stateObject);
try
{
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; }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,11 @@ public void AddDeviceMessenger(IMobileControlMessenger 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)
Expand Down Expand Up @@ -2230,16 +2234,14 @@ private void ParseStreamRx(string messageText)
// /room/roomAB

// 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);
break;
}

var handlers = handlersKv.Value;
}

foreach (var handler in handlers)
{
Expand Down