Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[netatmo] Room-Thing offline after restart #13467

Merged
merged 2 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,24 @@ public class RoomActions implements ThingActions {
SetpointMode.HOME);

private @Nullable CommonInterface handler;
private Optional<EnergyCapability> energy = Optional.empty();

public RoomActions() {
logger.debug("Netatmo RoomActions service created");
}

private Optional<EnergyCapability> 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);
}
}

Expand All @@ -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")
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -245,6 +246,12 @@ public synchronized <T> T executeUri(URI uri, HttpMethod method, Class<T> 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());
Expand Down