Compare commits

...

4 Commits

Author SHA1 Message Date
Neil Dorin
4e43565c1a Merge pull request #1239 from PepperDash/mc-fixes 2025-04-02 08:16:02 -06:00
Andrew Welker
97e157b5b6 fix: bring modifications made to plugin over 2025-04-02 08:39:08 -05:00
Jason DeVito
3411fe0cf3 Merge pull request #1235 from PepperDash/fix-volume-add-again
fix: move current volume action creation after power registrations
2025-04-01 10:09:54 -05:00
Andrew Welker
6713ea53f2 fix: move current volume action creation after power registrations 2025-04-01 09:44:18 -05:00
4 changed files with 96 additions and 70 deletions

View File

@@ -43,7 +43,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
protected override void RegisterActions()
{
AddAction("/presets/fullStatus", (id, content) =>
AddAction("/fullStatus", (id, content) =>
{
this.LogInformation("getting full status for client {id}", id);
try
@@ -56,7 +56,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
}
});
AddAction("/presets/recall", (id, content) =>
AddAction("/recall", (id, content) =>
{
var p = content.ToObject<PresetChannelMessage>();
@@ -70,7 +70,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
RecallPreset(dev, p.Preset.Channel);
});
AddAction("/presets/save", (id, content) =>
AddAction("/save", (id, content) =>
{
var presets = content.ToObject<List<PresetChannel>>();

View File

@@ -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
{
@@ -56,10 +59,32 @@ namespace PepperDash.Essentials.AppServer.Messengers
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; }
}
}

View File

@@ -1133,7 +1133,11 @@ namespace PepperDash.Essentials
_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)
@@ -2230,16 +2234,14 @@ Mobile Control Direct Server Infromation:
// /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)
{

View File

@@ -116,64 +116,6 @@ namespace PepperDash.Essentials.RoomBridges
if (Room is IRunDefaultPresentRoute defaultRoom)
AddAction("/defaultsource", (id, content) => defaultRoom.RunDefaultPresentRoute());
if (Room is IHasCurrentVolumeControls volumeRoom)
{
volumeRoom.CurrentVolumeDeviceChange += Room_CurrentVolumeDeviceChange;
if (volumeRoom.CurrentVolumeControls == null) return;
AddAction("/volumes/master/level", (id, content) =>
{
var msg = content.ToObject<MobileControlSimpleContent<ushort>>();
if (volumeRoom.CurrentVolumeControls is IBasicVolumeWithFeedback basicVolumeWithFeedback)
basicVolumeWithFeedback.SetVolume(msg.Value);
});
AddAction("/volumes/master/muteToggle", (id, content) => volumeRoom.CurrentVolumeControls.MuteToggle());
AddAction("/volumes/master/muteOn", (id, content) =>
{
if (volumeRoom.CurrentVolumeControls is IBasicVolumeWithFeedback basicVolumeWithFeedback)
basicVolumeWithFeedback.MuteOn();
});
AddAction("/volumes/master/muteOff", (id, content) =>
{
if (volumeRoom.CurrentVolumeControls is IBasicVolumeWithFeedback basicVolumeWithFeedback)
basicVolumeWithFeedback.MuteOff();
});
AddAction("/volumes/master/volumeUp", (id, content) => PressAndHoldHandler.HandlePressAndHold(DeviceKey, content, (b) =>
{
if (volumeRoom.CurrentVolumeControls is IBasicVolumeWithFeedback basicVolumeWithFeedback)
{
basicVolumeWithFeedback.VolumeUp(b);
}
}
));
AddAction("/volumes/master/volumeDown", (id, content) => PressAndHoldHandler.HandlePressAndHold(DeviceKey, content, (b) =>
{
if (volumeRoom.CurrentVolumeControls is IBasicVolumeWithFeedback basicVolumeWithFeedback)
{
basicVolumeWithFeedback.VolumeDown(b);
}
}
));
// Registers for initial volume events, if possible
if (volumeRoom.CurrentVolumeControls is IBasicVolumeWithFeedback currentVolumeDevice)
{
this.LogVerbose("Registering for volume feedback events");
currentVolumeDevice.MuteFeedback.OutputChange += MuteFeedback_OutputChange;
currentVolumeDevice.VolumeLevelFeedback.OutputChange += VolumeLevelFeedback_OutputChange;
}
}
if (Room is IHasCurrentSourceInfoChange sscRoom)
sscRoom.CurrentSourceChange += Room_CurrentSingleSourceChange;
@@ -212,6 +154,63 @@ namespace PepperDash.Essentials.RoomBridges
Room.IsWarmingUpFeedback.OutputChange += IsWarmingUpFeedback_OutputChange;
AddTechRoomActions();
if (Room is IHasCurrentVolumeControls volumeRoom)
{
volumeRoom.CurrentVolumeDeviceChange += Room_CurrentVolumeDeviceChange;
if (volumeRoom.CurrentVolumeControls == null) return;
AddAction("/volumes/master/level", (id, content) =>
{
var msg = content.ToObject<MobileControlSimpleContent<ushort>>();
if (volumeRoom.CurrentVolumeControls is IBasicVolumeWithFeedback basicVolumeWithFeedback)
basicVolumeWithFeedback.SetVolume(msg.Value);
});
AddAction("/volumes/master/muteToggle", (id, content) => volumeRoom.CurrentVolumeControls.MuteToggle());
AddAction("/volumes/master/muteOn", (id, content) =>
{
if (volumeRoom.CurrentVolumeControls is IBasicVolumeWithFeedback basicVolumeWithFeedback)
basicVolumeWithFeedback.MuteOn();
});
AddAction("/volumes/master/muteOff", (id, content) =>
{
if (volumeRoom.CurrentVolumeControls is IBasicVolumeWithFeedback basicVolumeWithFeedback)
basicVolumeWithFeedback.MuteOff();
});
AddAction("/volumes/master/volumeUp", (id, content) => PressAndHoldHandler.HandlePressAndHold(DeviceKey, content, (b) =>
{
if (volumeRoom.CurrentVolumeControls is IBasicVolumeWithFeedback basicVolumeWithFeedback)
{
basicVolumeWithFeedback.VolumeUp(b);
}
}
));
AddAction("/volumes/master/volumeDown", (id, content) => PressAndHoldHandler.HandlePressAndHold(DeviceKey, content, (b) =>
{
if (volumeRoom.CurrentVolumeControls is IBasicVolumeWithFeedback basicVolumeWithFeedback)
{
basicVolumeWithFeedback.VolumeDown(b);
}
}
));
// Registers for initial volume events, if possible
if (volumeRoom.CurrentVolumeControls is IBasicVolumeWithFeedback currentVolumeDevice)
{
this.LogVerbose("Registering for volume feedback events");
currentVolumeDevice.MuteFeedback.OutputChange += MuteFeedback_OutputChange;
currentVolumeDevice.VolumeLevelFeedback.OutputChange += VolumeLevelFeedback_OutputChange;
}
}
}
private void OnTouchPanelsUpdated(JToken content)