diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/action/RoomActions.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/action/RoomActions.java index 1ab991f3ac30f..c4605833a8744 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/action/RoomActions.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/action/RoomActions.java @@ -42,18 +42,24 @@ public class RoomActions implements ThingActions { SetpointMode.HOME); private @Nullable CommonInterface handler; - private Optional energy = Optional.empty(); public RoomActions() { logger.debug("Netatmo RoomActions service created"); } + private Optional getEnergyCapability() { + CommonInterface localHandler = handler; + if (localHandler != null) { + return localHandler.getHomeCapability(EnergyCapability.class); + } + return Optional.empty(); + } + @Override public void setThingHandler(@Nullable ThingHandler handler) { if (handler instanceof CommonInterface) { CommonInterface commonHandler = (CommonInterface) handler; this.handler = commonHandler; - energy = commonHandler.getHomeCapability(EnergyCapability.class); } } @@ -77,7 +83,8 @@ public void setThermRoomTempSetpoint( logger.info("Temperature provided but no endtime given, action ignored"); return; } - energy.ifPresent(cap -> cap.setRoomThermTemp(roomHandler.getId(), temp, endTime, SetpointMode.MANUAL)); + getEnergyCapability() + .ifPresent(cap -> cap.setRoomThermTemp(roomHandler.getId(), temp, endTime, SetpointMode.MANUAL)); } @RuleAction(label = "@text/actionSetThermRoomModeSetpointLabel", description = "@text/actionSetThermRoomModeSetpointDesc") @@ -116,7 +123,7 @@ public void setThermRoomModeSetpoint( long setpointEnd = targetEndTime; SetpointMode setpointMode = targetMode; - energy.ifPresent(cap -> cap.setRoomThermTemp(roomHandler.getId(), 0, setpointEnd, setpointMode)); + getEnergyCapability().ifPresent(cap -> cap.setRoomThermTemp(roomHandler.getId(), 0, setpointEnd, setpointMode)); } public static void setThermRoomTempSetpoint(ThingActions actions, @Nullable Double temp, @Nullable Long endTime) { diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java index 87aa07526cd68..702c7820cfcf9 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java @@ -46,6 +46,7 @@ import org.openhab.binding.netatmo.internal.api.RestManager; import org.openhab.binding.netatmo.internal.api.SecurityApi; import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.Scope; +import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.ServiceError; import org.openhab.binding.netatmo.internal.config.ApiHandlerConfiguration; import org.openhab.binding.netatmo.internal.config.BindingConfiguration; import org.openhab.binding.netatmo.internal.config.ConfigurationLevel; @@ -245,6 +246,12 @@ public synchronized T executeUri(URI uri, HttpMethod method, Class clazz, throw new NetatmoException(error); } return deserializer.deserialize(clazz, responseBody); + } catch (NetatmoException e) { + if (e.getStatusCode() == ServiceError.MAXIMUM_USAGE_REACHED) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); + prepareReconnection(null, null); + } + throw e; } catch (InterruptedException e) { Thread.currentThread().interrupt(); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());