diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleHandler.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleHandler.java index 13633b0c3..25a53beea 100644 --- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleHandler.java +++ b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleHandler.java @@ -335,7 +335,12 @@ public class LcnModuleHandler extends BaseThingHandler { State convertedState = state; if (converter != null) { - convertedState = converter.onStateUpdateFromHandler(state); + try { + convertedState = converter.onStateUpdateFromHandler(state); + } catch (LcnException e) { + logger.warn("{}: {}{}: Value conversion failed: {}", moduleAddress, channelGroup, channelId, + e.getMessage()); + } } updateState(channelUid, convertedState); diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/common/VariableValue.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/common/VariableValue.java index f61af1d23..e679fdc7d 100644 --- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/common/VariableValue.java +++ b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/common/VariableValue.java @@ -30,8 +30,6 @@ import org.openhab.core.types.State; */ @NonNullByDefault public class VariableValue { - private static final String SENSOR_DEFECTIVE_STATE = "DEFECTIVE"; - /** The absolute, native LCN value. */ private final long nativeValue; @@ -88,9 +86,9 @@ public class VariableValue { public State getState(Variable variable) { State stateValue; if (variable.useLcnSpecialValues() && isSensorDefective()) { - stateValue = new StringType(SENSOR_DEFECTIVE_STATE); + stateValue = new StringType("Sensor defective: " + variable); } else if (variable.useLcnSpecialValues() && !isConfigured()) { - stateValue = new StringType("Not configured in LCN-PRO"); + stateValue = new StringType("Not configured in LCN-PRO: " + variable); } else { stateValue = new DecimalType(toNative(variable.useLcnSpecialValues())); } diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/converter/Converter.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/converter/Converter.java index 6e42d974a..7b4c034fd 100644 --- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/converter/Converter.java +++ b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/converter/Converter.java @@ -30,8 +30,9 @@ public class Converter { * * @param state from the Thing * @return human readable representational State + * @throws LcnException */ - public State onStateUpdateFromHandler(State state) { + public State onStateUpdateFromHandler(State state) throws LcnException { return state; } diff --git a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/converter/ValueConverter.java b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/converter/ValueConverter.java index fc1809bbc..20c4f2f1c 100644 --- a/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/converter/ValueConverter.java +++ b/bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/converter/ValueConverter.java @@ -22,8 +22,6 @@ import org.openhab.binding.lcn.internal.common.LcnException; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.types.State; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Base class for all LCN variable value converters. @@ -32,7 +30,6 @@ import org.slf4j.LoggerFactory; */ @NonNullByDefault public class ValueConverter extends Converter { - private final Logger logger = LoggerFactory.getLogger(ValueConverter.class); private @Nullable final Unit unit; private final Function toHuman; private final Function toNative; @@ -102,20 +99,20 @@ public class ValueConverter extends Converter { * * @param state from the Thing * @return human readable State + * @throws LcnException */ @Override - public State onStateUpdateFromHandler(State state) { - State result = state; - + public State onStateUpdateFromHandler(State state) throws LcnException { if (state instanceof DecimalType) { Unit localUnit = unit; if (localUnit != null) { - result = QuantityType.valueOf(toHumanReadable(((DecimalType) state).longValue()), localUnit); + return QuantityType.valueOf(toHumanReadable(((DecimalType) state).longValue()), localUnit); } - } else { - logger.warn("Unexpected state type: {}", state.getClass().getSimpleName()); - } - return result; + return state; + } else { + throw new LcnException("Unexpected state type: Was " + state.getClass().getSimpleName() + + " but expected DecimalType: " + state); + } } } diff --git a/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRvarSetpointSubHandlerTest.java b/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRvarSetpointSubHandlerTest.java index 1c41b6578..eedb77560 100644 --- a/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRvarSetpointSubHandlerTest.java +++ b/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleRvarSetpointSubHandlerTest.java @@ -121,7 +121,8 @@ public class LcnModuleRvarSetpointSubHandlerTest extends AbstractTestLcnModuleSu @Test public void testRvar1SensorDefective() { tryParseAllHandlers("=M000005.S132512"); - verify(handler).updateChannel(LcnChannelGroup.RVARSETPOINT, "1", new StringType("DEFECTIVE")); + verify(handler).updateChannel(LcnChannelGroup.RVARSETPOINT, "1", + new StringType("Sensor defective: RVARSETPOINT1")); verify(handler).updateChannel(LcnChannelGroup.RVARLOCK, "1", OnOffType.OFF); verify(handler, times(2)).updateChannel(any(), any(), any()); } diff --git a/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleVariableSubHandlerTest.java b/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleVariableSubHandlerTest.java index 59062efe7..0bc9bdf5a 100644 --- a/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleVariableSubHandlerTest.java +++ b/bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/LcnModuleVariableSubHandlerTest.java @@ -82,14 +82,15 @@ public class LcnModuleVariableSubHandlerTest extends AbstractTestLcnModuleSubHan @Test public void testStatusVariable10SensorDefective() { tryParseAllHandlers("=M000005.A01032512"); - verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "10", new StringType("DEFECTIVE")); + verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "10", new StringType("Sensor defective: VARIABLE10")); verify(handler).updateChannel(any(), any(), any()); } @Test public void testStatusVariable8NotConfigured() { tryParseAllHandlers("=M000005.A00865535"); - verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "8", new StringType("Not configured in LCN-PRO")); + verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "8", + new StringType("Not configured in LCN-PRO: VARIABLE8")); verify(handler).updateChannel(any(), any(), any()); } }