-
Notifications
You must be signed in to change notification settings - Fork 85
Feature/demo room #1492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature/demo room #1492
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6bb6e7a
feat: add MockLightingDevice and configuration classes for simulated …
ndorin 40ebacd
feat: enhance MockRoutingMidpoint to support video sync detection and…
ndorin 3152602
Merge remote-tracking branch 'origin/release' into feature/demo-room
ndorin 32311dd
fix: avoid enumeration issues by copying current source keys and hand…
ndorin 264bb09
feat: add ICommunicationMonitor implementation to mock devices and cr…
ndorin 9e28671
fix: update app URL resolution to use ResolveAppUrlHost for improved …
ndorin e23d629
feat: enhance GenericSink to track last switched input port and impro…
ndorin f734650
feat: enhance routing logic for midpoints to handle null output ports…
ndorin cb7970b
fix: feedback update for current lighting scene
ndorin 59e1fb1
fix: track USB and per-signal route types in mock midpoint feedback
ndorin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
src/PepperDash.Essentials.Devices.Common/Lighting/MockLightingDevice.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using Crestron.SimplSharpPro.DeviceSupport; | ||
| using Newtonsoft.Json; | ||
| using PepperDash.Core.Logging; | ||
| using PepperDash.Essentials.Core; | ||
| using PepperDash.Essentials.Core.Bridges; | ||
| using PepperDash.Essentials.Core.Config; | ||
| using PepperDash.Essentials.Core.Lighting; | ||
|
|
||
| namespace PepperDash.Essentials.Devices.Common.Lighting; | ||
|
|
||
| /// <summary> | ||
| /// Scenes to simulate for a <see cref="MockLightingDevice"/>. | ||
| /// </summary> | ||
| public class MockLightingConfig | ||
| { | ||
| /// <summary> | ||
| /// Scenes to simulate, in display order. Defaults to a generic 3-scene set (On/Dim/Off) when | ||
| /// omitted so the device works with no config at all. | ||
| /// </summary> | ||
| [JsonProperty("scenes", NullValueHandling = NullValueHandling.Ignore)] | ||
| public List<MockLightingSceneConfig> Scenes { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// ID of the scene active on startup. Falls back to the first configured scene when unset | ||
| /// or when it does not match any configured scene. | ||
| /// </summary> | ||
| [JsonProperty("defaultSceneId", NullValueHandling = NullValueHandling.Ignore)] | ||
| public string DefaultSceneId { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// One configured scene. | ||
| /// </summary> | ||
| public class MockLightingSceneConfig | ||
| { | ||
| /// <summary> | ||
| /// Scene ID, referenced by the client's /selectScene request | ||
| /// </summary> | ||
| [JsonProperty("id")] | ||
| public string Id { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Display name for the scene | ||
| /// </summary> | ||
| [JsonProperty("name")] | ||
| public string Name { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Simulated lighting scene controller. No hardware behind it - selecting a scene just updates | ||
| /// <see cref="LightingBase.CurrentLightingScene"/> and fires feedback, exactly like a real DSP | ||
| /// or lighting processor would once the scene recall is acknowledged. | ||
| /// </summary> | ||
| public class MockLightingDevice : LightingBase, ICommunicationMonitor | ||
| { | ||
| /// <inheritdoc /> | ||
| /// <remarks>Always online: there's no real connection behind this mock to lose.</remarks> | ||
| public StatusMonitorBase CommunicationMonitor { get; } | ||
|
|
||
| private static readonly List<MockLightingSceneConfig> DefaultScenes = new List<MockLightingSceneConfig> | ||
| { | ||
| new MockLightingSceneConfig { Id = "on", Name = "On" }, | ||
| new MockLightingSceneConfig { Id = "dim", Name = "Dim" }, | ||
| new MockLightingSceneConfig { Id = "off", Name = "Off" }, | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the MockLightingDevice class | ||
| /// </summary> | ||
| /// <param name="key">The device key</param> | ||
| /// <param name="name">The device name</param> | ||
| /// <param name="config">Scenes to simulate; null falls back to a generic On/Dim/Off set</param> | ||
| public MockLightingDevice(string key, string name, MockLightingConfig config) | ||
| : base(key, name) | ||
| { | ||
| CommunicationMonitor = new MockCommunicationMonitor(this); | ||
|
|
||
| var scenesConfig = config?.Scenes != null && config.Scenes.Count > 0 | ||
| ? config.Scenes | ||
| : DefaultScenes; | ||
|
|
||
| LightingScenes = scenesConfig | ||
| .Select(s => new LightingScene { ID = s.Id, Name = s.Name }) | ||
| .ToList(); | ||
|
|
||
| CurrentLightingScene = LightingScenes.FirstOrDefault(s => s.ID == config?.DefaultSceneId) | ||
| ?? LightingScenes.FirstOrDefault() | ||
| ?? new LightingScene(); | ||
|
|
||
| CurrentLightingSceneFeedback = new IntFeedback("currentLightingScene", | ||
| () => LightingScenes.IndexOf(CurrentLightingScene)); | ||
| CurrentLightingSceneFeedback.FireUpdate(); | ||
|
|
||
| OnLightingSceneChange(); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override void SelectScene(LightingScene scene) | ||
| { | ||
| var match = LightingScenes.FirstOrDefault(s => s.ID == scene?.ID); | ||
|
|
||
| if (match == null) | ||
| { | ||
| this.LogWarning("No lighting scene with id '{sceneId}'", scene?.ID); | ||
| return; | ||
| } | ||
|
|
||
| this.LogInformation("Selecting lighting scene '{sceneId}'", match.ID); | ||
|
|
||
| CurrentLightingScene = match; | ||
| CurrentLightingSceneFeedback.FireUpdate(); | ||
| OnLightingSceneChange(); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) => | ||
| LinkLightingToApi(this, trilist, joinStart, joinMapKey, bridge); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Builds a <see cref="MockLightingDevice"/> for any config entry typed "mockLightingDevice". | ||
| /// </summary> | ||
| public class MockLightingDeviceFactory : EssentialsDeviceFactory<MockLightingDevice> | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the MockLightingDeviceFactory class | ||
| /// </summary> | ||
| public MockLightingDeviceFactory() | ||
| { | ||
| TypeNames = new List<string> { "mockLightingDevice" }; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override EssentialsDevice BuildDevice(DeviceConfig dc) | ||
| { | ||
| var config = dc.Properties?.ToObject<MockLightingConfig>(); | ||
|
|
||
| return new MockLightingDevice(dc.Key, dc.Name, config); | ||
| } | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
src/PepperDash.Essentials.Devices.Common/MockCommunicationMonitor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using PepperDash.Core; | ||
| using PepperDash.Essentials.Core; | ||
|
|
||
| namespace PepperDash.Essentials.Devices.Common; | ||
|
|
||
| /// <summary> | ||
| /// A <see cref="StatusMonitorBase"/> for mock devices, whose status is set directly rather than | ||
| /// derived from polling a real connection. Reports <see cref="MonitorStatus.IsOk"/> until told otherwise. | ||
| /// </summary> | ||
| public class MockCommunicationMonitor : StatusMonitorBase | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="MockCommunicationMonitor"/> class, reporting online. | ||
| /// </summary> | ||
| public MockCommunicationMonitor(IKeyed parent) : base(parent, 30000, 60000) | ||
| { | ||
| Status = MonitorStatus.IsOk; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override void Start() { } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override void Stop() { } | ||
|
|
||
| /// <summary> | ||
| /// Sets the monitor's current status. | ||
| /// </summary> | ||
| public void SetStatus(MonitorStatus status) => Status = status; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.