[nikohomecontrol] Fix dimmer control sequence (#11737)
* Fix dimmer control sequence Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
This commit is contained in:
@@ -395,7 +395,7 @@ public class NikoHomeControlCommunication2 extends NikoHomeControlCommunication
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
actionType = ActionType.GENERIC;
|
actionType = ActionType.GENERIC;
|
||||||
logger.debug("device type {} not recognised, default to GENERIC action", device.type);
|
logger.debug("device model {} not recognised, default to GENERIC action", device.model);
|
||||||
}
|
}
|
||||||
|
|
||||||
NhcAction2 nhcAction = new NhcAction2(device.uuid, device.name, device.model, device.technology,
|
NhcAction2 nhcAction = new NhcAction2(device.uuid, device.name, device.model, device.technology,
|
||||||
@@ -480,32 +480,36 @@ public class NikoHomeControlCommunication2 extends NikoHomeControlCommunication
|
|||||||
booleanState = basicStateProperty.get().basicState;
|
booleanState = basicStateProperty.get().basicState;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (booleanState != null) {
|
if (NHCOFF.equals(booleanState)) {
|
||||||
if (NHCON.equals(booleanState)) {
|
|
||||||
action.setBooleanState(true);
|
|
||||||
logger.debug("setting action {} internally to ON", action.getId());
|
|
||||||
} else if (NHCOFF.equals(booleanState)) {
|
|
||||||
action.setBooleanState(false);
|
action.setBooleanState(false);
|
||||||
logger.debug("setting action {} internally to OFF", action.getId());
|
logger.debug("setting action {} internally to OFF", action.getId());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (dimmerProperty.isPresent()) {
|
if (dimmerProperty.isPresent()) {
|
||||||
String brightness = dimmerProperty.get().brightness;
|
String brightness = dimmerProperty.get().brightness;
|
||||||
if (brightness != null) {
|
if (brightness != null) {
|
||||||
|
try {
|
||||||
action.setState(Integer.parseInt(brightness));
|
action.setState(Integer.parseInt(brightness));
|
||||||
logger.debug("setting action {} internally to {}", action.getId(), dimmerProperty.get().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 (NHCON.equals(booleanState)) {
|
||||||
|
action.setBooleanState(true);
|
||||||
|
logger.debug("setting action {} internally to ON", action.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateRollershutterState(NhcAction2 action, List<NhcProperty> deviceProperties) {
|
private void updateRollershutterState(NhcAction2 action, List<NhcProperty> deviceProperties) {
|
||||||
deviceProperties.stream().map(p -> p.position).filter(Objects::nonNull).findFirst().ifPresent(position -> {
|
deviceProperties.stream().map(p -> p.position).filter(Objects::nonNull).findFirst().ifPresent(position -> {
|
||||||
try {
|
try {
|
||||||
action.setState(Integer.parseInt(position));
|
action.setState(Integer.parseInt(position));
|
||||||
logger.debug("setting action {} internally to {}", action.getId(), position);
|
logger.debug("setting action {} internally to {}", action.getId(), position);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
logger.trace("received empty rollershutter {} position info", action.getId());
|
logger.trace("received empty or invalid rollershutter {} position info {}", action.getId(), position);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -615,6 +619,10 @@ public class NikoHomeControlCommunication2 extends NikoHomeControlCommunication
|
|||||||
switch (action.getType()) {
|
switch (action.getType()) {
|
||||||
case GENERIC:
|
case GENERIC:
|
||||||
case TRIGGER:
|
case TRIGGER:
|
||||||
|
if (!NHCON.equals(value)) {
|
||||||
|
// Only trigger for ON
|
||||||
|
return;
|
||||||
|
}
|
||||||
property.basicState = NHCTRIGGERED;
|
property.basicState = NHCTRIGGERED;
|
||||||
break;
|
break;
|
||||||
case RELAY:
|
case RELAY:
|
||||||
@@ -627,6 +635,17 @@ public class NikoHomeControlCommunication2 extends NikoHomeControlCommunication
|
|||||||
} else if (NHCOFF.equals(value)) {
|
} else if (NHCOFF.equals(value)) {
|
||||||
property.status = value;
|
property.status = value;
|
||||||
} else {
|
} else {
|
||||||
|
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
|
// If the light is off, turn the light on before sending the brightness value, needs to happen
|
||||||
// in 2 separate messages.
|
// in 2 separate messages.
|
||||||
if (!action.booleanState()) {
|
if (!action.booleanState()) {
|
||||||
@@ -643,8 +662,7 @@ public class NikoHomeControlCommunication2 extends NikoHomeControlCommunication
|
|||||||
} else if (NHCDOWN.equals(value)) {
|
} else if (NHCDOWN.equals(value)) {
|
||||||
property.position = "0";
|
property.position = "0";
|
||||||
} else {
|
} else {
|
||||||
int position = Integer.parseInt(value);
|
property.position = value;
|
||||||
property.position = String.valueOf(position);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user