From 6713ea53f2669649fc9244d0ffa949d0cb3de8e7 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 1 Apr 2025 09:44:18 -0500 Subject: [PATCH] fix: move current volume action creation after power registrations --- .../MobileControlEssentialsRoomBridge.cs | 115 +++++++++--------- 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/src/PepperDash.Essentials.MobileControl/RoomBridges/MobileControlEssentialsRoomBridge.cs b/src/PepperDash.Essentials.MobileControl/RoomBridges/MobileControlEssentialsRoomBridge.cs index ac53a1d4..9009c4cc 100644 --- a/src/PepperDash.Essentials.MobileControl/RoomBridges/MobileControlEssentialsRoomBridge.cs +++ b/src/PepperDash.Essentials.MobileControl/RoomBridges/MobileControlEssentialsRoomBridge.cs @@ -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>(); - - - 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>(); + + + 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)