mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[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:
parent
7480c63636
commit
76c785947b
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user