[plugwiseha] Fix set the scene for a zone (#13832)

* Fix request body

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel 2022-12-09 19:08:41 +01:00 committed by GitHub
parent 7480c63636
commit 76c785947b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 5 deletions

View File

@ -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);
}

View File

@ -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<T> {
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) {

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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);