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;
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);
}
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;
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<ByteBuffer> 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) {
@XStreamImplicit(itemFieldName = "actuator_functionality", keyFieldName = "type")
private ActuatorFunctionalities actuatorFunctionalities;
- public Location(String presetScene) {
- this.preset = presetScene;
- }
-
public String getName() {
return name;
}
return null;
}
+ public void setPreset(String preset) {
+ this.preset = preset;
+ }
+
public int applianceCount() {
if (this.locationAppliances == null) {
return 0;
--- /dev/null
+/**
+ * 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;
+}
import java.time.ZonedDateTime;
import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
/**
* The {@link PlugwiseBaseModel} abstract class contains
*/
public abstract class PlugwiseBaseModel {
+ @XStreamAsAttribute
private String id;
@XStreamAlias("created_date")
public ZonedDateTime getDeletedDate() {
return deletedDate;
}
+
+ public void setId(String id) {
+ this.id = id;
+ }
}
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;
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);