diff --git a/src/main/java/org/openhab/binding/openlicht/handler/EraserHandler.java b/src/main/java/org/openhab/binding/openlicht/handler/EraserHandler.java index 04899e4b1f3c01dea3692e997b4391c8261c68e9..9aba70617e21e09a15f3ce713835a1383a4d2f3c 100644 --- a/src/main/java/org/openhab/binding/openlicht/handler/EraserHandler.java +++ b/src/main/java/org/openhab/binding/openlicht/handler/EraserHandler.java @@ -159,8 +159,10 @@ public class EraserHandler extends AbstractMqttHandler implements StateChangeLis } // assume this is a GenericItem GenericItem genericItem = (GenericItem) item; - State newState = setState(genericItem, new String(payload)); + State newState = parseState(genericItem, new String(payload)); if (newState != null) { + logger.debug("Setting state {} of type {} for {}", newState, newState.getClass().getSimpleName(), + genericItem.getName()); genericItem.setState(newState); } else { logger.warn("Could not set state for {} using '{}'", genericItem, new String(payload)); @@ -170,18 +172,18 @@ public class EraserHandler extends AbstractMqttHandler implements StateChangeLis } } - private State setState(GenericItem genericItem, String state) { - for (Class<? extends @NonNull State> type : genericItem.getAcceptedDataTypes()) { + private State parseState(GenericItem genericItem, String state) { + for (Class<? extends @NonNull Command> type : genericItem.getAcceptedCommandTypes()) { if (type.equals(StringType.class)) { return new StringType(state); + } else if (type.equals(HSBType.class)) { + return new HSBType(state); } else if (type.equals(DecimalType.class)) { return new DecimalType(state); } else if (type.equals(OnOffType.class)) { return OnOffType.from(state); } else if (type.equals(DateTimeType.class)) { return new DateTimeType(state); - } else if (type.equals(HSBType.class)) { - return new HSBType(state); } } return null; @@ -191,26 +193,6 @@ public class EraserHandler extends AbstractMqttHandler implements StateChangeLis public void handleCommand(ChannelUID channelUID, Command command) { logger.debug("got a command " + command); } - // - // @Override - // public Set<@NonNull String> getSubscribedEventTypes() { - // return Collections.singleton(ItemStateEvent.TYPE); - // } - // - // @Override - // public @Nullable EventFilter getEventFilter() { - // return null; - // } - // - // @Override - // public void receive(Event event) { - // // publish MQTT message - // logger.debug("Received an event: " + event); - // ItemStateEvent itemStateEvent = (ItemStateEvent) event; - // String topic = outTopic + itemStateEvent.getItemName(); - // String payload = itemStateEvent.getPayload(); - // publish(topic, payload); - // } public void added(Item element) { GenericItem genericItem = (GenericItem) element;