diff --git a/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/PlugwiseHAController.java b/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/PlugwiseHAController.java index c46f0a8f0..e1739c795 100644 --- a/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/PlugwiseHAController.java +++ b/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/PlugwiseHAController.java @@ -37,6 +37,7 @@ import org.openhab.binding.plugwiseha.internal.api.model.dto.DomainObjects; import org.openhab.binding.plugwiseha.internal.api.model.dto.GatewayInfo; import org.openhab.binding.plugwiseha.internal.api.model.dto.Location; import org.openhab.binding.plugwiseha.internal.api.model.dto.Locations; +import org.openhab.binding.plugwiseha.internal.api.model.dto.LocationsArray; import org.openhab.binding.plugwiseha.internal.api.xml.PlugwiseHAXStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -395,7 +396,15 @@ public class PlugwiseHAController { request.setPath("/core/locations"); request.addPathParameter("id", String.format("%s", location.getId())); - request.setBodyParameter(new Location(state)); + + Location locationWithChangesOnly = new Location(); + locationWithChangesOnly.setPreset(state); + locationWithChangesOnly.setId(location.getId()); + + LocationsArray locations = new LocationsArray(); + locations.items = new Location[] { locationWithChangesOnly }; + + request.setBodyParameter(locations); executeRequest(request); } diff --git a/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/PlugwiseHAControllerRequest.java b/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/PlugwiseHAControllerRequest.java index b559f64cd..f921e3a39 100644 --- a/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/PlugwiseHAControllerRequest.java +++ b/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/PlugwiseHAControllerRequest.java @@ -17,9 +17,11 @@ import java.io.StringWriter; import java.net.ConnectException; import java.net.SocketTimeoutException; import java.net.UnknownHostException; +import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ExecutionException; @@ -225,6 +227,22 @@ public class PlugwiseHAControllerRequest { this.logger.debug("Performing API request: {} {}", request.getMethod(), request.getURI()); + if (logger.isTraceEnabled()) { + String content = ""; + final ContentProvider provider = request.getContent(); + if (provider != null) { + final Iterator it = provider.iterator(); + while (it.hasNext()) { + final ByteBuffer next = it.next(); + final byte[] bytes = new byte[next.capacity()]; + next.get(bytes); + content += String.format("{}\n", new String(bytes, StandardCharsets.UTF_8)); + } + } + + logger.trace(">> \n{}", content); + } + try { response = request.send(); } catch (InterruptedException e) { diff --git a/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/dto/Location.java b/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/dto/Location.java index 6e6673e1f..b2bbf92c9 100644 --- a/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/dto/Location.java +++ b/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/dto/Location.java @@ -47,10 +47,6 @@ public class Location extends PlugwiseBaseModel implements PlugwiseComparableDat @XStreamImplicit(itemFieldName = "actuator_functionality", keyFieldName = "type") private ActuatorFunctionalities actuatorFunctionalities; - public Location(String presetScene) { - this.preset = presetScene; - } - public String getName() { return name; } @@ -116,6 +112,10 @@ public class Location extends PlugwiseBaseModel implements PlugwiseComparableDat return null; } + public void setPreset(String preset) { + this.preset = preset; + } + public int applianceCount() { if (this.locationAppliances == null) { return 0; diff --git a/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/dto/LocationsArray.java b/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/dto/LocationsArray.java new file mode 100644 index 000000000..bf44ca32e --- /dev/null +++ b/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/dto/LocationsArray.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2010-2022 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.plugwiseha.internal.api.model.dto; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamImplicit; + +/** + * The {@link LocationsArray} class is an object model class that mirrors the XML + * structure provided by the Plugwise Home Automation controller for the + * collection of Plugwise locations/zones. + * + * @author L. Siepel - Initial contribution + */ + +@XStreamAlias("locations") +public class LocationsArray { + + @XStreamImplicit + public Location[] items; +} diff --git a/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/dto/PlugwiseBaseModel.java b/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/dto/PlugwiseBaseModel.java index a4638f1a2..a90327a0b 100644 --- a/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/dto/PlugwiseBaseModel.java +++ b/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/model/dto/PlugwiseBaseModel.java @@ -15,6 +15,7 @@ package org.openhab.binding.plugwiseha.internal.api.model.dto; import java.time.ZonedDateTime; import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamAsAttribute; /** * The {@link PlugwiseBaseModel} abstract class contains @@ -24,6 +25,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; */ public abstract class PlugwiseBaseModel { + @XStreamAsAttribute private String id; @XStreamAlias("created_date") @@ -57,4 +59,8 @@ public abstract class PlugwiseBaseModel { public ZonedDateTime getDeletedDate() { return deletedDate; } + + public void setId(String id) { + this.id = id; + } } diff --git a/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/xml/PlugwiseHAXStream.java b/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/xml/PlugwiseHAXStream.java index d8c16ab98..51f646123 100644 --- a/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/xml/PlugwiseHAXStream.java +++ b/bundles/org.openhab.binding.plugwiseha/src/main/java/org/openhab/binding/plugwiseha/internal/api/xml/PlugwiseHAXStream.java @@ -29,6 +29,7 @@ import org.openhab.binding.plugwiseha.internal.api.model.dto.GatewayEnvironment; import org.openhab.binding.plugwiseha.internal.api.model.dto.GatewayInfo; import org.openhab.binding.plugwiseha.internal.api.model.dto.Location; import org.openhab.binding.plugwiseha.internal.api.model.dto.Locations; +import org.openhab.binding.plugwiseha.internal.api.model.dto.LocationsArray; import org.openhab.binding.plugwiseha.internal.api.model.dto.Log; import org.openhab.binding.plugwiseha.internal.api.model.dto.Logs; import org.openhab.binding.plugwiseha.internal.api.model.dto.Module; @@ -87,6 +88,7 @@ public class PlugwiseHAXStream extends XStream { this.allowClass(Appliance.class); this.allowClass(Modules.class); this.allowClass(Module.class); + this.allowClass(LocationsArray.class); this.allowClass(Locations.class); this.allowClass(Location.class); this.allowClass(Logs.class);