[plugwiseha] Improve connection stability (#17677)

* Improvements
* Sync config with readme
* Fix unit detection
* Fix NPE

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel 2024-11-17 11:25:16 +01:00 committed by GitHub
parent 562ce0348f
commit 4a5aa04c0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 106 additions and 111 deletions

View File

@ -101,10 +101,13 @@ public class PlugwiseHAController {
callback.run();
}
/**
* Refreshes all changed objects. Will result in a call to the remote service.
*
* @throws PlugwiseHAException
*/
public void refresh() throws PlugwiseHAException {
synchronized (this) {
this.getUpdatedDomainObjects();
}
domainObjects = this.getUpdatedDomainObjects();
}
// Public API methods
@ -113,7 +116,7 @@ public class PlugwiseHAController {
return getGatewayInfo(false);
}
public GatewayInfo getGatewayInfo(Boolean forceRefresh) throws PlugwiseHAException {
private synchronized GatewayInfo getGatewayInfo(Boolean forceRefresh) throws PlugwiseHAException {
GatewayInfo gatewayInfo = null;
DomainObjects localDomainObjects = this.domainObjects;
if (localDomainObjects != null) {
@ -133,12 +136,12 @@ public class PlugwiseHAController {
DomainObjects domainObjects = executeRequest(request);
this.gatewayUpdateDateTime = ZonedDateTime.parse(request.getServerDateTime(), PlugwiseHAController.FORMAT);
return mergeDomainObjects(domainObjects).getGatewayInfo();
domainObjects = mergeDomainObjects(domainObjects);
return domainObjects.getGatewayInfo();
}
}
public Appliances getAppliances(Boolean forceRefresh) throws PlugwiseHAException {
private synchronized Appliances getAppliances(Boolean forceRefresh) throws PlugwiseHAException {
Appliances appliances = null;
DomainObjects localDomainObjects = this.domainObjects;
if (localDomainObjects != null) {
@ -167,6 +170,13 @@ public class PlugwiseHAController {
}
}
/**
* Gets the appliance with the givven id. May result in a call to the remote service.
*
* @param id of the appliance
* @return Appliance may be null
* @throws PlugwiseHAException
*/
public @Nullable Appliance getAppliance(String id) throws PlugwiseHAException {
Appliances appliances = this.getAppliances(false);
if (!appliances.containsKey(id)) {
@ -181,7 +191,7 @@ public class PlugwiseHAController {
}
}
public Locations getLocations(Boolean forceRefresh) throws PlugwiseHAException {
private synchronized Locations getLocations(Boolean forceRefresh) throws PlugwiseHAException {
Locations locations = null;
DomainObjects localDomainObjects = this.domainObjects;
if (localDomainObjects != null) {
@ -209,6 +219,13 @@ public class PlugwiseHAController {
}
}
/**
* Gets the location with the givven id. May result in a call to the remote service.
*
* @param id of the location
* @return Location may be null
* @throws PlugwiseHAException
*/
public @Nullable Location getLocation(String id) throws PlugwiseHAException {
Locations locations = this.getLocations(false);
if (!locations.containsKey(id)) {
@ -223,7 +240,13 @@ public class PlugwiseHAController {
}
}
public @Nullable DomainObjects getDomainObjects() throws PlugwiseHAException {
/**
* Gets and caches all objects from the remote service resulting in a call to the remote service.
*
* @return up to date DomainObjects may be null
* @throws PlugwiseHAException
*/
public synchronized @Nullable DomainObjects getAndMergeDomainObjects() throws PlugwiseHAException {
PlugwiseHAControllerRequest<DomainObjects> request;
request = newRequest(DomainObjects.class, this.domainObjectsTransformer);
@ -239,27 +262,24 @@ public class PlugwiseHAController {
return mergeDomainObjects(domainObjects);
}
public @Nullable DomainObjects getUpdatedDomainObjects() throws PlugwiseHAException {
private @Nullable DomainObjects getUpdatedDomainObjects() throws PlugwiseHAException {
ZonedDateTime localGatewayUpdateDateTime = this.gatewayUpdateDateTime;
ZonedDateTime localGatewayFullUpdateDateTime = this.gatewayFullUpdateDateTime;
if (localGatewayUpdateDateTime == null || localGatewayFullUpdateDateTime == null) {
return getDomainObjects();
return getAndMergeDomainObjects();
} else if (localGatewayUpdateDateTime.isBefore(ZonedDateTime.now().minusSeconds(maxAgeSecondsRefresh))) {
return getUpdatedDomainObjects(localGatewayUpdateDateTime);
return getUpdatedAndMergeDomainObjects(localGatewayUpdateDateTime.toEpochSecond());
} else if (localGatewayFullUpdateDateTime
.isBefore(ZonedDateTime.now().minusMinutes(MAX_AGE_MINUTES_FULL_REFRESH))) {
return getDomainObjects();
return getAndMergeDomainObjects();
} else {
return null;
}
}
public @Nullable DomainObjects getUpdatedDomainObjects(ZonedDateTime since) throws PlugwiseHAException {
return getUpdatedDomainObjects(since.toEpochSecond());
}
public @Nullable DomainObjects getUpdatedDomainObjects(Long since) throws PlugwiseHAException {
private synchronized @Nullable DomainObjects getUpdatedAndMergeDomainObjects(Long since)
throws PlugwiseHAException {
PlugwiseHAControllerRequest<DomainObjects> request;
request = newRequest(DomainObjects.class, this.domainObjectsTransformer);
@ -276,7 +296,7 @@ public class PlugwiseHAController {
return mergeDomainObjects(domainObjects);
}
public void setLocationThermostat(Location location, Double temperature) throws PlugwiseHAException {
public synchronized void setLocationThermostat(Location location, Double temperature) throws PlugwiseHAException {
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
Optional<ActuatorFunctionality> thermostat = location.getActuatorFunctionalities().getFunctionalityThermostat();
@ -291,7 +311,7 @@ public class PlugwiseHAController {
}
}
public void setThermostat(Appliance appliance, Double temperature) throws PlugwiseHAException {
public synchronized void setThermostat(Appliance appliance, Double temperature) throws PlugwiseHAException {
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
Optional<ActuatorFunctionality> thermostat = appliance.getActuatorFunctionalities()
.getFunctionalityThermostat();
@ -307,7 +327,7 @@ public class PlugwiseHAController {
}
}
public void setOffsetTemperature(Appliance appliance, Double temperature) throws PlugwiseHAException {
public synchronized void setOffsetTemperature(Appliance appliance, Double temperature) throws PlugwiseHAException {
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
Optional<ActuatorFunctionality> offsetTemperatureFunctionality = appliance.getActuatorFunctionalities()
.getFunctionalityOffsetTemperature();
@ -323,7 +343,7 @@ public class PlugwiseHAController {
}
}
public void setPreHeating(Location location, Boolean state) throws PlugwiseHAException {
public synchronized void setPreHeating(Location location, Boolean state) throws PlugwiseHAException {
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
Optional<ActuatorFunctionality> thermostat = location.getActuatorFunctionalities().getFunctionalityThermostat();
@ -335,7 +355,7 @@ public class PlugwiseHAController {
executeRequest(request);
}
public void setAllowCooling(Location location, Boolean state) throws PlugwiseHAException {
public synchronized void setAllowCooling(Location location, Boolean state) throws PlugwiseHAException {
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
Optional<ActuatorFunctionality> thermostat = location.getActuatorFunctionalities().getFunctionalityThermostat();
@ -347,7 +367,7 @@ public class PlugwiseHAController {
executeRequest(request);
}
public void setRegulationControl(Location location, String state) throws PlugwiseHAException {
public synchronized void setRegulationControl(Location location, String state) throws PlugwiseHAException {
List<String> allowStates = Arrays.asList("active", "passive", "off");
if (!allowStates.contains(state.toLowerCase())) {
this.logger.warn("Trying to set the regulation control to an invalid state");
@ -365,7 +385,7 @@ public class PlugwiseHAController {
executeRequest(request);
}
public void setRelay(Appliance appliance, Boolean state) throws PlugwiseHAException {
public synchronized void setRelay(Appliance appliance, Boolean state) throws PlugwiseHAException {
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
request.setPath("/core/appliances");
@ -375,7 +395,7 @@ public class PlugwiseHAController {
executeRequest(request);
}
public void setRelayLock(Appliance appliance, Boolean state) throws PlugwiseHAException {
public synchronized void setRelayLock(Appliance appliance, Boolean state) throws PlugwiseHAException {
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
request.setPath("/core/appliances");
@ -385,7 +405,7 @@ public class PlugwiseHAController {
executeRequest(request);
}
public void setPresetScene(Location location, String state) throws PlugwiseHAException {
public synchronized void setPresetScene(Location location, String state) throws PlugwiseHAException {
List<String> allowStates = Arrays.asList("home", "asleep", "away", "vacation", "no_frost");
if (!allowStates.contains(state.toLowerCase())) {
this.logger.warn("Trying to set the preset scene to an invalid state");
@ -409,19 +429,6 @@ public class PlugwiseHAController {
executeRequest(request);
}
public ZonedDateTime ping() throws PlugwiseHAException {
PlugwiseHAControllerRequest<Void> request;
request = newRequest(Void.class, null);
request.setPath("/cache/gateways");
request.addPathParameter("ping");
executeRequest(request);
return ZonedDateTime.parse(request.getServerDateTime(), PlugwiseHAController.FORMAT);
}
// Protected and private methods
private static Transformer setXSLT(StreamSource xsltSource) throws PlugwiseHAException {
@ -444,16 +451,13 @@ public class PlugwiseHAController {
@SuppressWarnings("null")
private <T> T executeRequest(PlugwiseHAControllerRequest<T> request) throws PlugwiseHAException {
T result;
result = request.execute();
return result;
return request.execute();
}
private DomainObjects mergeDomainObjects(@Nullable DomainObjects updatedDomainObjects) {
DomainObjects localDomainObjects = this.domainObjects;
if (localDomainObjects == null && updatedDomainObjects != null) {
this.domainObjects = updatedDomainObjects;
return updatedDomainObjects;
return this.domainObjects = updatedDomainObjects;
} else if (localDomainObjects != null && updatedDomainObjects == null) {
return localDomainObjects;
} else if (localDomainObjects != null && updatedDomainObjects != null) {
@ -467,7 +471,6 @@ public class PlugwiseHAController {
if (locations != null) {
localDomainObjects.mergeLocations(locations);
}
this.domainObjects = localDomainObjects;
return localDomainObjects;
} else {
return new DomainObjects();

View File

@ -72,6 +72,7 @@ public class PlugwiseHAControllerRequest<T> {
private static final String CONTENT_TYPE_TEXT_XML = MimeTypes.Type.TEXT_XML_8859_1.toString();
private static final long TIMEOUT_SECONDS = 5;
private static final int REQUEST_MAX_RETRY_COUNT = 3;
private static final int RETRY_DELAY_TIMOUT = 3000;
private final Logger logger = LoggerFactory.getLogger(PlugwiseHAControllerRequest.class);
private final XStream xStream;
@ -252,6 +253,12 @@ public class PlugwiseHAControllerRequest<T> {
} catch (TimeoutException e) {
if (retries > 0) {
this.logger.debug("TimeoutException occured, remaining retries {}", retries - 1);
try {
Thread.sleep(RETRY_DELAY_TIMOUT);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new PlugwiseHATimeoutException(ie);
}
return getContentResponse(retries - 1);
} else {
throw new PlugwiseHATimeoutException(e);

View File

@ -38,10 +38,7 @@ public class DateTimeConverter extends AbstractSingleValueConverter {
@Override
public boolean canConvert(@Nullable @SuppressWarnings("rawtypes") Class type) {
if (type == null) {
return false;
}
return ZonedDateTime.class.isAssignableFrom(type);
return (type == null) ? false : ZonedDateTime.class.isAssignableFrom(type);
}
@Override

View File

@ -24,15 +24,12 @@ public class ActuatorFunctionalityThermostat extends ActuatorFunctionality {
@SuppressWarnings("unused")
private Double setpoint;
@SuppressWarnings("unused")
@XStreamAlias("preheating_allowed")
private Boolean preheatingAllowed;
@SuppressWarnings("unused")
@XStreamAlias("cooling_allowed")
private Boolean coolingAllowed;
@SuppressWarnings("unused")
@XStreamAlias("regulation_control")
private String regulationControl;

View File

@ -30,7 +30,6 @@ public class DomainObjects {
@XStreamImplicit(itemFieldName = "location", keyFieldName = "id")
private Locations locations = new Locations();
@SuppressWarnings("unused")
@XStreamImplicit(itemFieldName = "module", keyFieldName = "id")
private Modules modules = new Modules();
@ -47,7 +46,9 @@ public class DomainObjects {
}
public Appliances mergeAppliances(Appliances updatedAppliances) {
if (updatedAppliances != null) {
if (appliances == null) {
this.appliances = updatedAppliances;
} else if (updatedAppliances != null) {
this.appliances.merge(updatedAppliances);
}
@ -55,7 +56,9 @@ public class DomainObjects {
}
public Locations mergeLocations(Locations updatedLocations) {
if (updatedLocations != null) {
if (locations == null) {
this.locations = updatedLocations;
} else if (updatedLocations != null) {
this.locations.merge(updatedLocations);
}

View File

@ -76,7 +76,7 @@ public class Log extends PlugwiseBaseModel implements PlugwiseComparableDate<Log
}
public Optional<String> getMeasurementUnit() {
return Optional.ofNullable(unit);
return Optional.ofNullable(unit != null && !unit.isBlank() ? unit : null);
}
public ZonedDateTime getMeasurementDate() {

View File

@ -30,7 +30,6 @@ import com.thoughtworks.xstream.annotations.XStreamImplicit;
@XStreamAlias("module")
public class Module extends PlugwiseBaseModel implements PlugwiseComparableDate<Module> {
@SuppressWarnings("unused")
@XStreamImplicit(itemFieldName = "service", keyFieldName = "id")
private Services services;

View File

@ -20,11 +20,9 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("service")
public class Service extends PlugwiseBaseModel {
@SuppressWarnings("unused")
@XStreamAlias("log_type")
private String logType;
@SuppressWarnings("unused")
@XStreamAlias("point_log")
private String pointLogId;
}

View File

@ -99,7 +99,7 @@ public class PlugwiseHADiscoveryService extends AbstractThingHandlerDiscoverySer
PlugwiseHAController controller = thingHandler.getController();
if (controller != null) {
DomainObjects domainObjects = controller.getDomainObjects();
DomainObjects domainObjects = controller.getAndMergeDomainObjects();
if (domainObjects != null) {
for (Location location : domainObjects.getLocations().values()) {

View File

@ -146,10 +146,8 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
}
break;
case APPLIANCE_OFFSET_CHANNEL:
if (command instanceof QuantityType quantityCommand) {
Unit<Temperature> unit = entity.getOffsetTemperatureUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
? SIUnits.CELSIUS
: ImperialUnits.FAHRENHEIT;
if (command instanceof QuantityType<?> quantityCommand) {
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
QuantityType<?> state = quantityCommand.toUnit(unit);
if (state != null) {
@ -172,9 +170,8 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
}
break;
case APPLIANCE_SETPOINT_CHANNEL:
if (command instanceof QuantityType quantityCommand) {
Unit<Temperature> unit = entity.getSetpointTemperatureUnit().orElse(UNIT_CELSIUS)
.equals(UNIT_CELSIUS) ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT;
if (command instanceof QuantityType<?> quantityCommand) {
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
QuantityType<?> state = quantityCommand.toUnit(unit);
if (state != null) {
@ -228,6 +225,11 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
return state;
}
private Unit<Temperature> getRemoteTemperatureUnit(Appliance entity) {
return UNIT_CELSIUS.equals(entity.getDHWTempUnit().orElse(UNIT_CELSIUS)) ? SIUnits.CELSIUS
: ImperialUnits.FAHRENHEIT;
}
@Override
protected void refreshChannel(Appliance entity, ChannelUID channelUID) {
String channelID = channelUID.getIdWithoutGroup();
@ -280,9 +282,7 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
break;
case APPLIANCE_OFFSET_CHANNEL:
if (entity.getOffsetTemperature().isPresent()) {
Unit<Temperature> unit = entity.getOffsetTemperatureUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
? SIUnits.CELSIUS
: ImperialUnits.FAHRENHEIT;
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
state = new QuantityType<>(entity.getOffsetTemperature().get(), unit);
}
break;
@ -298,16 +298,13 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
break;
case APPLIANCE_SETPOINT_CHANNEL:
if (entity.getSetpointTemperature().isPresent()) {
Unit<Temperature> unit = entity.getSetpointTemperatureUnit().orElse(UNIT_CELSIUS)
.equals(UNIT_CELSIUS) ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT;
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
state = new QuantityType<>(entity.getSetpointTemperature().get(), unit);
}
break;
case APPLIANCE_TEMPERATURE_CHANNEL:
if (entity.getTemperature().isPresent()) {
Unit<Temperature> unit = entity.getTemperatureUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
? SIUnits.CELSIUS
: ImperialUnits.FAHRENHEIT;
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
state = new QuantityType<>(entity.getTemperature().get(), unit);
}
break;
@ -330,8 +327,7 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
break;
case APPLIANCE_INTENDEDBOILERTEMP_CHANNEL:
if (entity.getIntendedBoilerTemp().isPresent()) {
Unit<Temperature> unit = entity.getIntendedBoilerTempUnit().orElse(UNIT_CELSIUS)
.equals(UNIT_CELSIUS) ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT;
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
state = new QuantityType<>(entity.getIntendedBoilerTemp().get(), unit);
}
break;
@ -358,17 +354,13 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
break;
case APPLIANCE_RETURNWATERTEMPERATURE_CHANNEL:
if (entity.getBoilerTemp().isPresent()) {
Unit<Temperature> unit = entity.getReturnWaterTempUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
? SIUnits.CELSIUS
: ImperialUnits.FAHRENHEIT;
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
state = new QuantityType<>(entity.getReturnWaterTemp().get(), unit);
}
break;
case APPLIANCE_DHWTEMPERATURE_CHANNEL:
if (entity.getDHWTemp().isPresent()) {
Unit<Temperature> unit = entity.getDHWTempUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
? SIUnits.CELSIUS
: ImperialUnits.FAHRENHEIT;
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
state = new QuantityType<>(entity.getDHWTemp().get(), unit);
}
break;
@ -379,25 +371,19 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
break;
case APPLIANCE_BOILERTEMPERATURE_CHANNEL:
if (entity.getBoilerTemp().isPresent()) {
Unit<Temperature> unit = entity.getBoilerTempUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
? SIUnits.CELSIUS
: ImperialUnits.FAHRENHEIT;
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
state = new QuantityType<>(entity.getBoilerTemp().get(), unit);
}
break;
case APPLIANCE_DHWSETPOINT_CHANNEL:
if (entity.getDHTSetpoint().isPresent()) {
Unit<Temperature> unit = entity.getDHTSetpointUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
? SIUnits.CELSIUS
: ImperialUnits.FAHRENHEIT;
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
state = new QuantityType<>(entity.getDHTSetpoint().get(), unit);
}
break;
case APPLIANCE_MAXBOILERTEMPERATURE_CHANNEL:
if (entity.getMaxBoilerTemp().isPresent()) {
Unit<Temperature> unit = entity.getMaxBoilerTempUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
? SIUnits.CELSIUS
: ImperialUnits.FAHRENHEIT;
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
state = new QuantityType<>(entity.getMaxBoilerTemp().get(), unit);
}
break;

View File

@ -31,6 +31,7 @@ import org.openhab.binding.plugwiseha.internal.api.exception.PlugwiseHAException
import org.openhab.binding.plugwiseha.internal.api.model.PlugwiseHAController;
import org.openhab.binding.plugwiseha.internal.api.model.dto.Location;
import org.openhab.binding.plugwiseha.internal.config.PlugwiseHAThingConfig;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
@ -108,6 +109,11 @@ public class PlugwiseHAZoneHandler extends PlugwiseHABaseHandler<Location, Plugw
return controller.getLocation(config.getId());
}
private Unit<Temperature> getRemoteTemperatureUnit(Location entity) {
return UNIT_CELSIUS.equals(entity.getTemperatureUnit().orElse(UNIT_CELSIUS)) ? SIUnits.CELSIUS
: ImperialUnits.FAHRENHEIT;
}
@Override
protected void handleCommand(Location entity, ChannelUID channelUID, Command command) throws PlugwiseHAException {
String channelID = channelUID.getIdWithoutGroup();
@ -127,17 +133,19 @@ public class PlugwiseHAZoneHandler extends PlugwiseHABaseHandler<Location, Plugw
}
break;
case ZONE_SETPOINT_CHANNEL:
if (command instanceof QuantityType quantityCommand) {
Unit<Temperature> unit = entity.getSetpointTemperatureUnit().orElse(UNIT_CELSIUS)
.equals(UNIT_CELSIUS) ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT;
QuantityType<?> state = quantityCommand.toUnit(unit);
if (state != null) {
try {
controller.setLocationThermostat(entity, state.doubleValue());
} catch (PlugwiseHAException e) {
logger.warn("Unable to update setpoint for zone '{}': {} -> {}", entity.getName(),
entity.getSetpointTemperature().orElse(null), state.doubleValue());
}
Unit<Temperature> remoteUnit = getRemoteTemperatureUnit(entity);
QuantityType<?> state = null;
if (command instanceof QuantityType<?> quantityCommand) {
state = quantityCommand.toUnit(remoteUnit);
} else if (command instanceof DecimalType decimalCommand) {
state = new QuantityType<>(decimalCommand.doubleValue(), remoteUnit);
}
if (state != null) {
try {
controller.setLocationThermostat(entity, state.doubleValue());
} catch (PlugwiseHAException e) {
logger.warn("Unable to update setpoint for zone '{}': {} -> {}", entity.getName(),
entity.getSetpointTemperature().orElse(null), state.doubleValue());
}
}
break;
@ -216,8 +224,7 @@ public class PlugwiseHAZoneHandler extends PlugwiseHABaseHandler<Location, Plugw
break;
case ZONE_SETPOINT_CHANNEL:
if (entity.getSetpointTemperature().isPresent()) {
Unit<Temperature> unit = entity.getSetpointTemperatureUnit().orElse(UNIT_CELSIUS)
.equals(UNIT_CELSIUS) ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT;
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
state = new QuantityType<>(entity.getSetpointTemperature().get(), unit);
}
break;
@ -229,9 +236,7 @@ public class PlugwiseHAZoneHandler extends PlugwiseHABaseHandler<Location, Plugw
break;
case ZONE_TEMPERATURE_CHANNEL:
if (entity.getTemperature().isPresent()) {
Unit<Temperature> unit = entity.getTemperatureUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
? SIUnits.CELSIUS
: ImperialUnits.FAHRENHEIT;
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
state = new QuantityType<>(entity.getTemperature().get(), unit);
}
break;

View File

@ -23,11 +23,11 @@
<label>Smile ID</label>
<description>The Smile ID is the 8 letter code on the sticker on the back of the Adam boiler gateway</description>
</parameter>
<parameter name="refresh" type="integer" min="1" max="120" required="true" unit="s">
<parameter name="refresh" type="integer" min="3" max="300" required="true" unit="s">
<label>Refresh Interval</label>
<unitLabel>seconds</unitLabel>
<description>Refresh interval in seconds</description>
<default>5</default>
<default>15</default>
<advanced>true</advanced>
</parameter>
</config-description>