Skip to content

Commit d2a6d60

Browse files
Novanicmarkus7017
authored andcommitted
Revert "[innogysmarthome] Reconnect fixes (openhab#8182) (openhab#8318)" (openhab#8324)
This reverts commit b621062. Reopens openhab#8182 Signed-off-by: Sven Strohschein <[email protected]>
1 parent e4712bd commit d2a6d60

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/InnogyWebSocket.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class InnogyWebSocket {
5252
/**
5353
* Constructs the {@link InnogyWebSocket}.
5454
*
55-
* @param eventListener the responsible {@link InnogyBridgeHandler}
55+
* @param bridgeHandler the responsible {@link InnogyBridgeHandler}
5656
* @param webSocketURI the {@link URI} of the websocket endpoint
5757
* @param maxIdleTimeout
5858
*/
@@ -128,8 +128,7 @@ public void onConnect(Session session) {
128128
public void onClose(int statusCode, String reason) {
129129
if (statusCode == StatusCode.NORMAL) {
130130
logger.info("Connection to innogy Webservice was closed normally.");
131-
} else if (!closing) {
132-
//An additional reconnect attempt is only required when the close/stop wasn't executed by the binding.
131+
} else {
133132
logger.info("Connection to innogy Webservice was closed abnormally (code: {}). Reason: {}", statusCode,
134133
reason);
135134
eventListener.connectionClosed();

bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
* The {@link InnogyBridgeHandler} is responsible for handling the innogy SmartHome controller including the connection
8383
* to the innogy backend for all communications with the innogy {@link Device}s.
8484
* <p/>
85-
* It implements the {@link AccessTokenRefreshListener} to handle updates of the oauth2 tokens and the
85+
* It implements the {@link CredentialRefreshListener} to handle updates of the oauth2 tokens and the
8686
* {@link EventListener} to handle {@link Event}s, that are received by the {@link InnogyWebSocket}.
8787
* <p/>
8888
* The {@link Device}s are organized by the {@link DeviceStructureManager}, which is also responsible for the connection
@@ -97,6 +97,8 @@ public class InnogyBridgeHandler extends BaseBridgeHandler
9797

9898
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_BRIDGE);
9999

100+
private static final long WEBSOCKET_TIMEOUT_RETRY_SECONDS = 5;
101+
100102
private final Logger logger = LoggerFactory.getLogger(InnogyBridgeHandler.class);
101103
private final Gson gson = new Gson();
102104
private final Object lock = new Object();
@@ -240,10 +242,8 @@ private void startClient() {
240242
return;
241243
}
242244
}
243-
244-
Device bridgeDevice = deviceStructMan.getBridgeDevice();
245-
setBridgeProperties(bridgeDevice);
246-
bridgeId = bridgeDevice.getId();
245+
setBridgeProperties(deviceStructMan.getBridgeDevice());
246+
bridgeId = deviceStructMan.getBridgeDevice().getId();
247247
startWebsocket();
248248
cancelReinitJob();
249249
}
@@ -508,7 +508,7 @@ public void onEvent(final String msg) {
508508

509509
case BaseEvent.TYPE_DISCONNECT:
510510
logger.debug("Websocket disconnected.");
511-
scheduleRestartClient(REINITIALIZE_DELAY_SECONDS);
511+
scheduleRestartClient(0);
512512
break;
513513

514514
case BaseEvent.TYPE_CONFIGURATION_CHANGED:
@@ -892,17 +892,18 @@ public void commandSetRollerShutterStop(final String deviceId, ShutterAction.Shu
892892
* @return boolean true, if binding should continue.
893893
*/
894894
private boolean handleClientException(final Exception e) {
895-
boolean isReinitialize = true;
895+
long reinitialize = REINITIALIZE_DELAY_SECONDS;
896896
if (e instanceof SessionExistsException) {
897897
logger.debug("Session already exists. Continuing...");
898-
isReinitialize = false;
898+
reinitialize = -1;
899899
} else if (e instanceof InvalidActionTriggeredException) {
900900
logger.debug("Error triggering action: {}", e.getMessage());
901-
isReinitialize = false;
901+
reinitialize = -1;
902902
} else if (e instanceof RemoteAccessNotAllowedException) {
903903
// Remote access not allowed (usually by IP address change)
904904
logger.debug("Remote access not allowed. Dropping access token and reinitializing binding...");
905905
refreshAccessToken();
906+
reinitialize = 0;
906907
} else if (e instanceof ControllerOfflineException) {
907908
logger.debug("innogy SmartHome Controller is offline.");
908909
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, e.getMessage());
@@ -918,11 +919,12 @@ private boolean handleClientException(final Exception e) {
918919
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
919920
} else if (e instanceof TimeoutException) {
920921
logger.debug("WebSocket timeout: {}", e.getMessage());
922+
reinitialize = WEBSOCKET_TIMEOUT_RETRY_SECONDS;
921923
} else if (e instanceof SocketTimeoutException) {
922924
logger.debug("Socket timeout: {}", e.getMessage());
923925
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
924926
} else if (e instanceof InterruptedException) {
925-
isReinitialize = false;
927+
reinitialize = -1;
926928
Thread.currentThread().interrupt();
927929
} else if (e instanceof ExecutionException) {
928930
logger.debug("ExecutionException: {}", ExceptionUtils.getRootCauseMessage(e));
@@ -931,8 +933,8 @@ private boolean handleClientException(final Exception e) {
931933
logger.debug("Unknown exception", e);
932934
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, e.getMessage());
933935
}
934-
if (isReinitialize) {
935-
scheduleRestartClient(REINITIALIZE_DELAY_SECONDS);
936+
if (reinitialize >= 0) {
937+
scheduleRestartClient(reinitialize);
936938
return true;
937939
}
938940
return false;

bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyDeviceHandler.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public InnogyDeviceHandler(final Thing thing) {
8080
public void handleCommand(final ChannelUID channelUID, final Command command) {
8181
logger.debug("handleCommand called for channel '{}' of type '{}' with command '{}'", channelUID,
8282
getThing().getThingTypeUID().getId(), command);
83-
@Nullable final InnogyBridgeHandler innogyBridgeHandler = getInnogyBridgeHandler();
83+
final InnogyBridgeHandler innogyBridgeHandler = getInnogyBridgeHandler();
8484
if (innogyBridgeHandler == null) {
8585
logger.warn("BridgeHandler not found. Cannot handle command without bridge.");
8686
return;
@@ -91,7 +91,7 @@ public void handleCommand(final ChannelUID channelUID, final Command command) {
9191
}
9292

9393
if (command instanceof RefreshType) {
94-
@Nullable final Device device = innogyBridgeHandler.getDeviceById(deviceId);
94+
final Device device = innogyBridgeHandler.getDeviceById(deviceId);
9595
if (device != null) {
9696
onDeviceStateChanged(device);
9797
}
@@ -102,8 +102,8 @@ public void handleCommand(final ChannelUID channelUID, final Command command) {
102102
if (CHANNEL_SWITCH.equals(channelUID.getId())) {
103103
// DEBUGGING HELPER
104104
// ----------------
105-
@Nullable final Device device = innogyBridgeHandler.getDeviceById(deviceId);
106-
if (device != null && DEBUG.equals(device.getConfig().getName())) {
105+
final Device device = innogyBridgeHandler.getDeviceById(deviceId);
106+
if (DEBUG.equals(device.getConfig().getName())) {
107107
logger.debug("DEBUG SWITCH ACTIVATED!");
108108
if (OnOffType.ON.equals(command)) {
109109
innogyBridgeHandler.onEvent(
@@ -244,7 +244,7 @@ private void initializeThing(@Nullable final ThingStatus bridgeStatus) {
244244
*/
245245
private boolean initializeProperties() {
246246
synchronized (this.lock) {
247-
@Nullable final Device device = getDevice();
247+
final Device device = getDevice();
248248
if (device != null) {
249249
final Map<String, String> properties = editProperties();
250250
properties.put(PROPERTY_ID, device.getId());
@@ -327,11 +327,11 @@ private boolean initializeProperties() {
327327
private @Nullable InnogyBridgeHandler getInnogyBridgeHandler() {
328328
synchronized (this.lock) {
329329
if (this.bridgeHandler == null) {
330-
@Nullable final Bridge bridge = getBridge();
330+
final Bridge bridge = getBridge();
331331
if (bridge == null) {
332332
return null;
333333
}
334-
@Nullable final ThingHandler handler = bridge.getHandler();
334+
final ThingHandler handler = bridge.getHandler();
335335
if (handler instanceof InnogyBridgeHandler) {
336336
this.bridgeHandler = (InnogyBridgeHandler) handler;
337337
this.bridgeHandler.registerDeviceStatusListener(this);
@@ -356,7 +356,7 @@ public void onDeviceStateChanged(final Device device) {
356356

357357
// DEVICE STATES
358358
if (device.hasDeviceState()) {
359-
@Nullable Boolean reachable = null;
359+
Boolean reachable = null;
360360
if (device.getDeviceState().hasIsReachableState()) {
361361
reachable = device.getDeviceState().isReachable();
362362
}
@@ -904,17 +904,18 @@ public void onDeviceStateChanged(final Device changedDevice, final Event event)
904904
} else {
905905
logger.debug("Unsupported capability type {}.", capability.getType());
906906
}
907-
} else {
907+
} else { // capability.hasState()
908908
logger.debug("Capability {} has no state (yet?) - refreshing device.", capability.getName());
909+
final InnogyBridgeHandler innogyBridgeHandler = getInnogyBridgeHandler();
909910

910-
@Nullable final InnogyBridgeHandler innogyBridgeHandler = getInnogyBridgeHandler();
911911
if (innogyBridgeHandler != null) {
912912
device = innogyBridgeHandler.refreshDevice(deviceId);
913913
}
914914
if (device != null) {
915915
capabilityMap = device.getCapabilityMap();
916916
capability = capabilityMap.get(linkedCapabilityId);
917917
if (capability.hasState()) {
918+
capabilityState = capability.getCapabilityState();
918919
deviceChanged = true;
919920
}
920921
}
@@ -928,7 +929,9 @@ public void onDeviceStateChanged(final Device changedDevice, final Event event)
928929
onDeviceStateChanged(device);
929930
} else {
930931
logger.debug("Device {}/{} has no state.", device.getConfig().getName(), device.getId());
932+
return;
931933
}
934+
932935
}
933936
}
934937
}
@@ -944,8 +947,8 @@ private int invertValueIfConfigured(final String channelId, final int value) {
944947
logger.debug("Channel {} cannot be inverted.", channelId);
945948
return value;
946949
}
950+
final Channel channel = getThing().getChannel(channelId);
947951

948-
@Nullable final Channel channel = getThing().getChannel(channelId);
949952
if (channel == null) {
950953
logger.debug("Channel {} was null! Value not inverted.", channelId);
951954
return value;

0 commit comments

Comments
 (0)