[nikohomecontrol] Do not set thing status before end of initialization (#12819)
* Do not set thing status before end of initialization * Change ThingStatusDetail when no communication object * Change bridge config error messages * Bridge status changed handling * Check bridge status in handler init Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
This commit is contained in:
parent
62bb809f76
commit
bdf59524b8
@ -36,6 +36,7 @@ import org.openhab.core.thing.ChannelUID;
|
|||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
import org.openhab.core.thing.ThingStatus;
|
import org.openhab.core.thing.ThingStatus;
|
||||||
import org.openhab.core.thing.ThingStatusDetail;
|
import org.openhab.core.thing.ThingStatusDetail;
|
||||||
|
import org.openhab.core.thing.ThingStatusInfo;
|
||||||
import org.openhab.core.thing.binding.BaseThingHandler;
|
import org.openhab.core.thing.binding.BaseThingHandler;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -54,6 +55,8 @@ public class NikoHomeControlActionHandler extends BaseThingHandler implements Nh
|
|||||||
|
|
||||||
private volatile @Nullable NhcAction nhcAction;
|
private volatile @Nullable NhcAction nhcAction;
|
||||||
|
|
||||||
|
private volatile boolean initialized = false;
|
||||||
|
|
||||||
private String actionId = "";
|
private String actionId = "";
|
||||||
private int stepValue;
|
private int stepValue;
|
||||||
private boolean invert;
|
private boolean invert;
|
||||||
@ -64,10 +67,9 @@ public class NikoHomeControlActionHandler extends BaseThingHandler implements Nh
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
NikoHomeControlCommunication nhcComm = getCommunication();
|
NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
|
||||||
if (nhcComm == null) {
|
if (nhcComm == null) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
|
logger.debug("communication not up yet, cannot handle command {} for {}", command, channelUID);
|
||||||
"@text/offline.bridge-unitialized");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,6 +202,8 @@ public class NikoHomeControlActionHandler extends BaseThingHandler implements Nh
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
initialized = false;
|
||||||
|
|
||||||
NikoHomeControlActionConfig config;
|
NikoHomeControlActionConfig config;
|
||||||
if (thing.getThingTypeUID().equals(THING_TYPE_DIMMABLE_LIGHT)) {
|
if (thing.getThingTypeUID().equals(THING_TYPE_DIMMABLE_LIGHT)) {
|
||||||
config = getConfig().as(NikoHomeControlActionDimmerConfig.class);
|
config = getConfig().as(NikoHomeControlActionDimmerConfig.class);
|
||||||
@ -212,52 +216,66 @@ public class NikoHomeControlActionHandler extends BaseThingHandler implements Nh
|
|||||||
}
|
}
|
||||||
actionId = config.actionId;
|
actionId = config.actionId;
|
||||||
|
|
||||||
NikoHomeControlCommunication nhcComm = getCommunication();
|
NikoHomeControlBridgeHandler bridgeHandler = getBridgeHandler();
|
||||||
if (nhcComm == null) {
|
if (bridgeHandler == null) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/offline.bridge-unitialized");
|
"@text/offline.configuration-error.invalid-bridge-handler");
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
updateStatus(ThingStatus.UNKNOWN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to do this in a separate thread because we may have to wait for the communication to become active
|
updateStatus(ThingStatus.UNKNOWN);
|
||||||
scheduler.submit(() -> {
|
|
||||||
if (!nhcComm.communicationActive()) {
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/offline.communication-error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NhcAction nhcAction = nhcComm.getActions().get(actionId);
|
Bridge bridge = getBridge();
|
||||||
if (nhcAction == null) {
|
if ((bridge != null) && ThingStatus.ONLINE.equals(bridge.getStatus())) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
// We need to do this in a separate thread because we may have to wait for the
|
||||||
"@text/offline.configuration-error.actionId");
|
// communication to become active
|
||||||
return;
|
scheduler.submit(this::startCommunication);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nhcAction.setEventHandler(this);
|
private synchronized void startCommunication() {
|
||||||
|
NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
|
||||||
|
|
||||||
updateProperties(nhcAction);
|
if (nhcComm == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String actionLocation = nhcAction.getLocation();
|
if (!nhcComm.communicationActive()) {
|
||||||
if (thing.getLocation() == null) {
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
||||||
thing.setLocation(actionLocation);
|
"@text/offline.communication-error");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
actionEvent(nhcAction.getState());
|
NhcAction nhcAction = nhcComm.getActions().get(actionId);
|
||||||
|
if (nhcAction == null) {
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
|
"@text/offline.configuration-error.actionId");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.nhcAction = nhcAction;
|
nhcAction.setEventHandler(this);
|
||||||
|
|
||||||
logger.debug("action initialized {}", actionId);
|
updateProperties(nhcAction);
|
||||||
|
|
||||||
Bridge bridge = getBridge();
|
String actionLocation = nhcAction.getLocation();
|
||||||
if ((bridge != null) && (bridge.getStatus() == ThingStatus.ONLINE)) {
|
if (thing.getLocation() == null) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
thing.setLocation(actionLocation);
|
||||||
} else {
|
}
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
|
||||||
}
|
this.nhcAction = nhcAction;
|
||||||
});
|
|
||||||
|
logger.debug("action initialized {}", actionId);
|
||||||
|
|
||||||
|
Bridge bridge = getBridge();
|
||||||
|
if ((bridge != null) && (bridge.getStatus() == ThingStatus.ONLINE)) {
|
||||||
|
updateStatus(ThingStatus.ONLINE);
|
||||||
|
} else {
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
actionEvent(nhcAction.getState());
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateProperties(NhcAction nhcAction) {
|
private void updateProperties(NhcAction nhcAction) {
|
||||||
@ -341,13 +359,13 @@ public class NikoHomeControlActionHandler extends BaseThingHandler implements Nh
|
|||||||
if (nhcBridgeHandler != null) {
|
if (nhcBridgeHandler != null) {
|
||||||
nhcBridgeHandler.bridgeOnline();
|
nhcBridgeHandler.bridgeOnline();
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/offline.bridge-unitialized");
|
"@text/offline.configuration-error.invalid-bridge-handler");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable NikoHomeControlCommunication getCommunication() {
|
private @Nullable NikoHomeControlCommunication getCommunication(
|
||||||
NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler();
|
@Nullable NikoHomeControlBridgeHandler nhcBridgeHandler) {
|
||||||
return nhcBridgeHandler != null ? nhcBridgeHandler.getCommunication() : null;
|
return nhcBridgeHandler != null ? nhcBridgeHandler.getCommunication() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,4 +373,18 @@ public class NikoHomeControlActionHandler extends BaseThingHandler implements Nh
|
|||||||
Bridge nhcBridge = getBridge();
|
Bridge nhcBridge = getBridge();
|
||||||
return nhcBridge != null ? (NikoHomeControlBridgeHandler) nhcBridge.getHandler() : null;
|
return nhcBridge != null ? (NikoHomeControlBridgeHandler) nhcBridge.getHandler() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
|
||||||
|
ThingStatus bridgeStatus = bridgeStatusInfo.getStatus();
|
||||||
|
if (ThingStatus.ONLINE.equals(bridgeStatus)) {
|
||||||
|
if (!initialized) {
|
||||||
|
scheduler.submit(this::startCommunication);
|
||||||
|
} else {
|
||||||
|
updateStatus(ThingStatus.ONLINE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import org.openhab.core.thing.ChannelUID;
|
|||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
import org.openhab.core.thing.ThingStatus;
|
import org.openhab.core.thing.ThingStatus;
|
||||||
import org.openhab.core.thing.ThingStatusDetail;
|
import org.openhab.core.thing.ThingStatusDetail;
|
||||||
|
import org.openhab.core.thing.ThingStatusInfo;
|
||||||
import org.openhab.core.thing.binding.BaseThingHandler;
|
import org.openhab.core.thing.binding.BaseThingHandler;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
import org.openhab.core.types.UnDefType;
|
import org.openhab.core.types.UnDefType;
|
||||||
@ -50,6 +51,8 @@ public class NikoHomeControlEnergyMeterHandler extends BaseThingHandler implemen
|
|||||||
|
|
||||||
private volatile @Nullable NhcEnergyMeter nhcEnergyMeter;
|
private volatile @Nullable NhcEnergyMeter nhcEnergyMeter;
|
||||||
|
|
||||||
|
private volatile boolean initialized = false;
|
||||||
|
|
||||||
private String energyMeterId = "";
|
private String energyMeterId = "";
|
||||||
|
|
||||||
public NikoHomeControlEnergyMeterHandler(Thing thing) {
|
public NikoHomeControlEnergyMeterHandler(Thing thing) {
|
||||||
@ -71,66 +74,81 @@ public class NikoHomeControlEnergyMeterHandler extends BaseThingHandler implemen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
initialized = false;
|
||||||
|
|
||||||
NikoHomeControlEnergyMeterConfig config = getConfig().as(NikoHomeControlEnergyMeterConfig.class);
|
NikoHomeControlEnergyMeterConfig config = getConfig().as(NikoHomeControlEnergyMeterConfig.class);
|
||||||
|
|
||||||
energyMeterId = config.energyMeterId;
|
energyMeterId = config.energyMeterId;
|
||||||
|
|
||||||
NikoHomeControlCommunication nhcComm = getCommunication();
|
NikoHomeControlBridgeHandler bridgeHandler = getBridgeHandler();
|
||||||
if (nhcComm == null) {
|
if (bridgeHandler == null) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/offline.bridge-unitialized");
|
"@text/offline.configuration-error.invalid-bridge-handler");
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
updateStatus(ThingStatus.UNKNOWN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to do this in a separate thread because we may have to wait for the
|
updateStatus(ThingStatus.UNKNOWN);
|
||||||
// communication to become active
|
|
||||||
scheduler.submit(() -> {
|
|
||||||
if (!nhcComm.communicationActive()) {
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/offline.communication-error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NhcEnergyMeter nhcEnergyMeter = nhcComm.getEnergyMeters().get(energyMeterId);
|
Bridge bridge = getBridge();
|
||||||
if (nhcEnergyMeter == null) {
|
if ((bridge != null) && ThingStatus.ONLINE.equals(bridge.getStatus())) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
// We need to do this in a separate thread because we may have to wait for the
|
||||||
"@text/offline.configuration-error.energyMeterId");
|
// communication to become active
|
||||||
return;
|
scheduler.submit(this::startCommunication);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nhcEnergyMeter.setEventHandler(this);
|
private synchronized void startCommunication() {
|
||||||
|
NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
|
||||||
|
|
||||||
updateProperties(nhcEnergyMeter);
|
if (nhcComm == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String location = nhcEnergyMeter.getLocation();
|
if (!nhcComm.communicationActive()) {
|
||||||
if (thing.getLocation() == null) {
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
||||||
thing.setLocation(location);
|
"@text/offline.communication-error");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Subscribing to power readings starts an intensive data flow, therefore only do it when there is an item
|
NhcEnergyMeter nhcEnergyMeter = nhcComm.getEnergyMeters().get(energyMeterId);
|
||||||
// linked to the channel
|
if (nhcEnergyMeter == null) {
|
||||||
if (isLinked(CHANNEL_POWER)) {
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
nhcComm.startEnergyMeter(energyMeterId);
|
"@text/offline.configuration-error.energyMeterId");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.nhcEnergyMeter = nhcEnergyMeter;
|
nhcEnergyMeter.setEventHandler(this);
|
||||||
|
|
||||||
logger.debug("energy meter intialized {}", energyMeterId);
|
updateProperties(nhcEnergyMeter);
|
||||||
|
|
||||||
Bridge bridge = getBridge();
|
String location = nhcEnergyMeter.getLocation();
|
||||||
if ((bridge != null) && (bridge.getStatus() == ThingStatus.ONLINE)) {
|
if (thing.getLocation() == null) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
thing.setLocation(location);
|
||||||
} else {
|
}
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
|
||||||
}
|
this.nhcEnergyMeter = nhcEnergyMeter;
|
||||||
});
|
|
||||||
|
logger.debug("energy meter intialized {}", energyMeterId);
|
||||||
|
|
||||||
|
Bridge bridge = getBridge();
|
||||||
|
if ((bridge != null) && (bridge.getStatus() == ThingStatus.ONLINE)) {
|
||||||
|
updateStatus(ThingStatus.ONLINE);
|
||||||
|
} else {
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subscribing to power readings starts an intensive data flow, therefore only do it when there is an item
|
||||||
|
// linked to the channel
|
||||||
|
if (isLinked(CHANNEL_POWER)) {
|
||||||
|
nhcComm.startEnergyMeter(energyMeterId);
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
NikoHomeControlCommunication nhcComm = getCommunication();
|
NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
|
||||||
|
|
||||||
if (nhcComm != null) {
|
if (nhcComm != null) {
|
||||||
nhcComm.stopEnergyMeter(energyMeterId);
|
nhcComm.stopEnergyMeter(energyMeterId);
|
||||||
@ -178,7 +196,7 @@ public class NikoHomeControlEnergyMeterHandler extends BaseThingHandler implemen
|
|||||||
// Subscribing to power readings starts an intensive data flow, therefore only do it when there is an item linked to
|
// Subscribing to power readings starts an intensive data flow, therefore only do it when there is an item linked to
|
||||||
// the channel
|
// the channel
|
||||||
public void channelLinked(ChannelUID channelUID) {
|
public void channelLinked(ChannelUID channelUID) {
|
||||||
NikoHomeControlCommunication nhcComm = getCommunication();
|
NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
|
||||||
if (nhcComm != null) {
|
if (nhcComm != null) {
|
||||||
// This can be expensive, therefore do it in a job.
|
// This can be expensive, therefore do it in a job.
|
||||||
scheduler.submit(() -> {
|
scheduler.submit(() -> {
|
||||||
@ -196,7 +214,7 @@ public class NikoHomeControlEnergyMeterHandler extends BaseThingHandler implemen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelUnlinked(ChannelUID channelUID) {
|
public void channelUnlinked(ChannelUID channelUID) {
|
||||||
NikoHomeControlCommunication nhcComm = getCommunication();
|
NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
|
||||||
if (nhcComm != null) {
|
if (nhcComm != null) {
|
||||||
// This can be expensive, therefore do it in a job.
|
// This can be expensive, therefore do it in a job.
|
||||||
scheduler.submit(() -> {
|
scheduler.submit(() -> {
|
||||||
@ -230,13 +248,13 @@ public class NikoHomeControlEnergyMeterHandler extends BaseThingHandler implemen
|
|||||||
if (nhcBridgeHandler != null) {
|
if (nhcBridgeHandler != null) {
|
||||||
nhcBridgeHandler.bridgeOnline();
|
nhcBridgeHandler.bridgeOnline();
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/offline.bridge-unitialized");
|
"@text/offline.configuration-error.invalid-bridge-handler");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable NikoHomeControlCommunication getCommunication() {
|
private @Nullable NikoHomeControlCommunication getCommunication(
|
||||||
NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler();
|
@Nullable NikoHomeControlBridgeHandler nhcBridgeHandler) {
|
||||||
return nhcBridgeHandler != null ? nhcBridgeHandler.getCommunication() : null;
|
return nhcBridgeHandler != null ? nhcBridgeHandler.getCommunication() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,4 +262,18 @@ public class NikoHomeControlEnergyMeterHandler extends BaseThingHandler implemen
|
|||||||
Bridge nhcBridge = getBridge();
|
Bridge nhcBridge = getBridge();
|
||||||
return nhcBridge != null ? (NikoHomeControlBridgeHandler) nhcBridge.getHandler() : null;
|
return nhcBridge != null ? (NikoHomeControlBridgeHandler) nhcBridge.getHandler() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
|
||||||
|
ThingStatus bridgeStatus = bridgeStatusInfo.getStatus();
|
||||||
|
if (ThingStatus.ONLINE.equals(bridgeStatus)) {
|
||||||
|
if (!initialized) {
|
||||||
|
scheduler.submit(this::startCommunication);
|
||||||
|
} else {
|
||||||
|
updateStatus(ThingStatus.ONLINE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import org.openhab.core.thing.ChannelUID;
|
|||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
import org.openhab.core.thing.ThingStatus;
|
import org.openhab.core.thing.ThingStatus;
|
||||||
import org.openhab.core.thing.ThingStatusDetail;
|
import org.openhab.core.thing.ThingStatusDetail;
|
||||||
|
import org.openhab.core.thing.ThingStatusInfo;
|
||||||
import org.openhab.core.thing.binding.BaseThingHandler;
|
import org.openhab.core.thing.binding.BaseThingHandler;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -54,6 +55,8 @@ public class NikoHomeControlThermostatHandler extends BaseThingHandler implement
|
|||||||
|
|
||||||
private volatile @Nullable NhcThermostat nhcThermostat;
|
private volatile @Nullable NhcThermostat nhcThermostat;
|
||||||
|
|
||||||
|
private volatile boolean initialized = false;
|
||||||
|
|
||||||
private String thermostatId = "";
|
private String thermostatId = "";
|
||||||
private int overruleTime;
|
private int overruleTime;
|
||||||
|
|
||||||
@ -66,10 +69,9 @@ public class NikoHomeControlThermostatHandler extends BaseThingHandler implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
NikoHomeControlCommunication nhcComm = getCommunication();
|
NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
|
||||||
if (nhcComm == null) {
|
if (nhcComm == null) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
|
logger.debug("communication not up yet, cannot handle command {} for {}", command, channelUID);
|
||||||
"@text/offline.bridge-unitialized");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,59 +151,74 @@ public class NikoHomeControlThermostatHandler extends BaseThingHandler implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
initialized = false;
|
||||||
|
|
||||||
NikoHomeControlThermostatConfig config = getConfig().as(NikoHomeControlThermostatConfig.class);
|
NikoHomeControlThermostatConfig config = getConfig().as(NikoHomeControlThermostatConfig.class);
|
||||||
|
|
||||||
thermostatId = config.thermostatId;
|
thermostatId = config.thermostatId;
|
||||||
overruleTime = config.overruleTime;
|
overruleTime = config.overruleTime;
|
||||||
|
|
||||||
NikoHomeControlCommunication nhcComm = getCommunication();
|
NikoHomeControlBridgeHandler bridgeHandler = getBridgeHandler();
|
||||||
if (nhcComm == null) {
|
if (bridgeHandler == null) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/offline.bridge-unitialized");
|
"@text/offline.configuration-error.invalid-bridge-handler");
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
updateStatus(ThingStatus.UNKNOWN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to do this in a separate thread because we may have to wait for the
|
updateStatus(ThingStatus.UNKNOWN);
|
||||||
// communication to become active
|
|
||||||
scheduler.submit(() -> {
|
|
||||||
if (!nhcComm.communicationActive()) {
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/offline.communication-error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NhcThermostat nhcThermostat = nhcComm.getThermostats().get(thermostatId);
|
Bridge bridge = getBridge();
|
||||||
if (nhcThermostat == null) {
|
if ((bridge != null) && ThingStatus.ONLINE.equals(bridge.getStatus())) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
// We need to do this in a separate thread because we may have to wait for the
|
||||||
"@text/offline.configuration-error.thermostatId");
|
// communication to become active
|
||||||
return;
|
scheduler.submit(this::startCommunication);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nhcThermostat.setEventHandler(this);
|
private synchronized void startCommunication() {
|
||||||
|
NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
|
||||||
|
|
||||||
updateProperties(nhcThermostat);
|
if (nhcComm == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String thermostatLocation = nhcThermostat.getLocation();
|
if (!nhcComm.communicationActive()) {
|
||||||
if (thing.getLocation() == null) {
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
||||||
thing.setLocation(thermostatLocation);
|
"@text/offline.communication-error");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
thermostatEvent(nhcThermostat.getMeasured(), nhcThermostat.getSetpoint(), nhcThermostat.getMode(),
|
NhcThermostat nhcThermostat = nhcComm.getThermostats().get(thermostatId);
|
||||||
nhcThermostat.getOverrule(), nhcThermostat.getDemand());
|
if (nhcThermostat == null) {
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
|
"@text/offline.configuration-error.thermostatId");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.nhcThermostat = nhcThermostat;
|
nhcThermostat.setEventHandler(this);
|
||||||
|
|
||||||
logger.debug("thermostat intialized {}", thermostatId);
|
updateProperties(nhcThermostat);
|
||||||
|
|
||||||
Bridge bridge = getBridge();
|
String thermostatLocation = nhcThermostat.getLocation();
|
||||||
if ((bridge != null) && (bridge.getStatus() == ThingStatus.ONLINE)) {
|
if (thing.getLocation() == null) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
thing.setLocation(thermostatLocation);
|
||||||
} else {
|
}
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
|
||||||
}
|
this.nhcThermostat = nhcThermostat;
|
||||||
});
|
|
||||||
|
logger.debug("thermostat intialized {}", thermostatId);
|
||||||
|
|
||||||
|
Bridge bridge = getBridge();
|
||||||
|
if ((bridge != null) && (bridge.getStatus() == ThingStatus.ONLINE)) {
|
||||||
|
updateStatus(ThingStatus.ONLINE);
|
||||||
|
} else {
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
thermostatEvent(nhcThermostat.getMeasured(), nhcThermostat.getSetpoint(), nhcThermostat.getMode(),
|
||||||
|
nhcThermostat.getOverrule(), nhcThermostat.getDemand());
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateProperties(NhcThermostat nhcThermostat) {
|
private void updateProperties(NhcThermostat nhcThermostat) {
|
||||||
@ -306,13 +323,13 @@ public class NikoHomeControlThermostatHandler extends BaseThingHandler implement
|
|||||||
if (nhcBridgeHandler != null) {
|
if (nhcBridgeHandler != null) {
|
||||||
nhcBridgeHandler.bridgeOnline();
|
nhcBridgeHandler.bridgeOnline();
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/offline.bridge-unitialized");
|
"@text/offline.configuration-error.invalid-bridge-handler");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable NikoHomeControlCommunication getCommunication() {
|
private @Nullable NikoHomeControlCommunication getCommunication(
|
||||||
NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler();
|
@Nullable NikoHomeControlBridgeHandler nhcBridgeHandler) {
|
||||||
return nhcBridgeHandler != null ? nhcBridgeHandler.getCommunication() : null;
|
return nhcBridgeHandler != null ? nhcBridgeHandler.getCommunication() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,4 +337,18 @@ public class NikoHomeControlThermostatHandler extends BaseThingHandler implement
|
|||||||
Bridge nhcBridge = getBridge();
|
Bridge nhcBridge = getBridge();
|
||||||
return nhcBridge != null ? (NikoHomeControlBridgeHandler) nhcBridge.getHandler() : null;
|
return nhcBridge != null ? (NikoHomeControlBridgeHandler) nhcBridge.getHandler() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
|
||||||
|
ThingStatus bridgeStatus = bridgeStatusInfo.getStatus();
|
||||||
|
if (ThingStatus.ONLINE.equals(bridgeStatus)) {
|
||||||
|
if (!initialized) {
|
||||||
|
scheduler.submit(this::startCommunication);
|
||||||
|
} else {
|
||||||
|
updateStatus(ThingStatus.ONLINE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -116,5 +116,6 @@ offline.configuration-error.energyMeterRemoved = Energy meter has been removed f
|
|||||||
offline.configuration-error.thermostatId = Configured thermostat ID does not match an thermostat in controller
|
offline.configuration-error.thermostatId = Configured thermostat ID does not match an thermostat in controller
|
||||||
offline.configuration-error.thermostatRemoved = Thermostat has been removed from controller
|
offline.configuration-error.thermostatRemoved = Thermostat has been removed from controller
|
||||||
|
|
||||||
|
offline.configuration-error.invalid-bridge-handler = Invalid bridge handler
|
||||||
|
|
||||||
offline.communication-error = Error communicating with controller
|
offline.communication-error = Error communicating with controller
|
||||||
offline.bridge-unitialized = Bridge not initialized
|
|
||||||
|
|||||||
@ -116,4 +116,3 @@ offline.configuration-error.thermostatId = L'ID configuré ne correspond pas à
|
|||||||
offline.configuration-error.thermostatRemoved = Le thermostat a été retiré de l'unité de contrôle
|
offline.configuration-error.thermostatRemoved = Le thermostat a été retiré de l'unité de contrôle
|
||||||
|
|
||||||
offline.communication-error = Erreur de communication avec l'unité de contrôle
|
offline.communication-error = Erreur de communication avec l'unité de contrôle
|
||||||
offline.bridge-unitialized = Pont de connexion non initialisé
|
|
||||||
|
|||||||
@ -116,4 +116,4 @@ offline.configuration-error.thermostatId = Geconfigureerde thermostaat-ID komt n
|
|||||||
offline.configuration-error.thermostatRemoved = Thermostaat is verwijderd van de controller
|
offline.configuration-error.thermostatRemoved = Thermostaat is verwijderd van de controller
|
||||||
|
|
||||||
offline.communication-error = Fout tijdens het communiceren met de controller
|
offline.communication-error = Fout tijdens het communiceren met de controller
|
||||||
offline.bridge-unitialized = Bridge niet geïnitialiseerd
|
|
||||||
|
|||||||
@ -161,8 +161,8 @@
|
|||||||
<bridge-type-ref id="bridge"/>
|
<bridge-type-ref id="bridge"/>
|
||||||
<bridge-type-ref id="bridge2"/>
|
<bridge-type-ref id="bridge2"/>
|
||||||
</supported-bridge-type-refs>
|
</supported-bridge-type-refs>
|
||||||
<label>@textThermostatLabel</label>
|
<label>@text/ThermostatLabel</label>
|
||||||
<description>@textThermostatDescription</description>
|
<description>@text/ThermostatDescription</description>
|
||||||
<channels>
|
<channels>
|
||||||
<channel id="measured" typeId="measured"/>
|
<channel id="measured" typeId="measured"/>
|
||||||
<channel id="mode" typeId="mode"/>
|
<channel id="mode" typeId="mode"/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user