mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-02-04 19:34:05 +01:00
[plugwiseha] Improve connection stability (#17677)
* Improvements * Sync config with readme * Fix unit detection * Fix NPE Signed-off-by: Leo Siepel <leosiepel@gmail.com> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
cd2b85d2b9
commit
81fea618a4
@ -101,10 +101,13 @@ public class PlugwiseHAController {
|
|||||||
callback.run();
|
callback.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refreshes all changed objects. Will result in a call to the remote service.
|
||||||
|
*
|
||||||
|
* @throws PlugwiseHAException
|
||||||
|
*/
|
||||||
public void refresh() throws PlugwiseHAException {
|
public void refresh() throws PlugwiseHAException {
|
||||||
synchronized (this) {
|
domainObjects = this.getUpdatedDomainObjects();
|
||||||
this.getUpdatedDomainObjects();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public API methods
|
// Public API methods
|
||||||
@ -113,7 +116,7 @@ public class PlugwiseHAController {
|
|||||||
return getGatewayInfo(false);
|
return getGatewayInfo(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GatewayInfo getGatewayInfo(Boolean forceRefresh) throws PlugwiseHAException {
|
private synchronized GatewayInfo getGatewayInfo(Boolean forceRefresh) throws PlugwiseHAException {
|
||||||
GatewayInfo gatewayInfo = null;
|
GatewayInfo gatewayInfo = null;
|
||||||
DomainObjects localDomainObjects = this.domainObjects;
|
DomainObjects localDomainObjects = this.domainObjects;
|
||||||
if (localDomainObjects != null) {
|
if (localDomainObjects != null) {
|
||||||
@ -133,12 +136,12 @@ public class PlugwiseHAController {
|
|||||||
|
|
||||||
DomainObjects domainObjects = executeRequest(request);
|
DomainObjects domainObjects = executeRequest(request);
|
||||||
this.gatewayUpdateDateTime = ZonedDateTime.parse(request.getServerDateTime(), PlugwiseHAController.FORMAT);
|
this.gatewayUpdateDateTime = ZonedDateTime.parse(request.getServerDateTime(), PlugwiseHAController.FORMAT);
|
||||||
|
domainObjects = mergeDomainObjects(domainObjects);
|
||||||
return mergeDomainObjects(domainObjects).getGatewayInfo();
|
return domainObjects.getGatewayInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Appliances getAppliances(Boolean forceRefresh) throws PlugwiseHAException {
|
private synchronized Appliances getAppliances(Boolean forceRefresh) throws PlugwiseHAException {
|
||||||
Appliances appliances = null;
|
Appliances appliances = null;
|
||||||
DomainObjects localDomainObjects = this.domainObjects;
|
DomainObjects localDomainObjects = this.domainObjects;
|
||||||
if (localDomainObjects != null) {
|
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 {
|
public @Nullable Appliance getAppliance(String id) throws PlugwiseHAException {
|
||||||
Appliances appliances = this.getAppliances(false);
|
Appliances appliances = this.getAppliances(false);
|
||||||
if (!appliances.containsKey(id)) {
|
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;
|
Locations locations = null;
|
||||||
DomainObjects localDomainObjects = this.domainObjects;
|
DomainObjects localDomainObjects = this.domainObjects;
|
||||||
if (localDomainObjects != null) {
|
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 {
|
public @Nullable Location getLocation(String id) throws PlugwiseHAException {
|
||||||
Locations locations = this.getLocations(false);
|
Locations locations = this.getLocations(false);
|
||||||
if (!locations.containsKey(id)) {
|
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;
|
PlugwiseHAControllerRequest<DomainObjects> request;
|
||||||
|
|
||||||
request = newRequest(DomainObjects.class, this.domainObjectsTransformer);
|
request = newRequest(DomainObjects.class, this.domainObjectsTransformer);
|
||||||
@ -239,27 +262,24 @@ public class PlugwiseHAController {
|
|||||||
return mergeDomainObjects(domainObjects);
|
return mergeDomainObjects(domainObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable DomainObjects getUpdatedDomainObjects() throws PlugwiseHAException {
|
private @Nullable DomainObjects getUpdatedDomainObjects() throws PlugwiseHAException {
|
||||||
ZonedDateTime localGatewayUpdateDateTime = this.gatewayUpdateDateTime;
|
ZonedDateTime localGatewayUpdateDateTime = this.gatewayUpdateDateTime;
|
||||||
ZonedDateTime localGatewayFullUpdateDateTime = this.gatewayFullUpdateDateTime;
|
ZonedDateTime localGatewayFullUpdateDateTime = this.gatewayFullUpdateDateTime;
|
||||||
|
|
||||||
if (localGatewayUpdateDateTime == null || localGatewayFullUpdateDateTime == null) {
|
if (localGatewayUpdateDateTime == null || localGatewayFullUpdateDateTime == null) {
|
||||||
return getDomainObjects();
|
return getAndMergeDomainObjects();
|
||||||
} else if (localGatewayUpdateDateTime.isBefore(ZonedDateTime.now().minusSeconds(maxAgeSecondsRefresh))) {
|
} else if (localGatewayUpdateDateTime.isBefore(ZonedDateTime.now().minusSeconds(maxAgeSecondsRefresh))) {
|
||||||
return getUpdatedDomainObjects(localGatewayUpdateDateTime);
|
return getUpdatedAndMergeDomainObjects(localGatewayUpdateDateTime.toEpochSecond());
|
||||||
} else if (localGatewayFullUpdateDateTime
|
} else if (localGatewayFullUpdateDateTime
|
||||||
.isBefore(ZonedDateTime.now().minusMinutes(MAX_AGE_MINUTES_FULL_REFRESH))) {
|
.isBefore(ZonedDateTime.now().minusMinutes(MAX_AGE_MINUTES_FULL_REFRESH))) {
|
||||||
return getDomainObjects();
|
return getAndMergeDomainObjects();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable DomainObjects getUpdatedDomainObjects(ZonedDateTime since) throws PlugwiseHAException {
|
private synchronized @Nullable DomainObjects getUpdatedAndMergeDomainObjects(Long since)
|
||||||
return getUpdatedDomainObjects(since.toEpochSecond());
|
throws PlugwiseHAException {
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable DomainObjects getUpdatedDomainObjects(Long since) throws PlugwiseHAException {
|
|
||||||
PlugwiseHAControllerRequest<DomainObjects> request;
|
PlugwiseHAControllerRequest<DomainObjects> request;
|
||||||
|
|
||||||
request = newRequest(DomainObjects.class, this.domainObjectsTransformer);
|
request = newRequest(DomainObjects.class, this.domainObjectsTransformer);
|
||||||
@ -276,7 +296,7 @@ public class PlugwiseHAController {
|
|||||||
return mergeDomainObjects(domainObjects);
|
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);
|
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
|
||||||
Optional<ActuatorFunctionality> thermostat = location.getActuatorFunctionalities().getFunctionalityThermostat();
|
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);
|
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
|
||||||
Optional<ActuatorFunctionality> thermostat = appliance.getActuatorFunctionalities()
|
Optional<ActuatorFunctionality> thermostat = appliance.getActuatorFunctionalities()
|
||||||
.getFunctionalityThermostat();
|
.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);
|
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
|
||||||
Optional<ActuatorFunctionality> offsetTemperatureFunctionality = appliance.getActuatorFunctionalities()
|
Optional<ActuatorFunctionality> offsetTemperatureFunctionality = appliance.getActuatorFunctionalities()
|
||||||
.getFunctionalityOffsetTemperature();
|
.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);
|
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
|
||||||
Optional<ActuatorFunctionality> thermostat = location.getActuatorFunctionalities().getFunctionalityThermostat();
|
Optional<ActuatorFunctionality> thermostat = location.getActuatorFunctionalities().getFunctionalityThermostat();
|
||||||
|
|
||||||
@ -335,7 +355,7 @@ public class PlugwiseHAController {
|
|||||||
executeRequest(request);
|
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);
|
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
|
||||||
Optional<ActuatorFunctionality> thermostat = location.getActuatorFunctionalities().getFunctionalityThermostat();
|
Optional<ActuatorFunctionality> thermostat = location.getActuatorFunctionalities().getFunctionalityThermostat();
|
||||||
|
|
||||||
@ -347,7 +367,7 @@ public class PlugwiseHAController {
|
|||||||
executeRequest(request);
|
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");
|
List<String> allowStates = Arrays.asList("active", "passive", "off");
|
||||||
if (!allowStates.contains(state.toLowerCase())) {
|
if (!allowStates.contains(state.toLowerCase())) {
|
||||||
this.logger.warn("Trying to set the regulation control to an invalid state");
|
this.logger.warn("Trying to set the regulation control to an invalid state");
|
||||||
@ -365,7 +385,7 @@ public class PlugwiseHAController {
|
|||||||
executeRequest(request);
|
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);
|
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
|
||||||
|
|
||||||
request.setPath("/core/appliances");
|
request.setPath("/core/appliances");
|
||||||
@ -375,7 +395,7 @@ public class PlugwiseHAController {
|
|||||||
executeRequest(request);
|
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);
|
PlugwiseHAControllerRequest<Void> request = newRequest(Void.class);
|
||||||
|
|
||||||
request.setPath("/core/appliances");
|
request.setPath("/core/appliances");
|
||||||
@ -385,7 +405,7 @@ public class PlugwiseHAController {
|
|||||||
executeRequest(request);
|
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");
|
List<String> allowStates = Arrays.asList("home", "asleep", "away", "vacation", "no_frost");
|
||||||
if (!allowStates.contains(state.toLowerCase())) {
|
if (!allowStates.contains(state.toLowerCase())) {
|
||||||
this.logger.warn("Trying to set the preset scene to an invalid state");
|
this.logger.warn("Trying to set the preset scene to an invalid state");
|
||||||
@ -409,19 +429,6 @@ public class PlugwiseHAController {
|
|||||||
executeRequest(request);
|
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
|
// Protected and private methods
|
||||||
|
|
||||||
private static Transformer setXSLT(StreamSource xsltSource) throws PlugwiseHAException {
|
private static Transformer setXSLT(StreamSource xsltSource) throws PlugwiseHAException {
|
||||||
@ -444,16 +451,13 @@ public class PlugwiseHAController {
|
|||||||
|
|
||||||
@SuppressWarnings("null")
|
@SuppressWarnings("null")
|
||||||
private <T> T executeRequest(PlugwiseHAControllerRequest<T> request) throws PlugwiseHAException {
|
private <T> T executeRequest(PlugwiseHAControllerRequest<T> request) throws PlugwiseHAException {
|
||||||
T result;
|
return request.execute();
|
||||||
result = request.execute();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DomainObjects mergeDomainObjects(@Nullable DomainObjects updatedDomainObjects) {
|
private DomainObjects mergeDomainObjects(@Nullable DomainObjects updatedDomainObjects) {
|
||||||
DomainObjects localDomainObjects = this.domainObjects;
|
DomainObjects localDomainObjects = this.domainObjects;
|
||||||
if (localDomainObjects == null && updatedDomainObjects != null) {
|
if (localDomainObjects == null && updatedDomainObjects != null) {
|
||||||
this.domainObjects = updatedDomainObjects;
|
return this.domainObjects = updatedDomainObjects;
|
||||||
return updatedDomainObjects;
|
|
||||||
} else if (localDomainObjects != null && updatedDomainObjects == null) {
|
} else if (localDomainObjects != null && updatedDomainObjects == null) {
|
||||||
return localDomainObjects;
|
return localDomainObjects;
|
||||||
} else if (localDomainObjects != null && updatedDomainObjects != null) {
|
} else if (localDomainObjects != null && updatedDomainObjects != null) {
|
||||||
@ -467,7 +471,6 @@ public class PlugwiseHAController {
|
|||||||
if (locations != null) {
|
if (locations != null) {
|
||||||
localDomainObjects.mergeLocations(locations);
|
localDomainObjects.mergeLocations(locations);
|
||||||
}
|
}
|
||||||
this.domainObjects = localDomainObjects;
|
|
||||||
return localDomainObjects;
|
return localDomainObjects;
|
||||||
} else {
|
} else {
|
||||||
return new DomainObjects();
|
return new DomainObjects();
|
||||||
|
@ -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 String CONTENT_TYPE_TEXT_XML = MimeTypes.Type.TEXT_XML_8859_1.toString();
|
||||||
private static final long TIMEOUT_SECONDS = 5;
|
private static final long TIMEOUT_SECONDS = 5;
|
||||||
private static final int REQUEST_MAX_RETRY_COUNT = 3;
|
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 Logger logger = LoggerFactory.getLogger(PlugwiseHAControllerRequest.class);
|
||||||
private final XStream xStream;
|
private final XStream xStream;
|
||||||
@ -252,6 +253,12 @@ public class PlugwiseHAControllerRequest<T> {
|
|||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
if (retries > 0) {
|
if (retries > 0) {
|
||||||
this.logger.debug("TimeoutException occured, remaining retries {}", retries - 1);
|
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);
|
return getContentResponse(retries - 1);
|
||||||
} else {
|
} else {
|
||||||
throw new PlugwiseHATimeoutException(e);
|
throw new PlugwiseHATimeoutException(e);
|
||||||
|
@ -38,10 +38,7 @@ public class DateTimeConverter extends AbstractSingleValueConverter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canConvert(@Nullable @SuppressWarnings("rawtypes") Class type) {
|
public boolean canConvert(@Nullable @SuppressWarnings("rawtypes") Class type) {
|
||||||
if (type == null) {
|
return (type == null) ? false : ZonedDateTime.class.isAssignableFrom(type);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return ZonedDateTime.class.isAssignableFrom(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,15 +24,12 @@ public class ActuatorFunctionalityThermostat extends ActuatorFunctionality {
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private Double setpoint;
|
private Double setpoint;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@XStreamAlias("preheating_allowed")
|
@XStreamAlias("preheating_allowed")
|
||||||
private Boolean preheatingAllowed;
|
private Boolean preheatingAllowed;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@XStreamAlias("cooling_allowed")
|
@XStreamAlias("cooling_allowed")
|
||||||
private Boolean coolingAllowed;
|
private Boolean coolingAllowed;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@XStreamAlias("regulation_control")
|
@XStreamAlias("regulation_control")
|
||||||
private String regulationControl;
|
private String regulationControl;
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ public class DomainObjects {
|
|||||||
@XStreamImplicit(itemFieldName = "location", keyFieldName = "id")
|
@XStreamImplicit(itemFieldName = "location", keyFieldName = "id")
|
||||||
private Locations locations = new Locations();
|
private Locations locations = new Locations();
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@XStreamImplicit(itemFieldName = "module", keyFieldName = "id")
|
@XStreamImplicit(itemFieldName = "module", keyFieldName = "id")
|
||||||
private Modules modules = new Modules();
|
private Modules modules = new Modules();
|
||||||
|
|
||||||
@ -47,7 +46,9 @@ public class DomainObjects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Appliances mergeAppliances(Appliances updatedAppliances) {
|
public Appliances mergeAppliances(Appliances updatedAppliances) {
|
||||||
if (updatedAppliances != null) {
|
if (appliances == null) {
|
||||||
|
this.appliances = updatedAppliances;
|
||||||
|
} else if (updatedAppliances != null) {
|
||||||
this.appliances.merge(updatedAppliances);
|
this.appliances.merge(updatedAppliances);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +56,9 @@ public class DomainObjects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Locations mergeLocations(Locations updatedLocations) {
|
public Locations mergeLocations(Locations updatedLocations) {
|
||||||
if (updatedLocations != null) {
|
if (locations == null) {
|
||||||
|
this.locations = updatedLocations;
|
||||||
|
} else if (updatedLocations != null) {
|
||||||
this.locations.merge(updatedLocations);
|
this.locations.merge(updatedLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class Log extends PlugwiseBaseModel implements PlugwiseComparableDate<Log
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Optional<String> getMeasurementUnit() {
|
public Optional<String> getMeasurementUnit() {
|
||||||
return Optional.ofNullable(unit);
|
return Optional.ofNullable(unit != null && !unit.isBlank() ? unit : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZonedDateTime getMeasurementDate() {
|
public ZonedDateTime getMeasurementDate() {
|
||||||
|
@ -30,7 +30,6 @@ import com.thoughtworks.xstream.annotations.XStreamImplicit;
|
|||||||
@XStreamAlias("module")
|
@XStreamAlias("module")
|
||||||
public class Module extends PlugwiseBaseModel implements PlugwiseComparableDate<Module> {
|
public class Module extends PlugwiseBaseModel implements PlugwiseComparableDate<Module> {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@XStreamImplicit(itemFieldName = "service", keyFieldName = "id")
|
@XStreamImplicit(itemFieldName = "service", keyFieldName = "id")
|
||||||
private Services services;
|
private Services services;
|
||||||
|
|
||||||
|
@ -20,11 +20,9 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||||||
@XStreamAlias("service")
|
@XStreamAlias("service")
|
||||||
public class Service extends PlugwiseBaseModel {
|
public class Service extends PlugwiseBaseModel {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@XStreamAlias("log_type")
|
@XStreamAlias("log_type")
|
||||||
private String logType;
|
private String logType;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@XStreamAlias("point_log")
|
@XStreamAlias("point_log")
|
||||||
private String pointLogId;
|
private String pointLogId;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ public class PlugwiseHADiscoveryService extends AbstractThingHandlerDiscoverySer
|
|||||||
PlugwiseHAController controller = thingHandler.getController();
|
PlugwiseHAController controller = thingHandler.getController();
|
||||||
|
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
DomainObjects domainObjects = controller.getDomainObjects();
|
DomainObjects domainObjects = controller.getAndMergeDomainObjects();
|
||||||
|
|
||||||
if (domainObjects != null) {
|
if (domainObjects != null) {
|
||||||
for (Location location : domainObjects.getLocations().values()) {
|
for (Location location : domainObjects.getLocations().values()) {
|
||||||
|
@ -146,10 +146,8 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case APPLIANCE_OFFSET_CHANNEL:
|
case APPLIANCE_OFFSET_CHANNEL:
|
||||||
if (command instanceof QuantityType quantityCommand) {
|
if (command instanceof QuantityType<?> quantityCommand) {
|
||||||
Unit<Temperature> unit = entity.getOffsetTemperatureUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
? SIUnits.CELSIUS
|
|
||||||
: ImperialUnits.FAHRENHEIT;
|
|
||||||
QuantityType<?> state = quantityCommand.toUnit(unit);
|
QuantityType<?> state = quantityCommand.toUnit(unit);
|
||||||
|
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
@ -172,9 +170,8 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case APPLIANCE_SETPOINT_CHANNEL:
|
case APPLIANCE_SETPOINT_CHANNEL:
|
||||||
if (command instanceof QuantityType quantityCommand) {
|
if (command instanceof QuantityType<?> quantityCommand) {
|
||||||
Unit<Temperature> unit = entity.getSetpointTemperatureUnit().orElse(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
.equals(UNIT_CELSIUS) ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT;
|
|
||||||
QuantityType<?> state = quantityCommand.toUnit(unit);
|
QuantityType<?> state = quantityCommand.toUnit(unit);
|
||||||
|
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
@ -228,6 +225,11 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Unit<Temperature> getRemoteTemperatureUnit(Appliance entity) {
|
||||||
|
return UNIT_CELSIUS.equals(entity.getDHWTempUnit().orElse(UNIT_CELSIUS)) ? SIUnits.CELSIUS
|
||||||
|
: ImperialUnits.FAHRENHEIT;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void refreshChannel(Appliance entity, ChannelUID channelUID) {
|
protected void refreshChannel(Appliance entity, ChannelUID channelUID) {
|
||||||
String channelID = channelUID.getIdWithoutGroup();
|
String channelID = channelUID.getIdWithoutGroup();
|
||||||
@ -280,9 +282,7 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
|
|||||||
break;
|
break;
|
||||||
case APPLIANCE_OFFSET_CHANNEL:
|
case APPLIANCE_OFFSET_CHANNEL:
|
||||||
if (entity.getOffsetTemperature().isPresent()) {
|
if (entity.getOffsetTemperature().isPresent()) {
|
||||||
Unit<Temperature> unit = entity.getOffsetTemperatureUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
? SIUnits.CELSIUS
|
|
||||||
: ImperialUnits.FAHRENHEIT;
|
|
||||||
state = new QuantityType<>(entity.getOffsetTemperature().get(), unit);
|
state = new QuantityType<>(entity.getOffsetTemperature().get(), unit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -298,16 +298,13 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
|
|||||||
break;
|
break;
|
||||||
case APPLIANCE_SETPOINT_CHANNEL:
|
case APPLIANCE_SETPOINT_CHANNEL:
|
||||||
if (entity.getSetpointTemperature().isPresent()) {
|
if (entity.getSetpointTemperature().isPresent()) {
|
||||||
Unit<Temperature> unit = entity.getSetpointTemperatureUnit().orElse(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
.equals(UNIT_CELSIUS) ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT;
|
|
||||||
state = new QuantityType<>(entity.getSetpointTemperature().get(), unit);
|
state = new QuantityType<>(entity.getSetpointTemperature().get(), unit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case APPLIANCE_TEMPERATURE_CHANNEL:
|
case APPLIANCE_TEMPERATURE_CHANNEL:
|
||||||
if (entity.getTemperature().isPresent()) {
|
if (entity.getTemperature().isPresent()) {
|
||||||
Unit<Temperature> unit = entity.getTemperatureUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
? SIUnits.CELSIUS
|
|
||||||
: ImperialUnits.FAHRENHEIT;
|
|
||||||
state = new QuantityType<>(entity.getTemperature().get(), unit);
|
state = new QuantityType<>(entity.getTemperature().get(), unit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -330,8 +327,7 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
|
|||||||
break;
|
break;
|
||||||
case APPLIANCE_INTENDEDBOILERTEMP_CHANNEL:
|
case APPLIANCE_INTENDEDBOILERTEMP_CHANNEL:
|
||||||
if (entity.getIntendedBoilerTemp().isPresent()) {
|
if (entity.getIntendedBoilerTemp().isPresent()) {
|
||||||
Unit<Temperature> unit = entity.getIntendedBoilerTempUnit().orElse(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
.equals(UNIT_CELSIUS) ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT;
|
|
||||||
state = new QuantityType<>(entity.getIntendedBoilerTemp().get(), unit);
|
state = new QuantityType<>(entity.getIntendedBoilerTemp().get(), unit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -358,17 +354,13 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
|
|||||||
break;
|
break;
|
||||||
case APPLIANCE_RETURNWATERTEMPERATURE_CHANNEL:
|
case APPLIANCE_RETURNWATERTEMPERATURE_CHANNEL:
|
||||||
if (entity.getBoilerTemp().isPresent()) {
|
if (entity.getBoilerTemp().isPresent()) {
|
||||||
Unit<Temperature> unit = entity.getReturnWaterTempUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
? SIUnits.CELSIUS
|
|
||||||
: ImperialUnits.FAHRENHEIT;
|
|
||||||
state = new QuantityType<>(entity.getReturnWaterTemp().get(), unit);
|
state = new QuantityType<>(entity.getReturnWaterTemp().get(), unit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case APPLIANCE_DHWTEMPERATURE_CHANNEL:
|
case APPLIANCE_DHWTEMPERATURE_CHANNEL:
|
||||||
if (entity.getDHWTemp().isPresent()) {
|
if (entity.getDHWTemp().isPresent()) {
|
||||||
Unit<Temperature> unit = entity.getDHWTempUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
? SIUnits.CELSIUS
|
|
||||||
: ImperialUnits.FAHRENHEIT;
|
|
||||||
state = new QuantityType<>(entity.getDHWTemp().get(), unit);
|
state = new QuantityType<>(entity.getDHWTemp().get(), unit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -379,25 +371,19 @@ public class PlugwiseHAApplianceHandler extends PlugwiseHABaseHandler<Appliance,
|
|||||||
break;
|
break;
|
||||||
case APPLIANCE_BOILERTEMPERATURE_CHANNEL:
|
case APPLIANCE_BOILERTEMPERATURE_CHANNEL:
|
||||||
if (entity.getBoilerTemp().isPresent()) {
|
if (entity.getBoilerTemp().isPresent()) {
|
||||||
Unit<Temperature> unit = entity.getBoilerTempUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
? SIUnits.CELSIUS
|
|
||||||
: ImperialUnits.FAHRENHEIT;
|
|
||||||
state = new QuantityType<>(entity.getBoilerTemp().get(), unit);
|
state = new QuantityType<>(entity.getBoilerTemp().get(), unit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case APPLIANCE_DHWSETPOINT_CHANNEL:
|
case APPLIANCE_DHWSETPOINT_CHANNEL:
|
||||||
if (entity.getDHTSetpoint().isPresent()) {
|
if (entity.getDHTSetpoint().isPresent()) {
|
||||||
Unit<Temperature> unit = entity.getDHTSetpointUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
? SIUnits.CELSIUS
|
|
||||||
: ImperialUnits.FAHRENHEIT;
|
|
||||||
state = new QuantityType<>(entity.getDHTSetpoint().get(), unit);
|
state = new QuantityType<>(entity.getDHTSetpoint().get(), unit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case APPLIANCE_MAXBOILERTEMPERATURE_CHANNEL:
|
case APPLIANCE_MAXBOILERTEMPERATURE_CHANNEL:
|
||||||
if (entity.getMaxBoilerTemp().isPresent()) {
|
if (entity.getMaxBoilerTemp().isPresent()) {
|
||||||
Unit<Temperature> unit = entity.getMaxBoilerTempUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
? SIUnits.CELSIUS
|
|
||||||
: ImperialUnits.FAHRENHEIT;
|
|
||||||
state = new QuantityType<>(entity.getMaxBoilerTemp().get(), unit);
|
state = new QuantityType<>(entity.getMaxBoilerTemp().get(), unit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -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.PlugwiseHAController;
|
||||||
import org.openhab.binding.plugwiseha.internal.api.model.dto.Location;
|
import org.openhab.binding.plugwiseha.internal.api.model.dto.Location;
|
||||||
import org.openhab.binding.plugwiseha.internal.config.PlugwiseHAThingConfig;
|
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.OnOffType;
|
||||||
import org.openhab.core.library.types.QuantityType;
|
import org.openhab.core.library.types.QuantityType;
|
||||||
import org.openhab.core.library.types.StringType;
|
import org.openhab.core.library.types.StringType;
|
||||||
@ -108,6 +109,11 @@ public class PlugwiseHAZoneHandler extends PlugwiseHABaseHandler<Location, Plugw
|
|||||||
return controller.getLocation(config.getId());
|
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
|
@Override
|
||||||
protected void handleCommand(Location entity, ChannelUID channelUID, Command command) throws PlugwiseHAException {
|
protected void handleCommand(Location entity, ChannelUID channelUID, Command command) throws PlugwiseHAException {
|
||||||
String channelID = channelUID.getIdWithoutGroup();
|
String channelID = channelUID.getIdWithoutGroup();
|
||||||
@ -127,10 +133,13 @@ public class PlugwiseHAZoneHandler extends PlugwiseHABaseHandler<Location, Plugw
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ZONE_SETPOINT_CHANNEL:
|
case ZONE_SETPOINT_CHANNEL:
|
||||||
if (command instanceof QuantityType quantityCommand) {
|
Unit<Temperature> remoteUnit = getRemoteTemperatureUnit(entity);
|
||||||
Unit<Temperature> unit = entity.getSetpointTemperatureUnit().orElse(UNIT_CELSIUS)
|
QuantityType<?> state = null;
|
||||||
.equals(UNIT_CELSIUS) ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT;
|
if (command instanceof QuantityType<?> quantityCommand) {
|
||||||
QuantityType<?> state = quantityCommand.toUnit(unit);
|
state = quantityCommand.toUnit(remoteUnit);
|
||||||
|
} else if (command instanceof DecimalType decimalCommand) {
|
||||||
|
state = new QuantityType<>(decimalCommand.doubleValue(), remoteUnit);
|
||||||
|
}
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
try {
|
try {
|
||||||
controller.setLocationThermostat(entity, state.doubleValue());
|
controller.setLocationThermostat(entity, state.doubleValue());
|
||||||
@ -139,7 +148,6 @@ public class PlugwiseHAZoneHandler extends PlugwiseHABaseHandler<Location, Plugw
|
|||||||
entity.getSetpointTemperature().orElse(null), state.doubleValue());
|
entity.getSetpointTemperature().orElse(null), state.doubleValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ZONE_PREHEAT_CHANNEL:
|
case ZONE_PREHEAT_CHANNEL:
|
||||||
if (command instanceof OnOffType onOffCommand) {
|
if (command instanceof OnOffType onOffCommand) {
|
||||||
@ -216,8 +224,7 @@ public class PlugwiseHAZoneHandler extends PlugwiseHABaseHandler<Location, Plugw
|
|||||||
break;
|
break;
|
||||||
case ZONE_SETPOINT_CHANNEL:
|
case ZONE_SETPOINT_CHANNEL:
|
||||||
if (entity.getSetpointTemperature().isPresent()) {
|
if (entity.getSetpointTemperature().isPresent()) {
|
||||||
Unit<Temperature> unit = entity.getSetpointTemperatureUnit().orElse(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
.equals(UNIT_CELSIUS) ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT;
|
|
||||||
state = new QuantityType<>(entity.getSetpointTemperature().get(), unit);
|
state = new QuantityType<>(entity.getSetpointTemperature().get(), unit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -229,9 +236,7 @@ public class PlugwiseHAZoneHandler extends PlugwiseHABaseHandler<Location, Plugw
|
|||||||
break;
|
break;
|
||||||
case ZONE_TEMPERATURE_CHANNEL:
|
case ZONE_TEMPERATURE_CHANNEL:
|
||||||
if (entity.getTemperature().isPresent()) {
|
if (entity.getTemperature().isPresent()) {
|
||||||
Unit<Temperature> unit = entity.getTemperatureUnit().orElse(UNIT_CELSIUS).equals(UNIT_CELSIUS)
|
Unit<Temperature> unit = getRemoteTemperatureUnit(entity);
|
||||||
? SIUnits.CELSIUS
|
|
||||||
: ImperialUnits.FAHRENHEIT;
|
|
||||||
state = new QuantityType<>(entity.getTemperature().get(), unit);
|
state = new QuantityType<>(entity.getTemperature().get(), unit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -23,11 +23,11 @@
|
|||||||
<label>Smile ID</label>
|
<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>
|
<description>The Smile ID is the 8 letter code on the sticker on the back of the Adam boiler gateway</description>
|
||||||
</parameter>
|
</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>
|
<label>Refresh Interval</label>
|
||||||
<unitLabel>seconds</unitLabel>
|
<unitLabel>seconds</unitLabel>
|
||||||
<description>Refresh interval in seconds</description>
|
<description>Refresh interval in seconds</description>
|
||||||
<default>5</default>
|
<default>15</default>
|
||||||
<advanced>true</advanced>
|
<advanced>true</advanced>
|
||||||
</parameter>
|
</parameter>
|
||||||
</config-description>
|
</config-description>
|
||||||
|
Loading…
Reference in New Issue
Block a user