mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[lcn] Improve logging (#13460)
Signed-off-by: Fabian Wolter <github@fabian-wolter.de>
This commit is contained in:
parent
c244391d08
commit
08375cd3a8
@ -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);
|
||||
|
@ -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()));
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<Long, Double> toHuman;
|
||||
private final Function<Double, Long> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user