import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
+import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.types.Command;
import org.slf4j.Logger;
private volatile @Nullable NhcAction nhcAction;
+ private volatile boolean initialized = false;
+
private String actionId = "";
private int stepValue;
private boolean invert;
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
- NikoHomeControlCommunication nhcComm = getCommunication();
+ NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
if (nhcComm == null) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
- "@text/offline.bridge-unitialized");
+ logger.debug("communication not up yet, cannot handle command {} for {}", command, channelUID);
return;
}
@Override
public void initialize() {
+ initialized = false;
+
NikoHomeControlActionConfig config;
if (thing.getThingTypeUID().equals(THING_TYPE_DIMMABLE_LIGHT)) {
config = getConfig().as(NikoHomeControlActionDimmerConfig.class);
}
actionId = config.actionId;
- NikoHomeControlCommunication nhcComm = getCommunication();
+ NikoHomeControlBridgeHandler bridgeHandler = getBridgeHandler();
+ if (bridgeHandler == null) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+ "@text/offline.configuration-error.invalid-bridge-handler");
+ return;
+ }
+
+ updateStatus(ThingStatus.UNKNOWN);
+
+ Bridge bridge = getBridge();
+ if ((bridge != null) && ThingStatus.ONLINE.equals(bridge.getStatus())) {
+ // We need to do this in a separate thread because we may have to wait for the
+ // communication to become active
+ scheduler.submit(this::startCommunication);
+ }
+ }
+
+ private synchronized void startCommunication() {
+ NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
+
if (nhcComm == null) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
- "@text/offline.bridge-unitialized");
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
- scheduler.submit(() -> {
- if (!nhcComm.communicationActive()) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
- "@text/offline.communication-error");
- return;
- }
+ if (!nhcComm.communicationActive()) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+ "@text/offline.communication-error");
+ return;
+ }
- NhcAction nhcAction = nhcComm.getActions().get(actionId);
- if (nhcAction == null) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
- "@text/offline.configuration-error.actionId");
- return;
- }
+ NhcAction nhcAction = nhcComm.getActions().get(actionId);
+ if (nhcAction == null) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+ "@text/offline.configuration-error.actionId");
+ return;
+ }
- nhcAction.setEventHandler(this);
+ nhcAction.setEventHandler(this);
- updateProperties(nhcAction);
+ updateProperties(nhcAction);
- String actionLocation = nhcAction.getLocation();
- if (thing.getLocation() == null) {
- thing.setLocation(actionLocation);
- }
+ String actionLocation = nhcAction.getLocation();
+ if (thing.getLocation() == null) {
+ thing.setLocation(actionLocation);
+ }
- actionEvent(nhcAction.getState());
+ this.nhcAction = nhcAction;
- this.nhcAction = nhcAction;
+ logger.debug("action initialized {}", actionId);
- 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);
+ }
- 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) {
if (nhcBridgeHandler != null) {
nhcBridgeHandler.bridgeOnline();
} else {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
- "@text/offline.bridge-unitialized");
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+ "@text/offline.configuration-error.invalid-bridge-handler");
}
}
- private @Nullable NikoHomeControlCommunication getCommunication() {
- NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler();
+ private @Nullable NikoHomeControlCommunication getCommunication(
+ @Nullable NikoHomeControlBridgeHandler nhcBridgeHandler) {
return nhcBridgeHandler != null ? nhcBridgeHandler.getCommunication() : null;
}
Bridge nhcBridge = getBridge();
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);
+ }
+ }
}
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
+import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.types.Command;
import org.openhab.core.types.UnDefType;
private volatile @Nullable NhcEnergyMeter nhcEnergyMeter;
+ private volatile boolean initialized = false;
+
private String energyMeterId = "";
public NikoHomeControlEnergyMeterHandler(Thing thing) {
@Override
public void initialize() {
+ initialized = false;
+
NikoHomeControlEnergyMeterConfig config = getConfig().as(NikoHomeControlEnergyMeterConfig.class);
energyMeterId = config.energyMeterId;
- NikoHomeControlCommunication nhcComm = getCommunication();
+ NikoHomeControlBridgeHandler bridgeHandler = getBridgeHandler();
+ if (bridgeHandler == null) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+ "@text/offline.configuration-error.invalid-bridge-handler");
+ return;
+ }
+
+ updateStatus(ThingStatus.UNKNOWN);
+
+ Bridge bridge = getBridge();
+ if ((bridge != null) && ThingStatus.ONLINE.equals(bridge.getStatus())) {
+ // We need to do this in a separate thread because we may have to wait for the
+ // communication to become active
+ scheduler.submit(this::startCommunication);
+ }
+ }
+
+ private synchronized void startCommunication() {
+ NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
+
if (nhcComm == null) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
- "@text/offline.bridge-unitialized");
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
- scheduler.submit(() -> {
- if (!nhcComm.communicationActive()) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
- "@text/offline.communication-error");
- return;
- }
+ if (!nhcComm.communicationActive()) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+ "@text/offline.communication-error");
+ return;
+ }
- NhcEnergyMeter nhcEnergyMeter = nhcComm.getEnergyMeters().get(energyMeterId);
- if (nhcEnergyMeter == null) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
- "@text/offline.configuration-error.energyMeterId");
- return;
- }
+ NhcEnergyMeter nhcEnergyMeter = nhcComm.getEnergyMeters().get(energyMeterId);
+ if (nhcEnergyMeter == null) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+ "@text/offline.configuration-error.energyMeterId");
+ return;
+ }
- nhcEnergyMeter.setEventHandler(this);
+ nhcEnergyMeter.setEventHandler(this);
- updateProperties(nhcEnergyMeter);
+ updateProperties(nhcEnergyMeter);
- String location = nhcEnergyMeter.getLocation();
- if (thing.getLocation() == null) {
- thing.setLocation(location);
- }
+ String location = nhcEnergyMeter.getLocation();
+ if (thing.getLocation() == null) {
+ thing.setLocation(location);
+ }
- // 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);
- }
+ this.nhcEnergyMeter = nhcEnergyMeter;
- this.nhcEnergyMeter = nhcEnergyMeter;
+ logger.debug("energy meter intialized {}", energyMeterId);
- 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);
+ }
- 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
public void dispose() {
- NikoHomeControlCommunication nhcComm = getCommunication();
+ NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
if (nhcComm != null) {
nhcComm.stopEnergyMeter(energyMeterId);
// Subscribing to power readings starts an intensive data flow, therefore only do it when there is an item linked to
// the channel
public void channelLinked(ChannelUID channelUID) {
- NikoHomeControlCommunication nhcComm = getCommunication();
+ NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
if (nhcComm != null) {
// This can be expensive, therefore do it in a job.
scheduler.submit(() -> {
@Override
public void channelUnlinked(ChannelUID channelUID) {
- NikoHomeControlCommunication nhcComm = getCommunication();
+ NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
if (nhcComm != null) {
// This can be expensive, therefore do it in a job.
scheduler.submit(() -> {
if (nhcBridgeHandler != null) {
nhcBridgeHandler.bridgeOnline();
} else {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
- "@text/offline.bridge-unitialized");
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+ "@text/offline.configuration-error.invalid-bridge-handler");
}
}
- private @Nullable NikoHomeControlCommunication getCommunication() {
- NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler();
+ private @Nullable NikoHomeControlCommunication getCommunication(
+ @Nullable NikoHomeControlBridgeHandler nhcBridgeHandler) {
return nhcBridgeHandler != null ? nhcBridgeHandler.getCommunication() : null;
}
Bridge nhcBridge = getBridge();
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);
+ }
+ }
}
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
+import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.types.Command;
import org.slf4j.Logger;
private volatile @Nullable NhcThermostat nhcThermostat;
+ private volatile boolean initialized = false;
+
private String thermostatId = "";
private int overruleTime;
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
- NikoHomeControlCommunication nhcComm = getCommunication();
+ NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
if (nhcComm == null) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
- "@text/offline.bridge-unitialized");
+ logger.debug("communication not up yet, cannot handle command {} for {}", command, channelUID);
return;
}
@Override
public void initialize() {
+ initialized = false;
+
NikoHomeControlThermostatConfig config = getConfig().as(NikoHomeControlThermostatConfig.class);
thermostatId = config.thermostatId;
overruleTime = config.overruleTime;
- NikoHomeControlCommunication nhcComm = getCommunication();
+ NikoHomeControlBridgeHandler bridgeHandler = getBridgeHandler();
+ if (bridgeHandler == null) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+ "@text/offline.configuration-error.invalid-bridge-handler");
+ return;
+ }
+
+ updateStatus(ThingStatus.UNKNOWN);
+
+ Bridge bridge = getBridge();
+ if ((bridge != null) && ThingStatus.ONLINE.equals(bridge.getStatus())) {
+ // We need to do this in a separate thread because we may have to wait for the
+ // communication to become active
+ scheduler.submit(this::startCommunication);
+ }
+ }
+
+ private synchronized void startCommunication() {
+ NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler());
+
if (nhcComm == null) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
- "@text/offline.bridge-unitialized");
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
- scheduler.submit(() -> {
- if (!nhcComm.communicationActive()) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
- "@text/offline.communication-error");
- return;
- }
+ if (!nhcComm.communicationActive()) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+ "@text/offline.communication-error");
+ return;
+ }
- NhcThermostat nhcThermostat = nhcComm.getThermostats().get(thermostatId);
- if (nhcThermostat == null) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
- "@text/offline.configuration-error.thermostatId");
- return;
- }
+ NhcThermostat nhcThermostat = nhcComm.getThermostats().get(thermostatId);
+ if (nhcThermostat == null) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+ "@text/offline.configuration-error.thermostatId");
+ return;
+ }
- nhcThermostat.setEventHandler(this);
+ nhcThermostat.setEventHandler(this);
- updateProperties(nhcThermostat);
+ updateProperties(nhcThermostat);
- String thermostatLocation = nhcThermostat.getLocation();
- if (thing.getLocation() == null) {
- thing.setLocation(thermostatLocation);
- }
+ String thermostatLocation = nhcThermostat.getLocation();
+ if (thing.getLocation() == null) {
+ thing.setLocation(thermostatLocation);
+ }
- thermostatEvent(nhcThermostat.getMeasured(), nhcThermostat.getSetpoint(), nhcThermostat.getMode(),
- nhcThermostat.getOverrule(), nhcThermostat.getDemand());
+ this.nhcThermostat = nhcThermostat;
- this.nhcThermostat = nhcThermostat;
+ logger.debug("thermostat intialized {}", thermostatId);
- 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);
+ }
- 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) {
if (nhcBridgeHandler != null) {
nhcBridgeHandler.bridgeOnline();
} else {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED,
- "@text/offline.bridge-unitialized");
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+ "@text/offline.configuration-error.invalid-bridge-handler");
}
}
- private @Nullable NikoHomeControlCommunication getCommunication() {
- NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler();
+ private @Nullable NikoHomeControlCommunication getCommunication(
+ @Nullable NikoHomeControlBridgeHandler nhcBridgeHandler) {
return nhcBridgeHandler != null ? nhcBridgeHandler.getCommunication() : null;
}
Bridge nhcBridge = getBridge();
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);
+ }
+ }
}
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.invalid-bridge-handler = Invalid bridge handler
+
offline.communication-error = Error communicating with controller
-offline.bridge-unitialized = Bridge not initialized
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.bridge-unitialized = Pont de connexion non initialisé
offline.configuration-error.thermostatRemoved = Thermostaat is verwijderd van de controller
offline.communication-error = Fout tijdens het communiceren met de controller
-offline.bridge-unitialized = Bridge niet geïnitialiseerd
+
<bridge-type-ref id="bridge"/>
<bridge-type-ref id="bridge2"/>
</supported-bridge-type-refs>
- <label>@textThermostatLabel</label>
- <description>@textThermostatDescription</description>
+ <label>@text/ThermostatLabel</label>
+ <description>@text/ThermostatDescription</description>
<channels>
<channel id="measured" typeId="measured"/>
<channel id="mode" typeId="mode"/>