Skip to content

Commit d049995

Browse files
authored
[mqtt.generic] Fix ClassCastException when receiving ON/OFF on a dimmer channel (openhab#17980)
Signed-off-by: Jimmy Tanagra <[email protected]>
1 parent 2f2cf22 commit d049995

File tree

2 files changed

+3
-1
lines changed
  • bundles/org.openhab.binding.mqtt.generic/src

2 files changed

+3
-1
lines changed

bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/PercentageValue.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public PercentageValue(@Nullable BigDecimal min, @Nullable BigDecimal max, @Null
7575

7676
@Override
7777
public Command parseCommand(Command command) throws IllegalArgumentException {
78-
PercentType oldvalue = (state instanceof UnDefType) ? new PercentType() : (PercentType) state;
78+
PercentType oldvalue = (state instanceof UnDefType) ? new PercentType() : state.as(PercentType.class);
7979
// Nothing do to -> We have received a percentage
8080
if (command instanceof PercentType percent) {
8181
return percent;

bundles/org.openhab.binding.mqtt.generic/src/test/java/org/openhab/binding/mqtt/generic/values/ValueTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ public void percentCalc() {
313313
assertThat(v.parseCommand(new DecimalType(10.0)), is(PercentType.ZERO));
314314
assertThat(v.getMQTTpublishValue(PercentType.ZERO, null), is("10"));
315315

316+
v.update(OnOffType.OFF);
317+
316318
assertThat(v.parseCommand(OnOffType.ON), is(OnOffType.ON));
317319
assertThat(v.getMQTTpublishValue(OnOffType.ON, null), is("110"));
318320
assertThat(v.parseCommand(OnOffType.OFF), is(OnOffType.OFF));

0 commit comments

Comments
 (0)