diff --git a/bundles/org.openhab.binding.sensibo/README.md b/bundles/org.openhab.binding.sensibo/README.md index 606996007ea78..d15e82d7efb75 100644 --- a/bundles/org.openhab.binding.sensibo/README.md +++ b/bundles/org.openhab.binding.sensibo/README.md @@ -43,7 +43,7 @@ Or you can find it during discovery. | mode | R/W | String | Current mode (cool, heat, etc, actual modes provided provided by the API) being active | | fanLevel | R/W | String | Current fan level (low, auto etc, actual levels provided provided by the API | | swingMode | R/W | String | Current swing mode (actual modes provided provided by the API | -| timer | R/W | Number | Number of seconds until AC is switched off automatically | +| timer | R/W | Number | Number of seconds until AC is switched off automatically. Setting to a value less than 60 seconds will cancel timer | ## Full Example diff --git a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/dto/deletetimer/DeleteTimerReponse.java b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/dto/deletetimer/DeleteTimerReponse.java new file mode 100644 index 0000000000000..eff4e52b47fdb --- /dev/null +++ b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/dto/deletetimer/DeleteTimerReponse.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2010-2019 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.sensibo.internal.dto.deletetimer; + +/** + * @author Arne Seime - Initial contribution + */ +public class DeleteTimerReponse { + +} diff --git a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/dto/deletetimer/DeleteTimerRequest.java b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/dto/deletetimer/DeleteTimerRequest.java new file mode 100644 index 0000000000000..b8490108769f8 --- /dev/null +++ b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/dto/deletetimer/DeleteTimerRequest.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2010-2019 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.sensibo.internal.dto.deletetimer; + +import org.eclipse.jetty.http.HttpMethod; +import org.openhab.binding.sensibo.internal.dto.AbstractRequest; + +/** + * @author Arne Seime - Initial contribution + */ +public class DeleteTimerRequest extends AbstractRequest { + public DeleteTimerRequest(String podId) { + this.podId = podId; + } + + public transient String podId; // Transient fields are ignored by gson + + @Override + public String getRequestUrl() { + return String.format("/v1/pods/%s/timer/", podId); + } + + @Override + public String getMethod() { + return HttpMethod.DELETE.asString(); + } +} diff --git a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboAccountHandler.java b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboAccountHandler.java index 4f58b81324d7f..dd2a2397d8542 100644 --- a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboAccountHandler.java +++ b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboAccountHandler.java @@ -44,6 +44,7 @@ import org.openhab.binding.sensibo.internal.client.RequestLogger; import org.openhab.binding.sensibo.internal.config.SensiboAccountConfiguration; import org.openhab.binding.sensibo.internal.dto.AbstractRequest; +import org.openhab.binding.sensibo.internal.dto.deletetimer.DeleteTimerRequest; import org.openhab.binding.sensibo.internal.dto.poddetails.GetPodsDetailsRequest; import org.openhab.binding.sensibo.internal.dto.poddetails.PodDetails; import org.openhab.binding.sensibo.internal.dto.pods.GetPodsRequest; @@ -278,6 +279,11 @@ private Request buildSetTimerRequest(SetTimerRequest setTimerRequest) { return req; } + private Request buildDeleteTimerRequest(DeleteTimerRequest deleteTimerRequest) { + final Request req = buildRequest(deleteTimerRequest); + return req; + } + private Request buildRequest(final AbstractRequest req) { Request request = httpClient.newRequest(API_ENDPOINT + req.getRequestUrl()).param("apiKey", config.apiKey) .method(req.getMethod()); @@ -314,22 +320,32 @@ public void updateSensiboSkyAcState(@Nullable final String macAddress, String pr } } - public void updateSensiboSkyTimer(@Nullable final String macAddress, int secondsFromNow) { + public void updateSensiboSkyTimer(@Nullable final String macAddress, @Nullable Integer secondsFromNow) { Optional optionalHeater = model.findSensiboSkyByMacAddress(macAddress); if (optionalHeater.isPresent()) { SensiboSky sensiboSky = optionalHeater.get(); try { + if (secondsFromNow != null && secondsFromNow >= 60) { + org.openhab.binding.sensibo.internal.dto.poddetails.AcState offState = new org.openhab.binding.sensibo.internal.dto.poddetails.AcState( + sensiboSky.getAcState()); + offState.on = false; + + SetTimerRequest setTimerRequest = new SetTimerRequest(sensiboSky.getId(), secondsFromNow / 60, + offState); + Request request = buildSetTimerRequest(setTimerRequest); + // No data in response + sendRequest(request, setTimerRequest, new TypeToken() { + }.getType()); - org.openhab.binding.sensibo.internal.dto.poddetails.AcState offState = new org.openhab.binding.sensibo.internal.dto.poddetails.AcState( - sensiboSky.getAcState()); - offState.on = false; + } else { + DeleteTimerRequest setTimerRequest = new DeleteTimerRequest(sensiboSky.getId()); + Request request = buildDeleteTimerRequest(setTimerRequest); + // No data in response + sendRequest(request, setTimerRequest, new TypeToken() { + }.getType()); + + } - SetTimerRequest setAcStatePropertyRequest = new SetTimerRequest(sensiboSky.getId(), secondsFromNow / 60, - offState); - Request request = buildSetTimerRequest(setAcStatePropertyRequest); - // No data in response - sendRequest(request, setAcStatePropertyRequest, new TypeToken() { - }.getType()); } catch (SensiboCommunicationException e) { logger.debug("Error setting timer for {}", macAddress, e); } diff --git a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java index a286ee0489432..d04c128026349 100644 --- a/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java +++ b/bundles/org.openhab.binding.sensibo/src/main/java/org/openhab/binding/sensibo/internal/handler/SensiboSkyHandler.java @@ -102,7 +102,7 @@ private void updateAcState(SensiboSky sensiboSky, String property, Object value) } } - private void updateTimer(SensiboSky sensiboSky, int secondsFromNowUntilSwitchOff) { + private void updateTimer(SensiboSky sensiboSky, @Nullable Integer secondsFromNowUntilSwitchOff) { final SensiboAccountHandler accountHandler = getAccountHandler(); if (accountHandler != null) { accountHandler.updateSensiboSkyTimer(config.macAddress, secondsFromNowUntilSwitchOff); @@ -169,7 +169,7 @@ protected void handleCommand(@NonNull final ChannelUID channelUID, @NonNull fina } } else if (CHANNEL_TIMER.equals(channelUID.getId())) { if (command instanceof RefreshType) { - if (unit.getTimer() != null && unit.getTimer().secondsRemaining >= 60) { + if (unit.getTimer() != null && unit.getTimer().secondsRemaining > 0) { updateState(channelUID, new DecimalType(unit.getTimer().secondsRemaining)); } else { updateState(channelUID, UnDefType.UNDEF); @@ -177,6 +177,8 @@ protected void handleCommand(@NonNull final ChannelUID channelUID, @NonNull fina } else if (command instanceof DecimalType) { final DecimalType newValue = (DecimalType) command; updateTimer(unit, newValue.intValue()); + } else { + updateTimer(unit, null); } } } else {