From 969325c16201a8781c0fbe1f0cc8e386b1204c26 Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Thu, 9 Dec 2021 16:49:39 +0100 Subject: [PATCH] Address review comments Signed-off-by: Mark Herwege --- .../nhc2/NikoHomeControlCommunication2.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java index dedce3510ec1..61d407f29ba0 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java @@ -480,7 +480,7 @@ private void updateLightState(NhcAction2 action, List devicePropert booleanState = basicStateProperty.get().basicState; } - if ((booleanState != null) && NHCOFF.equals(booleanState)) { + if (NHCOFF.equals(booleanState)) { action.setBooleanState(false); logger.debug("setting action {} internally to OFF", action.getId()); } @@ -488,12 +488,16 @@ private void updateLightState(NhcAction2 action, List devicePropert if (dimmerProperty.isPresent()) { String brightness = dimmerProperty.get().brightness; if (brightness != null) { - action.setState(Integer.parseInt(brightness)); - logger.debug("setting action {} internally to {}", action.getId(), dimmerProperty.get().brightness); + try { + action.setState(Integer.parseInt(brightness)); + logger.debug("setting action {} internally to {}", action.getId(), dimmerProperty.get().brightness); + } catch (NumberFormatException e) { + logger.debug("received invalid brightness value {} for dimmer {}", brightness, action.getId()); + } } } - if ((booleanState != null) && NHCON.equals(booleanState)) { + if (NHCON.equals(booleanState)) { action.setBooleanState(true); logger.debug("setting action {} internally to ON", action.getId()); } @@ -505,7 +509,7 @@ private void updateRollershutterState(NhcAction2 action, List devic action.setState(Integer.parseInt(position)); logger.debug("setting action {} internally to {}", action.getId(), position); } catch (NumberFormatException e) { - logger.trace("received empty rollershutter {} position info", action.getId()); + logger.trace("received empty or invalid rollershutter {} position info {}", action.getId(), position); } }); } @@ -631,9 +635,17 @@ public void executeAction(String actionId, String value) { } else if (NHCOFF.equals(value)) { property.status = value; } else { - action.setState(Integer.parseInt(value)); // set cached state to new brightness value to avoid - // switching on with old brightness value before updating - // to new value + try { + action.setState(Integer.parseInt(value)); // set cached state to new brightness value to avoid + // switching on with old brightness value before + // updating + // to new value + } catch (NumberFormatException e) { + logger.debug("internal error, trying to set invalid brightness value {} for dimmer {}", value, + action.getId()); + return; + } + // If the light is off, turn the light on before sending the brightness value, needs to happen // in 2 separate messages. if (!action.booleanState()) { @@ -650,8 +662,7 @@ public void executeAction(String actionId, String value) { } else if (NHCDOWN.equals(value)) { property.position = "0"; } else { - int position = Integer.parseInt(value); - property.position = String.valueOf(position); + property.position = value; } break; }