handler.updateState(SIGNAL_STRENGTH, UnDefType.UNDEF);
handler.updateState(BATTERY_LEVEL, UnDefType.UNDEF);
handler.updateState(LOW_BATTERY, UnDefType.UNDEF);
- handler.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
- "Device " + deviceId + " is not syncing with K1 hub");
+ String msg = String.format("@text/offline.device-not-syncing [ \"%d\" ]", deviceId);
+ handler.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, msg);
break;
case FAULT:
handler.updateState(SIGNAL_STRENGTH, UnDefType.UNDEF);
handler.updateState(BATTERY_LEVEL, UnDefType.UNDEF);
handler.updateState(LOW_BATTERY, UnDefType.UNDEF);
- handler.updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, "Device " + deviceId + " has a fault");
+ msg = String.format("@text/offline.device-fault [ \"%d\" ]", deviceId);
+ handler.updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, msg);
break;
default:
handler.updateState(SIGNAL_STRENGTH, new DecimalType(signalStrength));
handler.updateState(SIGNAL_STRENGTH, UnDefType.UNDEF);
handler.updateState(BATTERY_LEVEL, UnDefType.UNDEF);
handler.updateState(LOW_BATTERY, UnDefType.UNDEF);
- handler.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
- "Device " + deviceId + " is not syncing with K1 hub");
+ String msg = String.format("@text/offline.device-not-syncing [ \"%d\" ]", deviceId);
+ handler.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, msg);
break;
case FAULT:
handler.updateState(ENTRY, UnDefType.UNDEF);
handler.updateState(SIGNAL_STRENGTH, UnDefType.UNDEF);
handler.updateState(BATTERY_LEVEL, UnDefType.UNDEF);
handler.updateState(LOW_BATTERY, UnDefType.UNDEF);
- handler.updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, "Device " + deviceId + " has a fault");
+ msg = String.format("@text/offline.device-fault [ \"%d\" ]", deviceId);
+ handler.updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, msg);
break;
default:
handler.updateState(ENTRY,
handler.updateState(SIGNAL_STRENGTH, UnDefType.UNDEF);
handler.updateState(BATTERY_LEVEL, UnDefType.UNDEF);
handler.updateState(LOW_BATTERY, UnDefType.UNDEF);
- handler.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
- "Device " + deviceId + " is not syncing with K1 hub");
+ String msg = String.format("@text/offline.device-not-syncing [ \"%d\" ]", deviceId);
+ handler.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, msg);
break;
case FAULT:
handler.updateState(SIGNAL_STRENGTH, UnDefType.UNDEF);
handler.updateState(BATTERY_LEVEL, UnDefType.UNDEF);
handler.updateState(LOW_BATTERY, UnDefType.UNDEF);
- handler.updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, "Device " + deviceId + " has a fault");
+ msg = String.format("@text/offline.device-fault [ \"%d\" ]", deviceId);
+ handler.updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, msg);
break;
default:
handler.updateState(SIGNAL_STRENGTH, new DecimalType(signalStrength));
handler.updateState(SIGNAL_STRENGTH, UnDefType.UNDEF);
handler.updateState(BATTERY_LEVEL, UnDefType.UNDEF);
handler.updateState(LOW_BATTERY, UnDefType.UNDEF);
- handler.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
- "Device " + deviceId + " is not syncing with K1 hub");
+ String msg = String.format("@text/offline.device-not-syncing [ \"%d\" ]", deviceId);
+ handler.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, msg);
break;
case FAULT:
handler.updateState(MOTION, UnDefType.UNDEF);
handler.updateState(SIGNAL_STRENGTH, UnDefType.UNDEF);
handler.updateState(BATTERY_LEVEL, UnDefType.UNDEF);
handler.updateState(LOW_BATTERY, UnDefType.UNDEF);
- handler.updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, "Device " + deviceId + " has a fault");
+ msg = String.format("@text/offline.device-fault [ \"%d\" ]", deviceId);
+ handler.updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, msg);
break;
default:
handler.updateState(MOTION,
String deviceStatus = this.deviceStatus;
if (deviceStatus.length() < 6) {
logger.debug("Could not decode device status: {}", deviceStatus);
+ String msg = String.format("@text/offline.device-fault [ \"%d\" ]", deviceId);
+ handler.updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, msg);
return;
}
: (STAT_OFF.equals(status) ? OnOffType.OFF : UnDefType.UNDEF);
handler.updateState(POWER_STATE, state);
if (UnDefType.UNDEF.equals(state)) {
- handler.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
- "Device " + deviceId + " is not syncing with K1 hub");
+ String msg = String.format("@text/offline.device-not-syncing [ \"%d\" ]", deviceId);
+ handler.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, msg);
} else {
handler.updateStatus(ThingStatus.ONLINE);
}
handler.updateState(LOW_BATTERY, UnDefType.UNDEF);
handler.updateState(TEMPERATURE, UnDefType.UNDEF);
handler.updateState(HUMIDITY, UnDefType.UNDEF);
- handler.updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, "Device " + deviceId + " has a fault");
+ String msg = String.format("@text/offline.device-fault [ \"%d\" ]", deviceId);
+ handler.updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, msg);
break;
default:
handler.updateState(SIGNAL_STRENGTH, new DecimalType(signalStrength));
login.put("password", password);
loginJson = gson.toJson(login);
+ updateStatus(ThingStatus.UNKNOWN);
+
// If background discovery is enabled, start polling (will do login first), else only login to take the thing
// online if successful
if (enableBackgroundDiscovery) {
legacyFirmware = config.legacyFirmware;
if (connectorId.isEmpty()) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "@text/offline.no-device-id");
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "@text/offline.no-connector-id");
return;
} else if (!CONNECTOR_ID_PATTERN.matcher(connectorId).matches()) {
- String msg = String.format("@text/offline.invalid-device-id [ \"%s\" ]", connectorId);
+ String msg = String.format("@text/offline.invalid-connector-id [ \"%s\" ]", connectorId);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, msg);
return;
}
queryString = QUERY_BASE_STRING + connectorId;
+ updateStatus(ThingStatus.UNKNOWN);
+
scheduler.submit(this::startCommunication);
}
*/
package org.openhab.binding.elroconnects.internal.handler;
+import static org.openhab.binding.elroconnects.internal.ElroConnectsBindingConstants.*;
+
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.elroconnects.internal.ElroConnectsBindingConstants.ElroDeviceType;
import org.openhab.binding.elroconnects.internal.devices.ElroConnectsDevice;
import org.openhab.binding.elroconnects.internal.util.ElroConnectsUtil;
import org.openhab.core.thing.Bridge;
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.RefreshType;
deviceId = config.deviceId;
ElroConnectsBridgeHandler bridgeHandler = getBridgeHandler();
+ if (bridgeHandler == null) {
+ // Thing status has already been updated in getBridgeHandler()
+ return;
+ }
- if (bridgeHandler != null) {
- bridgeHandler.setDeviceHandler(deviceId, this);
- updateProperties(bridgeHandler);
- updateDeviceName(bridgeHandler);
- refreshChannels(bridgeHandler);
+ if (bridgeHandler.getThing().getStatus() == ThingStatus.ONLINE) {
+ ElroConnectsDevice device = bridgeHandler.getDevice(deviceId);
+ if (device != null) {
+ ElroDeviceType deviceType = TYPE_MAP.get(device.getDeviceType());
+ if ((deviceType == null) || !thing.getThingTypeUID().equals(THING_TYPE_MAP.get(deviceType))) {
+ String msg = String.format("@text/offline.invalid-device-type [ \"%s\" ]", deviceType);
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, msg);
+ } else {
+ bridgeHandler.setDeviceHandler(deviceId, this);
+ updateProperties(bridgeHandler);
+ updateDeviceName(bridgeHandler);
+ refreshChannels(bridgeHandler);
+ }
+ } else {
+ String msg = String.format("@text/offline.invalid-device-id [ \"%d\" ]", deviceId);
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, msg);
+ }
+ } else {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
}
}
return bridgeHandler;
}
+ @Override
+ public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
+ if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE) {
+ initialize();
+ } else {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
+ }
+ }
+
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
ElroConnectsBridgeHandler bridgeHandler = getBridgeHandler();
offline.request-timeout = Request timeout
offline.request-failed = Request failed
-offline.no-device-id = Device ID not set
-offline.invalid-device-id = Device ID {0} not of format ST_xxxxxxxxxxxx with xxxxxxxxxxxx the lowercase MAC address of the connector
+offline.no-connector-id = Connector ID not set
+offline.invalid-connector-id = Connector ID {0} not of format ST_xxxxxxxxxxxx with xxxxxxxxxxxx the lowercase MAC address of the connector
offline.find-ip-fail = Error trying to find IP address for connector with ID {0}
offline.communication-data-error = Communication data error while starting communication
offline.communication-error = Error in communication: {0}
offline.no-bridge = No bridge defined for device: {0}
offline.no-bridge-handler = No bridge handler defined for device: {0}
+offline.invalid-device-id = Device ID {0} not defined in the connector
+offline.invalid-device-type = Thing type does not match device type {0}
+offline.device-not-syncing = Device {0} not syncing with K1 hub
+offline.device-fault = Device {0} has a fault
+