Skip to content

Commit

Permalink
[mqtt.generic] Fix ClassCastException when receiving ON/OFF on a dimm…
Browse files Browse the repository at this point in the history
…er channel (#17980)

Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng authored Dec 25, 2024
1 parent 2f2cf22 commit d049995
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public PercentageValue(@Nullable BigDecimal min, @Nullable BigDecimal max, @Null

@Override
public Command parseCommand(Command command) throws IllegalArgumentException {
PercentType oldvalue = (state instanceof UnDefType) ? new PercentType() : (PercentType) state;
PercentType oldvalue = (state instanceof UnDefType) ? new PercentType() : state.as(PercentType.class);
// Nothing do to -> We have received a percentage
if (command instanceof PercentType percent) {
return percent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ public void percentCalc() {
assertThat(v.parseCommand(new DecimalType(10.0)), is(PercentType.ZERO));
assertThat(v.getMQTTpublishValue(PercentType.ZERO, null), is("10"));

v.update(OnOffType.OFF);

assertThat(v.parseCommand(OnOffType.ON), is(OnOffType.ON));
assertThat(v.getMQTTpublishValue(OnOffType.ON, null), is("110"));
assertThat(v.parseCommand(OnOffType.OFF), is(OnOffType.OFF));
Expand Down

0 comments on commit d049995

Please sign in to comment.