Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
[novelanheatpump] Add port config parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
watou committed Dec 29, 2015
1 parent d128f57 commit 8a680d0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
Expand Up @@ -15,7 +15,8 @@
import java.util.Dictionary;
import java.util.Iterator;

import org.apache.commons.lang.StringUtils;
import static org.apache.commons.lang.StringUtils.isNotBlank;
import static org.apache.commons.lang.StringUtils.isNumeric;
import org.openhab.binding.novelanheatpump.HeatPumpBindingProvider;
import org.openhab.binding.novelanheatpump.HeatpumpCommandType;
import org.openhab.binding.novelanheatpump.HeatpumpCoolingOperationMode;
Expand All @@ -38,12 +39,15 @@
* With the state array each binding will be updated.
*
* @author Jan-Philipp Bolle
* @author John Cocula -- made port configurable
* @since 1.0.0
*/
public class HeatPumpBinding extends AbstractActiveBinding<HeatPumpBindingProvider> implements ManagedService {

private static final Logger logger = LoggerFactory.getLogger(HeatPumpBinding.class);
private static final SimpleDateFormat sdateformat = new SimpleDateFormat("dd.MM.yy HH:mm"); //$NON-NLS-1$
private static final int DEFAULT_PORT = 8888;
private static final long DEFAULT_REFRESH_INTERVAL = 60000L;

/** Parameter code for heating operation mode */
public static int PARAM_HEATING_OPERATION_MODE = 3;
Expand All @@ -67,11 +71,13 @@ public class HeatPumpBinding extends AbstractActiveBinding<HeatPumpBindingProvid


/** Default refresh interval (currently 1 minute) */
private long refreshInterval = 60000L;
private long refreshInterval = DEFAULT_REFRESH_INTERVAL;

/* The IP address to connect to */
protected static String ip;


/* the port to connect to. */
protected static int port = DEFAULT_PORT;

public void deactivate() {
}
Expand All @@ -85,18 +91,32 @@ public void activate() {
@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
if (config != null) {
String ip = (String) config.get("ip"); //$NON-NLS-1$
if (StringUtils.isNotBlank(ip) && !ip.equals(HeatPumpBinding.ip)) {
// only do something if the ip has changed
HeatPumpBinding.ip = ip;
boolean properlyConfigured = true;

long refreshInterval = DEFAULT_REFRESH_INTERVAL;
int port = DEFAULT_PORT;
String ip = null;
try {
String refreshIntervalString = (String) config.get("refresh"); //$NON-NLS-1$
refreshInterval = isNotBlank(refreshIntervalString) ?
Long.parseLong(refreshIntervalString) : DEFAULT_REFRESH_INTERVAL;

String refreshIntervalString = (String) config.get("refresh");
if (StringUtils.isNotBlank(refreshIntervalString)) {
refreshInterval = Long.parseLong(refreshIntervalString);
}
ip = (String) config.get("ip"); //$NON-NLS-1$
properlyConfigured = properlyConfigured && isNotBlank(ip);

setProperlyConfigured(true);
String portString = (String) config.get("port"); //$NON-NLS-1$
port = isNumeric(portString) ? Integer.parseInt(portString) : DEFAULT_PORT;
}
catch (NumberFormatException ex) {
properlyConfigured = false;
}

if (properlyConfigured) {
this.refreshInterval = refreshInterval;
HeatPumpBinding.ip = ip;
HeatPumpBinding.port = port;
}
setProperlyConfigured(properlyConfigured);
}
}

Expand All @@ -109,7 +129,7 @@ public void execute() {
logger.debug("There is no existing Heatpump binding configuration => refresh cycle aborted!");
return;
}
HeatpumpConnector connector = new HeatpumpConnector(ip);
HeatpumpConnector connector = new HeatpumpConnector(ip, port);
try {
connector.connect();
// read all available values
Expand Down Expand Up @@ -478,7 +498,7 @@ protected void internalReceiveCommand(String itemName, Command command){
* @param value
*/
private boolean sendParamToHeatpump(int param, int value) {
HeatpumpConnector connector = new HeatpumpConnector(ip);
HeatpumpConnector connector = new HeatpumpConnector(ip, port);
try {
connector.connect();
return connector.setParam(param, value);
Expand Down
Expand Up @@ -24,6 +24,7 @@
* With the heatpump connector the internal state of a Novelan (Siemens) Heatpump can be read.
*
* @author Jan-Philipp Bolle
* @author John Cocula -- made port configurable
* @since 1.0.0
*/
public class HeatpumpConnector {
Expand All @@ -32,12 +33,13 @@ public class HeatpumpConnector {

private DataInputStream datain = null;
private DataOutputStream dataout = null;
private String serverIp = "";
private int serverPort = 8888;
private String serverIp;
private int serverPort;


public HeatpumpConnector(String serverIp){
public HeatpumpConnector(String serverIp, int serverPort) {
this.serverIp = serverIp;
this.serverPort = serverPort;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion distribution/openhabhome/configurations/openhab_default.cfg
Expand Up @@ -817,9 +817,12 @@ ntp:hostname=ptbtime1.ptb.de

######################## Novelan (Siemens) Heatpump Binding ###########################
#
# IP address of the Novelan (Siemens) Heatpump to connect to
# IP address of the Novelan (Siemens) Heatpump to connect to (required)
#novelanheatpump:ip=

# port number of the Novelan (Siemens) Heatpump to connect to (optional, defaults to 8888)
#novelanheatpump:port=

# refresh interval in milliseconds (optional, defaults to 60000)
#novelanheatpump:refresh=

Expand Down

0 comments on commit 8a680d0

Please sign in to comment.