diff --git a/bundles/binding/org.openhab.binding.autelis/.classpath b/bundles/binding/org.openhab.binding.autelis/.classpath new file mode 100644 index 00000000000..6d224cd3d0d --- /dev/null +++ b/bundles/binding/org.openhab.binding.autelis/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/bundles/binding/org.openhab.binding.autelis/.project b/bundles/binding/org.openhab.binding.autelis/.project new file mode 100644 index 00000000000..36b6630a518 --- /dev/null +++ b/bundles/binding/org.openhab.binding.autelis/.project @@ -0,0 +1,33 @@ + + + org.openhab.binding.autelis + This is the autelis binding of the open Home Automation Bus (openHAB) + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/bundles/binding/org.openhab.binding.autelis/META-INF/MANIFEST.MF b/bundles/binding/org.openhab.binding.autelis/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..a19632638e3 --- /dev/null +++ b/bundles/binding/org.openhab.binding.autelis/META-INF/MANIFEST.MF @@ -0,0 +1,28 @@ +Manifest-Version: 1.0 +Private-Package: org.openhab.binding.autelis.internal +Ignore-Package: org.openhab.binding.autelis.internal +Bundle-License: http://www.eclipse.org/legal/epl-v10.html +Bundle-Name: openHAB Autelis Binding +Bundle-SymbolicName: org.openhab.binding.autelis +Bundle-Vendor: openHAB.org +Bundle-Version: 1.7.0.qualifier +Bundle-ManifestVersion: 2 +Bundle-Description: This is the Autelis binding of the open Home Aut + omation Bus (openHAB) +Import-Package: org.apache.commons.lang, + org.openhab.core.binding, + org.openhab.core.events, + org.openhab.core.items, + org.openhab.core.library.items, + org.openhab.core.library.types, + org.openhab.core.types, + org.openhab.io.net.http, + org.openhab.model.item.binding, + org.osgi.framework, + org.osgi.service.component, + org.osgi.service.event, + org.slf4j +Bundle-DocURL: http://www.openhab.org +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Service-Component: OSGI-INF/binding.xml, OSGI-INF/genericbindingprovider.xml +Bundle-ClassPath: . diff --git a/bundles/binding/org.openhab.binding.autelis/OSGI-INF/binding.xml b/bundles/binding/org.openhab.binding.autelis/OSGI-INF/binding.xml new file mode 100644 index 00000000000..39c5ac14230 --- /dev/null +++ b/bundles/binding/org.openhab.binding.autelis/OSGI-INF/binding.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + diff --git a/bundles/binding/org.openhab.binding.autelis/OSGI-INF/genericbindingprovider.xml b/bundles/binding/org.openhab.binding.autelis/OSGI-INF/genericbindingprovider.xml new file mode 100644 index 00000000000..f7a24ace12a --- /dev/null +++ b/bundles/binding/org.openhab.binding.autelis/OSGI-INF/genericbindingprovider.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + diff --git a/bundles/binding/org.openhab.binding.autelis/README.md b/bundles/binding/org.openhab.binding.autelis/README.md new file mode 100644 index 00000000000..653e4136c03 --- /dev/null +++ b/bundles/binding/org.openhab.binding.autelis/README.md @@ -0,0 +1,158 @@ +## Introduction + +This is a OpenHab binding for Autelis pool controllers + +Autelis manufactures a network enabled pool interface for many popular pool systems. See [the Autelis webiste](http://www.autelis.com) and the [Autelis Command Protocol](http://www.autelis.com/wiki/index.php?title=Pool_Control_(PI)_HTTP_Command_Reference) for more information. + +The binding is fairly complete and supports the following functionality. + +* Read circuit, auxiliary, temperature, pump, chemistry and system values +* Control circuit, auxiliary lighting scenes, and temperature set points + +## Installation + +Copy the binding jar (org.openhab.autelis*.jar) to the addons directory + +add the following to your openhab.cfg and comment out the relevant options +``` +############################### Autelis Pool Control Binding ######################### +# +# Host (name or ip) to connect to +# optional port (default 80) +# optional username and password (no default) +# optional refresh rate in millis (default 5000) +# +#autelis:refresh=5000 +#autelis:host=poolcontrol +#autelis:port=80 +#autelis:username=admin +#autelis:password=admin +``` + +## Items + +format is +`{autelis:"parentNode.childElement"}` +or +`{autelis:"lightscmd"}` + +An example to get the system version would be: + +`{autelis="system.version"}` + +* only 'equipment.*', 'temp.*' and 'lightscmd' items can be updated from openhab, everything else is read only. +* For lighting commands the following strings can be sent to a item configured with "{autels:"lightscmd"}" (through a mapped push button for example) + * 'alloff, allon, csync, cset, cswim, party, romance, caribbean, american, sunset, royalty, blue, green, red, white, magenta, hold, recall` + +The following are a listing of possible values for the configuration string using a sample xml output from a Autelis controller: + +```xml + + 50 + 13 + 20 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1.4.4 + + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + 1 + 1 + 0 + 71 + 101 + 60 + 60 + 55 + F + 0 + + + 0,0,0 + + + + + + + + + + 1 + 50 + 0 + 58 + 0 + 0 + Intellichlor--40 + +``` + +## More Item Examples + +``` +String PoolVersion "Version [%s]" {autelis="system.version"} + +Number PoolSetPoint "Pool SetPoint [%d]" {autelis="temp.poolsp"} + +Number PoolTemp "Pool Temp [%d]" {autelis="temp.pooltemp"} + +Number PoolSpaTemp "Spa Temp [%d]" {autelis="temp.spatemp"} + +Number PoolAirTemp "Air Temp [%d]" {autelis="temp.airtemp"} + +Number PoolSpaSetPoint "Spa SetPoint [%d]" {autelis="temp.spasp"} + +Number PoolChemSalt "Salt Levels [%d]" {autelis="chlor.salt"} + +Switch PoolSpaMode "Spa Mode [%s]" {autelis="equipment.circuit1"} + +Switch PoolMode "Pool Mode [%s]" {autelis="equipment.circuit6"} + +Switch PoolWaterfall "Waterfall [%s]" {autelis="equipment.circuit2"} + +Switch PoolSpaLight "Spa Light [%s]" {autelis="equipment.circuit3"} + +Switch PoolLight "Pool Light [%s]" {autelis="equipment.circuit4"} + +String PoolLightCmd {autelis="lightscmd"} +``` + diff --git a/bundles/binding/org.openhab.binding.autelis/build.properties b/bundles/binding/org.openhab.binding.autelis/build.properties new file mode 100644 index 00000000000..30f33af0ad2 --- /dev/null +++ b/bundles/binding/org.openhab.binding.autelis/build.properties @@ -0,0 +1,6 @@ +source.. = src/main/java/,\ + src/main/resources/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/ +output.. = target/classes/ diff --git a/bundles/binding/org.openhab.binding.autelis/pom.xml b/bundles/binding/org.openhab.binding.autelis/pom.xml new file mode 100644 index 00000000000..4f2968ca3e8 --- /dev/null +++ b/bundles/binding/org.openhab.binding.autelis/pom.xml @@ -0,0 +1,35 @@ + + + + + org.openhab.bundles + binding + 1.7.0-SNAPSHOT + + + + org.openhab.binding.autelis + org.openhab.binding.autelis + openhab-addon-binding-Autelis + openhab addon binding Autelis + + + 4.0.0 + org.openhab.binding + org.openhab.binding.autelis + + openHAB Autelis Binding + + eclipse-plugin + + + + + org.vafer + jdeb + + + + + diff --git a/bundles/binding/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/AutelisBindingProvider.java b/bundles/binding/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/AutelisBindingProvider.java new file mode 100644 index 00000000000..239ca265420 --- /dev/null +++ b/bundles/binding/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/AutelisBindingProvider.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2010-2015, openHAB.org and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.autelis; + +import org.openhab.core.binding.BindingProvider; +import org.openhab.core.items.Item; + +/** + * + * Provides a mapping between openHAB {@link Item}s and a Autelis Pool controller. + * @author Dan Cunningham + * @since 1.7.0 + */ +public interface AutelisBindingProvider extends BindingProvider { + + /** + * Returns an {@link Item} for a given item name + * @param itemName + * @return {@link Item} for the given item name + */ + public Item getItem(String itemName); + + /** + * Returns the binding configuration for an item as a {@link String} + * @param itemName + * @return {@link String} + */ + public String getAutelisBindingConfigString(String itemName); +} diff --git a/bundles/binding/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/internal/AutelisBinding.java b/bundles/binding/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/internal/AutelisBinding.java new file mode 100644 index 00000000000..cdc6fffcb7d --- /dev/null +++ b/bundles/binding/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/internal/AutelisBinding.java @@ -0,0 +1,438 @@ +/** + * Copyright (c) 2010-2015, openHAB.org and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.autelis.internal; + +import java.io.StringReader; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.openhab.binding.autelis.AutelisBindingProvider; +import org.apache.commons.lang.StringUtils; +import org.openhab.core.binding.AbstractActiveBinding; +import org.openhab.core.items.Item; +import org.openhab.core.library.items.NumberItem; +import org.openhab.core.library.items.SwitchItem; +import org.openhab.core.library.types.DecimalType; +import org.openhab.core.library.types.IncreaseDecreaseType; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.StringType; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; +import org.openhab.io.net.http.HttpUtil; +import org.osgi.framework.BundleContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.InputSource; + + +/** + * Autelis Pool Control Binding + * + * Autelis controllers allow remote access to many common pool systems. This + * binding allows openHAB to both monitor and control a pool system through these + * controllers. + * + * @see http://autelis.com + * + * @author Dan Cunningham + * @since 1.7.0 + */ +public class AutelisBinding extends AbstractActiveBinding { + + private static final Logger logger = + LoggerFactory.getLogger(AutelisBinding.class); + + /** + * Default port to use for connections to a Autelis controller + */ + static final int DEFAULT_PORT=80; + + /** + * Default timeout for http connections to a Autelis controller + */ + static final int TIMEOUT=5000; + + + /** + * Dim command for lights + */ + static final String AUTELIS_CMD_DIM = "dim"; + + /** + * UP command + */ + static final String AUTELIS_CMD_UP = "up"; + + /** + * Down Command + */ + static final String AUTELIS_CMD_DOWN = "down"; + + /** + * Value command + */ + static final String AUTELIS_CMD_VALUE = "value"; + + /** + * Value command + */ + static final String AUTELIS_CMD_HEAT = "hval"; + + /** + * Equipment status type + */ + static final String AUTELIS_TYPES_EQUIP = "equipment"; + + /** + * General status type + */ + static final String AUTELIS_TYPES_STATUS = "status"; + + /** + * Temperature status type + */ + static final String AUTELIS_TYPES_TEMP = "temp"; + + /** + * Lights type + */ + static final String AUTELIS_TYPES_LIGHTS = "lightscmd"; + + /** + * Chemistry status type + */ + static final String AUTELIS_TYPES_CHEMISTRY = "chem"; + + /** + * Pumps status type. + */ + static final String AUTELIS_TYPES_PUMPS = "pumps"; + + /** + * Setpoint + */ + static final String AUTELIS_SETPOINT = "sp"; + + /** + * Heat point ? + */ + static final String AUTELIS_HEATPOINT = "hp"; + + /** + * Heat type? + */ + static final String AUTELIS_HEATTYPE = "ht"; + + /** + * Constructed URL consisting of host, port, username and password use to connect to a Autelis controller + */ + private String baseURL; + + /** + * Regex expression to match XML responses from the Autelis, this is used to combine similar XML docs + * into a single document, {@link XPath} is still used for XML querying + */ + private Pattern responsePattern = Pattern.compile("(.+?)", Pattern.DOTALL); + + /** + * Commands can only be sent on equipment and temp configurations + */ + private Pattern commandPattern = Pattern.compile("^(equipment|temp)\\.(.*)"); + + /** + * Autelis controllers will not update their XML immediately after we change a value. To compensate + * we cache previous values for a {@link Item} using the item name as a key. After a polling + * run has been executed we only update an item if the value is different then what's in the + * cache. This cache is cleared after a fixed time period when commands are sent. + */ + private Map stateMap = Collections.synchronizedMap(new HashMap()); + + /** + * Clear our state every hour + */ + private static int NORMAL_CLEARTIME = 60 * 60; //one hour + + /** + * Clear state after an command is sent + */ + private static int UPDATE_CLEARTIME = 60 * 2; //two minutes + + /** + * Holds the next clear time in millis + */ + private long clearTime; + + /** + * the refresh interval which is used to poll values from the Autelis + * device (optional, defaults to 5000ms) + */ + private long refreshInterval = 5000; + + public AutelisBinding() { + logger.debug("Autelius binding started"); + } + + /** + * Called by the SCR to activate the component with its configuration read from CAS + * + * @param bundleContext BundleContext of the Bundle that defines this component + * @param configuration Configuration properties for this component obtained from the ConfigAdmin service + */ + public void activate(final BundleContext bundleContext, final Map configuration) { + configureBinding(configuration); + } + + /** + * Called by the SCR when the configuration of a binding has been changed through the ConfigAdmin service. + * @param configuration Updated configuration properties + */ + public void modified(final Map configuration) { + configureBinding(configuration); + } + + /** + * Configures binding for both bundle activation and modification. + * @param configuration + */ + private void configureBinding(final Map configuration){ + String refreshIntervalString = (String) configuration.get("refresh"); + if (StringUtils.isNotBlank(refreshIntervalString)) { + refreshInterval = Long.parseLong(refreshIntervalString); + } + + int port = DEFAULT_PORT; + String host = (String) configuration.get("host"); + String username = (String) configuration.get("username"); + String password = (String) configuration.get("password"); + + if(StringUtils.isBlank(host)){ + logger.error("Host config parameter is missing"); + setProperlyConfigured(false); + return; + } + + String portString = (String) configuration.get("port"); + if(StringUtils.isNotBlank(portString)) + port = Integer.parseInt(portString); + + String prefix = ""; + if(username != null) { + prefix = username + ":" + password + "@"; + } + + baseURL = "http://" + prefix + host + ":" + port; + + logger.debug("Autelius binding configured for host {}", host); + + setProperlyConfigured(true); + } + + /** + * @{inheritDoc} + */ + @Override + protected long getRefreshInterval() { + return refreshInterval; + } + + /** + * @{inheritDoc} + */ + @Override + protected String getName() { + return "autelis"; + } + + /** + * @{inheritDoc} + */ + @Override + protected void execute() { + logger.trace("Connecting to {}" + baseURL); + + clearState(); + + + String xmlDoc = fetchStateFromController(); + + if(xmlDoc == null) + return; + + for (AutelisBindingProvider provider : providers) { + for (String itemName : provider.getItemNames()) { + Item item = provider.getItem(itemName); + String config = provider.getAutelisBindingConfigString(itemName); + XPathFactory xpathFactory = XPathFactory.newInstance(); + XPath xpath = xpathFactory.newXPath(); + try { + InputSource is = new InputSource(new StringReader(xmlDoc)); + String value = xpath.evaluate("response/" + config.replace('.', '/'), is); + State state = toState(item.getClass(), value); + State oldState = stateMap.put(itemName, state); + if(!state.equals(oldState)){ + logger.debug("updating item {} with state {}", itemName, state); + eventPublisher.postUpdate(itemName, state); + } + } catch (XPathExpressionException e) { + logger.warn("could not parse xml",e); + } + + } + } + } + + /** + * @{inheritDoc} + */ + @Override + protected void internalReceiveCommand(String itemName, Command command) { + logger.trace("internalReceiveCommand({},{}) is called!", itemName, command); + for (AutelisBindingProvider provider : providers) { + Item item = provider.getItem(itemName); + String config = provider.getAutelisBindingConfigString(itemName); + Matcher m = commandPattern.matcher(config); + if (m.find() && m.groupCount() > 1) { + String type = m.group(1); + String name = m.group(2); + if(type.equals(AUTELIS_TYPES_EQUIP)){ + String cmd = AUTELIS_CMD_VALUE; + int value; + if(command == OnOffType.OFF){ + value = 0; + } else if(command == OnOffType.ON){ + value = 1; + } else if(command instanceof DecimalType){ + value = ((DecimalType)item.getStateAs(DecimalType.class)).intValue(); + if(value >= 3){ + //this is a dim type. not sure what 2 does + cmd = AUTELIS_CMD_DIM; + } + } else { + logger.error("Equipment commands must be of Decimal type not {}", command); + break; + } + String response = HttpUtil.executeUrl("GET", baseURL + "/set.cgi?name=" + name + "&" + cmd + "=" + value, TIMEOUT); + logger.trace("equipment set {} {} {} : result {}", name, cmd, value, response); + } else if(type.equals(AUTELIS_TYPES_TEMP)){ + String value; + if(command == IncreaseDecreaseType.INCREASE){ + value = AUTELIS_CMD_UP; + }else if(command == IncreaseDecreaseType.DECREASE){ + value = AUTELIS_CMD_DOWN; + }else { + value = command.toString(); + } + + String cmd; + //name ending in sp are setpoints, ht are heat types? + if(name.endsWith(AUTELIS_SETPOINT)){ + cmd = AUTELIS_TYPES_TEMP; + } else if(name.endsWith(AUTELIS_HEATTYPE)){ + cmd = AUTELIS_CMD_HEAT; + } else { + logger.error("Unknown temp type {}", name); + break; + } + + String response = HttpUtil.executeUrl("GET", baseURL + "/set.cgi?wait=1&name=" + name + "&" + cmd + "=" + value, TIMEOUT); + logger.trace("temp set {} {} : result {}", cmd, value, response); + } + } else if(config.equals(AUTELIS_TYPES_LIGHTS)){ + /* + * lighting command + * possible values, but we will let anything through. + * alloff, allon, csync, cset, cswim, party, romance, caribbean, american, + * sunset, royalty, blue, green, red, white, magenta, hold, recall + */ + String response = HttpUtil.executeUrl("GET", baseURL + "lights.cgi?val=" + command.toString(), TIMEOUT); + logger.trace("lights set {} : result {}", command.toString(), response); + } else { + logger.error("Unsupported set config {}", config); + } + } + scheduleClearTime(UPDATE_CLEARTIME); + } + + /** + * Fetches the XML string from a Autelis controller. + * @return + */ + private String fetchStateFromController() { + // we will reconstruct the document with all the responses combined for + // XPATH + StringBuilder sb = new StringBuilder(""); + + // pull down the three xml documents + String[] statuses = { AUTELIS_TYPES_STATUS, AUTELIS_TYPES_CHEMISTRY, AUTELIS_TYPES_PUMPS }; + for (String status : statuses) { + String response = HttpUtil.executeUrl("GET", baseURL + "/" + status + + ".xml", TIMEOUT); + logger.trace(baseURL + "/" + status + ".xml \n {}", response); + if (response == null) { + logger.warn("No response from Autelis controller!"); + return null; + } + // get the xml data between the response tags and append to our main + // doc + Matcher m = responsePattern.matcher(response); + if (m.find()) { + sb.append(m.group(1)); + } + } + // finish our "new" XML Document + sb.append(""); + + /* + * This xmlDoc will now contain the three XML documents we retrieved + * wrapped in response tags for easier querying in XPath. + */ + return sb.toString(); + } + + /** + * Converts a {@link String} value to a {@link State} for a given {@link Item} + * @param itemType + * @param value + * @return {@link State} + */ + private State toState(Class itemType, String value) { + if (itemType.isAssignableFrom(NumberItem.class)) { + return new DecimalType(value); + } else if (itemType.isAssignableFrom(SwitchItem.class)) { + return Integer.parseInt(value) > 0 ? OnOffType.ON : OnOffType.OFF; + } else { + return StringType.valueOf(value); + } + } + + /** + * Clears our state if it is time + */ + private void clearState(){ + if(System.currentTimeMillis() >= clearTime){ + stateMap.clear(); + scheduleClearTime(NORMAL_CLEARTIME); + } + } + + /** + * Schedule when our next clear cycle will be + * @param secs + */ + private void scheduleClearTime(int secs){ + clearTime = System.currentTimeMillis() + (secs * 1000); + } +} diff --git a/bundles/binding/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/internal/AutelisGenericBindingProvider.java b/bundles/binding/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/internal/AutelisGenericBindingProvider.java new file mode 100644 index 00000000000..7a92dddfdd2 --- /dev/null +++ b/bundles/binding/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/internal/AutelisGenericBindingProvider.java @@ -0,0 +1,139 @@ +/** +w * Copyright (c) 2010-2015, openHAB.org and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.autelis.internal; + +import java.util.HashSet; +import java.util.Set; + +import org.openhab.binding.autelis.AutelisBindingProvider; +import org.openhab.core.binding.BindingConfig; +import org.openhab.core.items.Item; +import org.openhab.core.library.items.DimmerItem; +import org.openhab.core.library.items.NumberItem; +import org.openhab.core.library.items.StringItem; +import org.openhab.core.library.items.SwitchItem; +import org.openhab.model.item.binding.AbstractGenericBindingProvider; +import org.openhab.model.item.binding.BindingConfigParseException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Autelis Pool control binding configurations. + *

Sample configuration strings: + *

    + *
  • {autelis="system.version"}
  • + *
  • {autelis="temp.poolsp"}
  • + *
  • {autelis="temp.pooltemp"}
  • + *
  • {autelis="chlor.salt"}
  • + *
  • {autelis="equipment.circuit1"}
  • + *
  • {autelis="pumps.pump1"}
  • + *
  • {autelis="lightscmd"}
  • + *
+ *

only 'equipment.*', 'temp.*' and 'lightscmd' items can be updated from openhab, everything else is read only. + * + * @author Dan Cunningham + * @since 1.7.0 + */ +public class AutelisGenericBindingProvider extends AbstractGenericBindingProvider implements AutelisBindingProvider { + private static final Logger logger = + LoggerFactory.getLogger(AutelisGenericBindingProvider.class); + /** + * {@inheritDoc} + */ + public String getBindingType() { + return "autelis"; + } + + /** + * @{inheritDoc} + */ + @Override + public void validateItemType(Item item, String bindingConfig) throws BindingConfigParseException { + if (!(item instanceof SwitchItem || item instanceof DimmerItem || item instanceof NumberItem || item instanceof StringItem)) { + throw new BindingConfigParseException("item '" + item.getName() + + "' is of type '" + item.getClass().getSimpleName() + + "', only Switch, Dimmer, Number and String Items are allowed - please check your *.items configuration"); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException { + super.processBindingConfiguration(context, item, bindingConfig); + + + //read values must contain a '.' like equipment.circuit1 or be lightcmd + if(bindingConfig.indexOf('.') < 0 && !bindingConfig.equalsIgnoreCase("lightscmd")){ + logger.warn("Item {}'s configuration ({}) is not valid, please use the pattern 'parentType.childType' or lightscmd ", item.getName(), bindingConfig); + return; + } + + AutelisBindingConfig config = new AutelisBindingConfig(bindingConfig); + + addBindingConfig(item, config); + + Set items = contextMap.get(context); + if (items == null) { + items = new HashSet(); + contextMap.put(context, items); + } + items.add(item); + } + + /** + * {@inheritDoc} + */ + @Override + public Item getItem(String itemName) { + for (Set items : contextMap.values()) { + if (items != null) { + for (Item item : items) { + if (itemName.equals(item.getName())) { + return item; + } + } + } + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public String getAutelisBindingConfigString(String itemName){ + return ((AutelisBindingConfig) this.bindingConfigs.get(itemName)).getConfig(); + } + + /** + * Class to hold binding specific configuration details + * + * @author Dan Cunningham + * @since 1.7.0 + */ + public class AutelisBindingConfig implements BindingConfig { + String config; + + public AutelisBindingConfig(String config) { + super(); + this.config = config; + } + + public String getConfig() { + return config; + } + + public void setConfig(String config) { + this.config = config; + } + } +} diff --git a/bundles/binding/pom.xml b/bundles/binding/pom.xml index ead1bde2cb2..bf4402cf97b 100644 --- a/bundles/binding/pom.xml +++ b/bundles/binding/pom.xml @@ -141,6 +141,7 @@ org.openhab.binding.wago org.openhab.binding.networkupstools org.openhab.binding.ecobee + org.openhab.binding.autelis org.openhab.binding.nest org.openhab.binding.satel org.openhab.binding.harmonyhub diff --git a/distribution/openhabhome/configurations/openhab_default.cfg b/distribution/openhabhome/configurations/openhab_default.cfg index cc3d0d15f77..5fe145d5973 100644 --- a/distribution/openhabhome/configurations/openhab_default.cfg +++ b/distribution/openhabhome/configurations/openhab_default.cfg @@ -1724,6 +1724,19 @@ tcp:refreshinterval=250 # UPS server pass (optional) #networkupstools:ups1.pass= +############################### Autelis Pool Control Binding ######################### +# +# Host (name or ip) to connect to +# optional port (default 80) +# optional username and password (no default) +# optional refresh rate in millis (default 5000) +# +#autelis:refresh=5000 +#autelis:host=poolcontrol +#autelis:port=80 +#autelis:username=admin +#autelis:password=admin + ############################## Nest binding ######################################## # # Data refresh interval in ms (optional, defaults to 60000)