Some warnings were still present at startup regarding Room initialization. (#14784)

Switched to late initialization.

Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital 2023-04-14 12:48:03 +02:00 committed by GitHub
parent 9f221e550b
commit a0f06ec051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -45,9 +45,11 @@ public class RoomCapability extends Capability {
super(handler);
}
@Override
public void initialize() {
energyCapability = handler.getHomeCapability(EnergyCapability.class);
protected Optional<EnergyCapability> getEnergyCapability() {
if (energyCapability.isEmpty()) {
energyCapability = handler.getHomeCapability(EnergyCapability.class);
}
return energyCapability;
}
@Override
@ -58,7 +60,7 @@ public class RoomCapability extends Capability {
if (targetMode == SetpointMode.MANUAL) {
logger.info("Switch to 'Manual' mode is done by setting a setpoint temp, command ignored");
} else {
energyCapability.ifPresent(cap -> cap.setRoomThermMode(handler.getId(), targetMode));
getEnergyCapability().ifPresent(cap -> cap.setRoomThermMode(handler.getId(), targetMode));
}
} catch (IllegalArgumentException e) {
logger.info("Command '{}' is not a valid setpoint mode for channel '{}'", command, channelName);
@ -66,7 +68,7 @@ public class RoomCapability extends Capability {
} else if (CHANNEL_VALUE.equals(channelName)) {
QuantityType<?> quantity = commandToQuantity(command, MeasureClass.INSIDE_TEMPERATURE);
if (quantity != null) {
energyCapability.ifPresent(cap -> cap.setRoomThermTemp(handler.getId(), quantity.doubleValue()));
getEnergyCapability().ifPresent(cap -> cap.setRoomThermTemp(handler.getId(), quantity.doubleValue()));
} else {
logger.warn("Incorrect command '{}' on channel '{}'", command, channelName);
}