mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[elroconnects] Set thingStatus earlier in initialize (#12877)
* Set thingStatus earlier in initialize * Check device configuration * Make sure to always set thing status * Make thing status message localizable Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
This commit is contained in:
parent
29a45ef1ab
commit
f5e5b5189a
@ -123,14 +123,15 @@ public class ElroConnectsDeviceCxsmAlarm extends ElroConnectsDevice {
|
||||
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));
|
||||
|
@ -88,15 +88,16 @@ public class ElroConnectsDeviceEntrySensor extends ElroConnectsDevice {
|
||||
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,
|
||||
|
@ -116,14 +116,15 @@ public class ElroConnectsDeviceGenericAlarm extends ElroConnectsDevice {
|
||||
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));
|
||||
|
@ -87,15 +87,16 @@ public class ElroConnectsDeviceMotionSensor extends ElroConnectsDevice {
|
||||
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,
|
||||
|
@ -69,6 +69,8 @@ public class ElroConnectsDevicePowerSocket extends ElroConnectsDevice {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -81,8 +83,8 @@ public class ElroConnectsDevicePowerSocket extends ElroConnectsDevice {
|
||||
: (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);
|
||||
}
|
||||
|
@ -75,7 +75,8 @@ public class ElroConnectsDeviceTemperatureSensor extends ElroConnectsDevice {
|
||||
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));
|
||||
|
@ -121,6 +121,8 @@ public class ElroConnectsAccountHandler extends BaseBridgeHandler {
|
||||
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) {
|
||||
|
@ -162,16 +162,18 @@ public class ElroConnectsBridgeHandler extends BaseBridgeHandler {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -12,11 +12,14 @@
|
||||
*/
|
||||
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;
|
||||
@ -24,6 +27,7 @@ import org.openhab.core.thing.ChannelUID;
|
||||
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;
|
||||
@ -49,12 +53,30 @@ public class ElroConnectsDeviceHandler extends BaseThingHandler {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,6 +112,15 @@ public class ElroConnectsDeviceHandler extends BaseThingHandler {
|
||||
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();
|
||||
|
@ -93,8 +93,8 @@ offline.credentials-error = Invalid username or password
|
||||
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}
|
||||
@ -104,3 +104,8 @@ offline.no-hub-address = Error in communication, hub address was not set
|
||||
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user