Skip to content

Commit 2df6566

Browse files
Copilotcdenig
andauthored
refactor: reduce PR scope and rename ActiveInput model
Agent-Logs-Url: https://github.com/PepperDash/epi-lg-display/sessions/39975e5a-7b51-4efe-97b0-7d32fe92dd5c Co-authored-by: cdenig <86131648+cdenig@users.noreply.github.com>
1 parent eafab84 commit 2df6566

3 files changed

Lines changed: 87 additions & 180 deletions

File tree

README.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,9 @@ This repo contains a plugin for use with [PepperDash Essentials](https://github.
3838
"stopBits": 1
3939
}
4040
},
41-
"activeInputs": [ //optional: only expose these inputs in the plugin
42-
{
43-
"key": "hdmiIn1",
44-
"name": "HDMI 1"
45-
},
46-
{
47-
"key": "hdmiIn2",
48-
"name": "HDMI 2"
49-
},
50-
{
51-
"key": "displayPortIn1",
52-
"name": "DisplayPort"
53-
}
54-
],
55-
"friendlyNames": [ //optional: rename/hide configured inputs
41+
"friendlyNames": [ //if you want to use friendly names, add this section
5642
{
57-
"inputKey": "90", //input key to rename/hide (for example: 90, 91, 92, 93, c0)
43+
"inputKey": "90", //The input key for the input you want to use a friendly name for, this has to be a valid input key(90,91,c0)
5844
"name": "Friendly Name 1", //The desired name to be displayed on the screen
5945
"hideInput": false //if set to true, the input will not be displayed in the list of inputs
6046
},
@@ -70,6 +56,15 @@ This repo contains a plugin for use with [PepperDash Essentials](https://github.
7056

7157
}
7258
],
59+
"activeInputs": [ //optional: only expose these inputs in plugin selectable inputs
60+
{
61+
"key": "hdmi1", //supports aliases like hdmi1/hdmiin1/90
62+
"name": "Cable Box" //optional override name
63+
},
64+
{
65+
"key": "c0" //displayport (displayport/displayport1/displayportin1/c0)
66+
}
67+
],
7368
}
7469

7570
}
@@ -81,7 +76,7 @@ For more configuration information, see the [PepperDash Essentials wiki](https:/
8176

8277
## GitHub Actions
8378

84-
This repo contains two GitHub Actions workflows that will build this project automatically. Modify the SOLUTION_PATH and SOLUTION_FILE environment variables as needed. Any branches named `feature/*`, `release/*`, `hotfix/*` or `development` will automatically be built with the action and create a release in the repository with a version number based on the latest release on the master branch. If there are no releases yet, the version number will be 0.0.1. The version number will be modified based on what branch triggered the build:
79+
This repo contains two GitHub Action workflows that will build this project automatically. Modify the SOLUTION_PATH and SOLUTION_FILE environment variables as needed. Any branches named `feature/*`, `release/*`, `hotfix/*` or `development` will automatically be built with the action and create a release in the repository with a version number based on the latest release on the master branch. If there are no releases yet, the version number will be 0.0.1. The version number will be modified based on what branch triggered the build:
8580

8681
- `feature` branch builds will be tagged with an `alpha` descriptor, with the Action run appended: `0.0.1-alpha-1`
8782
- `development` branch builds will be tagged with a `beta` descriptor, with the Action run appended: `0.0.1-beta-2`

src/LgDisplayController.cs

Lines changed: 70 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
44
using System.Linq;
@@ -57,20 +57,21 @@ public LgDisplayController(string key, string name, LgDisplayPropertiesConfig co
5757
receiveQueue = new GenericQueue(key + "-queue");
5858

5959
this.config = config;
60-
if (this.config == null)
60+
var props = config;
61+
if (props == null)
6162
{
6263
Debug.LogError(this, "Display configuration must be included");
6364
return;
6465
}
65-
smallDisplay = this.config.SmallDisplay;
66-
Id = !string.IsNullOrEmpty(this.config.Id) ? this.config.Id : "01";
67-
upperLimit = this.config.volumeUpperLimit;
68-
lowerLimit = this.config.volumeLowerLimit;
69-
overrideWol = this.config.OverrideWol;
70-
pollIntervalMs = this.config.pollIntervalMs > 1999 ? this.config.pollIntervalMs : 10000;
71-
coolingTimeMs = this.config.coolingTimeMs > 0 ? this.config.coolingTimeMs : 10000;
72-
warmingTimeMs = this.config.warmingTimeMs > 0 ? this.config.warmingTimeMs : 8000;
73-
//UdpSocketKey = this.config.udpSocketKey;
66+
smallDisplay = props.SmallDisplay;
67+
Id = !string.IsNullOrEmpty(props.Id) ? props.Id : "01";
68+
upperLimit = props.volumeUpperLimit;
69+
lowerLimit = props.volumeLowerLimit;
70+
overrideWol = props.OverrideWol;
71+
pollIntervalMs = props.pollIntervalMs > 1999 ? props.pollIntervalMs : 10000;
72+
coolingTimeMs = props.coolingTimeMs > 0 ? props.coolingTimeMs : 10000;
73+
warmingTimeMs = props.warmingTimeMs > 0 ? props.warmingTimeMs : 8000;
74+
//UdpSocketKey = props.udpSocketKey;
7475

7576
InputNumberFeedback = new IntFeedback(() =>
7677
{
@@ -576,186 +577,97 @@ public override bool CustomActivate()
576577

577578
private void SetupInputs()
578579
{
579-
if (this.config.ActiveInputs != null && this.config.ActiveInputs.Count > 0)
580+
var defaultInputs = new Dictionary<string, ISelectableItem>
581+
{
582+
{ "90", new LgInput("90", "HDMI 1", this) },
583+
{ "91", new LgInput("91", "HDMI 2", this) },
584+
{ "92", new LgInput("92", "HDMI 3", this) },
585+
{ "93", new LgInput("93", "HDMI 4", this) },
586+
{ "c0", new LgInput("c0", "DisplayPort", this) },
587+
};
588+
589+
if (config.ActiveInputs != null && config.ActiveInputs.Count > 0)
580590
{
581591
Inputs = new LgInputs { Items = new Dictionary<string, ISelectableItem>() };
582592

583-
var activeInputsMap = this.config.ActiveInputs
593+
var activeInputsMap = config.ActiveInputs
584594
.Where(ai => !string.IsNullOrEmpty(ai.Key))
585595
.GroupBy(ai => ai.Key, StringComparer.OrdinalIgnoreCase)
586596
.ToDictionary(
587-
g => g.Key,
597+
g => g.Key.ToLowerInvariant(),
588598
g => g.Last().Name,
589599
StringComparer.OrdinalIgnoreCase
590600
);
591601

592-
var allInputs = new Dictionary<string, KeyValuePair<string, LgInput>>(StringComparer.OrdinalIgnoreCase)
602+
var inputAliases = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
593603
{
594-
{
595-
"hdmi1",
596-
new KeyValuePair<string, LgInput>(
597-
"90",
598-
new LgInput("90", "HDMI 1", this)
599-
)
600-
},
601-
{
602-
"hdmiin1",
603-
new KeyValuePair<string, LgInput>(
604-
"90",
605-
new LgInput("90", "HDMI 1", this)
606-
)
607-
},
608-
{
609-
"90",
610-
new KeyValuePair<string, LgInput>(
611-
"90",
612-
new LgInput("90", "HDMI 1", this)
613-
)
614-
},
615-
{
616-
"hdmi2",
617-
new KeyValuePair<string, LgInput>(
618-
"91",
619-
new LgInput("91", "HDMI 2", this)
620-
)
621-
},
622-
{
623-
"hdmiin2",
624-
new KeyValuePair<string, LgInput>(
625-
"91",
626-
new LgInput("91", "HDMI 2", this)
627-
)
628-
},
629-
{
630-
"91",
631-
new KeyValuePair<string, LgInput>(
632-
"91",
633-
new LgInput("91", "HDMI 2", this)
634-
)
635-
},
636-
{
637-
"hdmi3",
638-
new KeyValuePair<string, LgInput>(
639-
"92",
640-
new LgInput("92", "HDMI 3", this)
641-
)
642-
},
643-
{
644-
"hdmiin3",
645-
new KeyValuePair<string, LgInput>(
646-
"92",
647-
new LgInput("92", "HDMI 3", this)
648-
)
649-
},
650-
{
651-
"92",
652-
new KeyValuePair<string, LgInput>(
653-
"92",
654-
new LgInput("92", "HDMI 3", this)
655-
)
656-
},
657-
{
658-
"hdmi4",
659-
new KeyValuePair<string, LgInput>(
660-
"93",
661-
new LgInput("93", "HDMI 4", this)
662-
)
663-
},
664-
{
665-
"hdmiin4",
666-
new KeyValuePair<string, LgInput>(
667-
"93",
668-
new LgInput("93", "HDMI 4", this)
669-
)
670-
},
671-
{
672-
"93",
673-
new KeyValuePair<string, LgInput>(
674-
"93",
675-
new LgInput("93", "HDMI 4", this)
676-
)
677-
},
678-
{
679-
"displayport",
680-
new KeyValuePair<string, LgInput>(
681-
"c0",
682-
new LgInput("c0", "DisplayPort", this)
683-
)
684-
},
685-
{
686-
"displayport1",
687-
new KeyValuePair<string, LgInput>(
688-
"c0",
689-
new LgInput("c0", "DisplayPort", this)
690-
)
691-
},
692-
{
693-
"displayportin1",
694-
new KeyValuePair<string, LgInput>(
695-
"c0",
696-
new LgInput("c0", "DisplayPort", this)
697-
)
698-
},
699-
{
700-
"c0",
701-
new KeyValuePair<string, LgInput>(
702-
"c0",
703-
new LgInput("c0", "DisplayPort", this)
704-
)
705-
},
604+
{ "hdmi1", "90" },
605+
{ "hdmiin1", "90" },
606+
{ "90", "90" },
607+
{ "hdmi2", "91" },
608+
{ "hdmiin2", "91" },
609+
{ "91", "91" },
610+
{ "hdmi3", "92" },
611+
{ "hdmiin3", "92" },
612+
{ "92", "92" },
613+
{ "hdmi4", "93" },
614+
{ "hdmiin4", "93" },
615+
{ "93", "93" },
616+
{ "displayport", "c0" },
617+
{ "displayport1", "c0" },
618+
{ "displayportin1", "c0" },
619+
{ "c0", "c0" },
706620
};
707621

708622
foreach (var activeInput in activeInputsMap)
709623
{
710-
if (allInputs.TryGetValue(activeInput.Key, out var input))
624+
if (!inputAliases.TryGetValue(activeInput.Key, out var inputCode))
625+
{
626+
continue;
627+
}
628+
629+
if (!defaultInputs.TryGetValue(inputCode, out var input))
711630
{
712-
Inputs.Items[input.Key] = new LgInput(
713-
input.Value.Key,
714-
string.IsNullOrEmpty(activeInput.Value) ? input.Value.Name : activeInput.Value,
715-
this
716-
);
631+
continue;
717632
}
633+
634+
var lgInput = input as LgInput;
635+
if (lgInput == null)
636+
{
637+
continue;
638+
}
639+
640+
Inputs.Items[lgInput.Key] = new LgInput(
641+
lgInput.Key,
642+
string.IsNullOrEmpty(activeInput.Value) ? lgInput.Name : activeInput.Value,
643+
this
644+
);
718645
}
719646

720647
if (Inputs.Items.Count == 0)
721648
{
722649
Inputs = new LgInputs
723650
{
724-
Items = new Dictionary<string, ISelectableItem>
725-
{
726-
{ "90", new LgInput("90", "HDMI 1", this) },
727-
{ "91", new LgInput("91", "HDMI 2", this) },
728-
{ "92", new LgInput("92", "HDMI 3", this) },
729-
{ "93", new LgInput("93", "HDMI 4", this) },
730-
{ "c0", new LgInput("c0", "DisplayPort", this) },
731-
}
651+
Items = new Dictionary<string, ISelectableItem>(defaultInputs)
732652
};
733653
}
734654
}
735655
else
736656
{
737657
Inputs = new LgInputs
738658
{
739-
Items = new Dictionary<string, ISelectableItem>
740-
{
741-
{ "90", new LgInput("90", "HDMI 1", this) },
742-
{ "91", new LgInput("91", "HDMI 2", this) },
743-
{ "92", new LgInput("92", "HDMI 3", this) },
744-
{ "93", new LgInput("93", "HDMI 4", this) },
745-
{ "c0", new LgInput("c0", "DisplayPort", this) },
746-
}
659+
Items = defaultInputs
747660
};
748661
}
749662

750-
ApplyFriendlyNames();
751-
663+
ApplyFriendlyNames(config);
752664
}
753-
private void ApplyFriendlyNames()
665+
private void ApplyFriendlyNames(LgDisplayPropertiesConfig config)
754666
{
755-
if (this.config?.FriendlyNames == null || Inputs == null || Inputs.Items == null)
667+
if (config?.FriendlyNames == null || Inputs == null || Inputs.Items == null)
756668
return;
757669

758-
foreach (var friendly in this.config.FriendlyNames)
670+
foreach (var friendly in config.FriendlyNames)
759671
{
760672
if (!string.IsNullOrEmpty(friendly.InputKey) && !string.IsNullOrEmpty(friendly.Name))
761673
{
@@ -1241,15 +1153,15 @@ public void UpdateInputFb(string s)
12411153
InputNumber = InputPorts.ToList().IndexOf(newInput) + 1;
12421154
}
12431155

1244-
if (Inputs.Items.ContainsKey(s.ToLowerInvariant()))
1156+
if (Inputs.Items.ContainsKey(normalizedInput))
12451157
{
12461158
foreach (var item in Inputs.Items)
12471159
{
1248-
item.Value.IsSelected = item.Key.Equals(s.ToLowerInvariant());
1160+
item.Value.IsSelected = item.Key.Equals(normalizedInput);
12491161
}
1250-
}
12511162

1252-
Inputs.CurrentItem = s.ToLowerInvariant();
1163+
Inputs.CurrentItem = normalizedInput;
1164+
}
12531165
}
12541166

12551167
/// <summary>

src/LgDisplayPropertiesConfig.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public class LgDisplayPropertiesConfig
4040
public List<FriendlyName> FriendlyNames { get; set; }
4141

4242
[JsonProperty("activeInputs")]
43-
public List<ActiveInputs> ActiveInputs { get; set; }
43+
public List<ActiveInput> ActiveInputs { get; set; }
4444

4545
public LgDisplayPropertiesConfig()
4646
{
4747
FriendlyNames = new List<FriendlyName>();
48-
ActiveInputs = new List<ActiveInputs>();
48+
ActiveInputs = new List<ActiveInput>();
4949
}
5050
}
5151

@@ -61,19 +61,19 @@ public class FriendlyName
6161
public bool HideInput { get; set; }
6262
}
6363

64-
public class ActiveInputs : IKeyName
64+
public class ActiveInput : IKeyName
6565
{
6666
[JsonProperty("key")]
6767
public string Key { get; set; }
6868

6969
[JsonProperty("name")]
7070
public string Name { get; set; }
7171

72-
public ActiveInputs()
72+
public ActiveInput()
7373
{
7474
Key = string.Empty;
7575
Name = string.Empty;
7676
}
7777
}
7878

79-
}
79+
}

0 commit comments

Comments
 (0)