Skip to content

Commit

Permalink
Merge pull request #336 from nada-ben-ali/NaBe/fix_multiplexer_encode…
Browse files Browse the repository at this point in the history
…_into_pdu_method

multiplexer.encode_into_pdu: Fix when case_spec is a string and it is the default case
  • Loading branch information
andlaus authored Aug 29, 2024
2 parents 6e816a3 + e7381be commit 89e98e0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion odxtools/multiplexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,22 @@ def encode_into_pdu(self, physical_value: ParameterValue, encode_state: EncodeSt
f"(case_name, content_value) tuple instead of as '{physical_value!r}'")

mux_case: Union[MultiplexerCase, MultiplexerDefaultCase]
applicable_cases: List[Union[MultiplexerCase, MultiplexerDefaultCase]]

if isinstance(case_spec, str):
applicable_cases = [x for x in self.cases if x.short_name == case_spec]
if not applicable_cases and self.default_case:
applicable_cases.append(self.default_case)
if len(applicable_cases) == 0:
raise EncodeError(
f"Multiplexer {self.short_name} does not know any case called {case_spec}")

odxassert(len(applicable_cases) == 1)
mux_case = applicable_cases[0]
key_value, _ = self._get_case_limits(mux_case)
if isinstance(mux_case, MultiplexerCase):
key_value, _ = self._get_case_limits(mux_case)
else:
key_value = 0
elif isinstance(case_spec, int):
applicable_cases = []
for x in self.cases:
Expand Down

0 comments on commit 89e98e0

Please sign in to comment.