From 36425cbef6163fdc2d0a02e0018272079a8b1f9c Mon Sep 17 00:00:00 2001 From: clinique Date: Thu, 29 Sep 2022 18:02:52 +0200 Subject: [PATCH 1/2] Correcting issue by late loading of the capability. Signed-off-by: clinique --- .../netatmo/internal/action/RoomActions.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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) { From 4e05180f8bed50bbfd952676a2acc47e28ec17b4 Mon Sep 17 00:00:00 2001 From: clinique Date: Fri, 30 Sep 2022 10:02:12 +0200 Subject: [PATCH 2/2] Handle MAXIMUM_USAGE_REACHED at ApiBridgeHandler level. Signed-off-by: clinique --- .../binding/netatmo/internal/handler/ApiBridgeHandler.java | 7 +++++++ 1 file changed, 7 insertions(+) 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());