Skip to content

Commit

Permalink
Replace numeric input names with user-defined names when available
Browse files Browse the repository at this point in the history
  • Loading branch information
Jalle19 committed Sep 12, 2024
1 parent 6f51127 commit 96d1f10
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions custom_components/extron/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
logger = logging.getLogger(__name__)


def make_numeric_source_bidict(num_sources: int) -> bidict:
def make_numeric_source_bidict(num_sources: int, input_names: list[str]) -> bidict:
bd = bidict()

for i in range(num_sources):
bd.put(i, str(i))
# Use user-defined input name for the source when available
bd.put(i, input_names[i - 1] if i - 1 < len(input_names) else str(i))

return bd

Expand Down Expand Up @@ -122,9 +123,8 @@ def source(self):
def source_list(self):
return list(self._source_bidict.values())

@staticmethod
def make_source_bidict() -> bidict:
return make_numeric_source_bidict(5)
def make_source_bidict(self) -> bidict:
return make_numeric_source_bidict(5, self._input_names)

async def async_select_source(self, source):
await self._ssp.select_input(self._source_bidict.inverse.get(source))
Expand Down Expand Up @@ -175,13 +175,13 @@ def make_source_bidict(self) -> bidict:
sw = model_name.split(" ")[0]

if sw == "SW2":
return make_numeric_source_bidict(2)
return make_numeric_source_bidict(2, self._input_names)
elif sw == "SW4":
return make_numeric_source_bidict(4)
return make_numeric_source_bidict(4, self._input_names)
elif sw == "SW6":
return make_numeric_source_bidict(6)
return make_numeric_source_bidict(6, self._input_names)
else:
return make_numeric_source_bidict(8)
return make_numeric_source_bidict(8, self._input_names)

async def async_select_source(self, source: str):
await self._hdmi_switcher.select_input(int(source))
Expand Down

0 comments on commit 96d1f10

Please sign in to comment.