[mqtt.generic] Fix ClassCastException when receiving ON/OFF on a dimmer channel (#17980)

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
jimtng 2024-12-26 01:32:26 +10:00 committed by GitHub
parent 2f2cf22332
commit d049995e56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View File

@ -75,7 +75,7 @@ public class PercentageValue extends Value {
@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;

View File

@ -313,6 +313,8 @@ public class ValueTests {
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));