Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
  • Loading branch information
mherwege committed Dec 9, 2021
1 parent 184a82d commit 969325c
Showing 1 changed file with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,20 +480,24 @@ private void updateLightState(NhcAction2 action, List<NhcProperty> 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());
}

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());
}
Expand All @@ -505,7 +509,7 @@ private void updateRollershutterState(NhcAction2 action, List<NhcProperty> 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);
}
});
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 969325c

Please sign in to comment.