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

introduced config option provider for serial ports #4568

Merged
merged 2 commits into from Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -52,7 +52,8 @@ class ConfigOptionRegistryOSGiTest extends OSGiTest {
oList1.add(parameterOption);

configOptionsProviderMock = [
getParameterOptions: {p1, p2, p3 -> oList1}
getParameterOptions: {p1, p2, p3, p4 ->
oList1}
] as ConfigOptionProvider

configDescriptionProviderMock = [
Expand Down
Expand Up @@ -210,7 +210,7 @@ private ConfigDescriptionParameter getConfigOptions(URI uri, ConfigDescriptionPa
boolean found = false;
for (ConfigOptionProvider configOptionProvider : this.configOptionProviders) {
Collection<ParameterOption> newOptions = configOptionProvider.getParameterOptions(uri, parameter.getName(),
locale);
parameter.getContext(), locale);

if (newOptions != null) {
found = true;
Expand Down
Expand Up @@ -16,19 +16,33 @@
* service to provide {@link ConfigDescription}s options.
*
* @author Chris Jackson - Initial contribution
* @author Kai Kreuzer - added support for contexts
*/
public interface ConfigOptionProvider {

/**
* Provides a collection of {@link ParameterOptions}s.
*
* @param uri
* the uri of the config description
* @param param
* the parameter name for which the requested options shall be returned
* @param locale
* locale
* @deprecated Use {@link getParameterOptions} with context instead.
*
* @param uri the uri of the config description
* @param param the parameter name for which the requested options shall be returned
* @param locale the locale in which the result is expected
* @return the configuration options provided by this provider if any or {@code null} otherwise
*/
@Deprecated
Collection<ParameterOption> getParameterOptions(URI uri, String param, Locale locale);

/**
* Provides a collection of {@link ParameterOptions}s.
*
* @param uri the uri of the config description
* @param param the parameter name for which the requested options shall be returned
* @param context the defined context of the parameter
* @param locale the locale in which the result is expected
* @return the configuration options provided by this provider if any or {@code null} otherwise
*/
default Collection<ParameterOption> getParameterOptions(URI uri, String param, String context, Locale locale) {
return getParameterOptions(uri, param, locale);
}
}
7 changes: 7 additions & 0 deletions bundles/config/org.eclipse.smarthome.config.serial/.classpath
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
33 changes: 33 additions & 0 deletions bundles/config/org.eclipse.smarthome.config.serial/.project
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.smarthome.config.serial</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,5 @@
#Fri Aug 06 15:20:42 CEST 2010
eclipse.preferences.version=1
pluginProject.equinox=false
pluginProject.extensions=false
resolve.requirebundle=false
@@ -0,0 +1,18 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Eclipse SmartHome Config Serial
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-SymbolicName: org.eclipse.smarthome.config.serial
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 0.9.0.qualifier
Import-Package:
gnu.io,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.config.core,
org.eclipse.smarthome.config.core.i18n,
org.eclipse.smarthome.core.common,
org.osgi.framework,
org.osgi.service.component,
org.osgi.service.component.annotations;resolution:=optional,
org.slf4j
Service-Component: OSGI-INF/*.xml
@@ -0,0 +1 @@
*.xml
29 changes: 29 additions & 0 deletions bundles/config/org.eclipse.smarthome.config.serial/about.html
@@ -0,0 +1,29 @@

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>About</title>
</head>
<body lang="EN-US">
<h2>About This Content</h2>

<p>&lt;<em>September 15, 2014</em>&gt;</p>
<h3>License</h3>

<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
indicated below, the Content is provided to you under the terms and conditions of the
Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>

<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
apply to your use of any object code in the Content. Check the Redistributor's license that was
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>

</body>
</html>
@@ -0,0 +1,6 @@
output.. = target/classes/
bin.includes = META-INF/,\
.,\
about.html,\
OSGI-INF/
source.. = src/main/java/
20 changes: 20 additions & 0 deletions bundles/config/org.eclipse.smarthome.config.serial/pom.xml
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<parent>
<groupId>org.eclipse.smarthome.bundles</groupId>
<artifactId>config</artifactId>
<version>0.9.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.smarthome.config</groupId>
<artifactId>org.eclipse.smarthome.config.serial</artifactId>

<name>Eclipse SmartHome Configuration Serial</name>

<packaging>eclipse-plugin</packaging>

</project>
@@ -0,0 +1,53 @@
/**
* Copyright (c) 2014-2017 by the respective copyright holders.
* 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.eclipse.smarthome.config.serial.internal;

import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;

import org.eclipse.smarthome.config.core.ConfigOptionProvider;
import org.eclipse.smarthome.config.core.ParameterOption;
import org.osgi.service.component.annotations.Component;

import gnu.io.CommPortIdentifier;

/**
* This service provides serial port names as options for configuration parameters.
*
* @author Kai Kreuzer - Initial contribution and API
*
*/
@Component
public class SerialConfigOptionProvider implements ConfigOptionProvider {

@Override
public Collection<ParameterOption> getParameterOptions(URI uri, String param, String context, Locale locale) {
List<ParameterOption> options = new ArrayList<>();
if ("serial-port".equals(context)) {
@SuppressWarnings("unchecked")
Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier id = portList.nextElement();
if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
options.add(new ParameterOption(id.getName(), id.getName()));
}
}
}
return options;
}

@Override
public Collection<ParameterOption> getParameterOptions(URI uri, String param, Locale locale) {
return null;
}

}
1 change: 1 addition & 0 deletions bundles/config/pom.xml
Expand Up @@ -24,6 +24,7 @@
<module>org.eclipse.smarthome.config.discovery.mdns</module>
<module>org.eclipse.smarthome.config.discovery.test</module>
<module>org.eclipse.smarthome.config.discovery.upnp</module>
<module>org.eclipse.smarthome.config.serial</module>
<module>org.eclipse.smarthome.config.xml</module>
<module>org.eclipse.smarthome.config.xml.test</module>
</modules>
Expand Down
6 changes: 3 additions & 3 deletions docs/documentation/development/bindings/xml-reference.md
Expand Up @@ -49,7 +49,7 @@ The following HTML tags are allowed -: ```<b>, <br>, <em>, <h1>, <h2>, <h3>, <h4
</parameter-group>

<parameter name="String" type="{text|integer|decimal|boolean}" min="Decimal" max="Decimal" step="Decimal" pattern="String" required="{true|false}" readOnly="{true|false}" multiple="{true|false}" groupName="String" unit="A|cd|K|kg|m|mol|s|g|rad|sr|Hz|N|Pa|J|W|C|V|F|Ω|S|Wb|T|H|Cel|lm|lx|Bq|Gy|Sv|kat|m/s2|m2v|m3|kph|%|l|ms|min|h|d|week|y">
<context>{network-address|password|password-create|color|date|datetime|email|month|week|dayOfWeek|time|tel|url|item|thing|group|tag|service|channel|rule|location}</context>
<context>{network-address|serial-port|password|password-create|color|date|datetime|email|month|week|dayOfWeek|time|tel|url|item|thing|group|tag|service|channel|rule|location}</context>
<required>{true|false}</required>
<default>String</default>
<label>String</label>
Expand Down Expand Up @@ -107,8 +107,8 @@ The following HTML tags are allowed -: ```<b>, <br>, <em>, <h1>, <h2>, <h3>, <h4
Context is used to provide some semantic details about the parameter. The UIs use it to render different kind of input widgets. The following contexts require a specific format of the content:

<table><tr><th>Name</th><th>Type</th><th>Format</th><th>Sample implementation</th></tr>
<tr><td>network-addess</td><td>text</td><td>IPv4,IPv6, domain name</td>
<td><code>&lt;input type="text"/></code></td></tr>
<tr><td>network-addess</td><td>text</td><td>IPv4,IPv6, domain name</td><td><code>&lt;input type="text"/></code></td></tr>
<tr><td>serial-port</td><td>text</td><td>Serial port name, e.g. COM1</td>custom input field</td></tr>
<tr><td>password</td><td>text</td><td>alphanumeric characters</td><td><code>&lt;input type="password"/></code></td></tr>
<tr><td>password-create</td><td>text</td><td>alphanumeric characters</td><td>custom password input</td></tr>
<tr><td>color</td><td>text</td><td>#000000 - #ffffff (hex color)</td><td><code>&lt;input type="color"/></code></td></tr>
Expand Down
11 changes: 11 additions & 0 deletions features/karaf/esh-core/src/main/feature/feature.xml
Expand Up @@ -211,6 +211,12 @@
<bundle>mvn:org.eclipse.smarthome.automation/org.eclipse.smarthome.automation.rest/${project.version}</bundle>
</feature>

<feature name="esh-config-serial" version="${project.version}">
<feature>esh-base</feature>
<feature>esh-io-transport-serial</feature>
<bundle>mvn:org.eclipse.smarthome.config/org.eclipse.smarthome.config.serial/${project.version}</bundle>
</feature>

<feature name="esh-io-console-karaf" description="Karaf Console support for SmartHome stuff" version="${project.version}">
<feature>esh-base</feature>
<feature>shell</feature>
Expand Down Expand Up @@ -287,6 +293,11 @@
<requirement>esh.tp;filter:="(feature=httpclient)"</requirement>
</feature>

<feature name="esh-io-transport-serial" version="${project.version}">
<feature>esh-base</feature>
<requirement>esh.tp;filter:="(feature=serial)"</requirement>
</feature>

<feature name="esh-io-transport-upnp" version="${project.version}">
<feature>esh-base</feature>
<requirement>esh.tp;filter:="(feature=jupnp)"</requirement>
Expand Down
7 changes: 7 additions & 0 deletions features/karaf/esh-tp/src/main/feature/feature.xml
Expand Up @@ -23,6 +23,7 @@
<feature dependency="true">esh-tp-jupnp</feature>
<feature dependency="true">esh-tp-jmdns</feature>
<feature dependency="true">esh-tp-paho</feature>
<feature dependency="true">esh-tp-serial</feature>
<feature dependency="true">esh-tp-xtext</feature>
<feature dependency="true">esh-tp-xtext-ide</feature>
<feature dependency="true">esh-tp-lsp4j</feature>
Expand Down Expand Up @@ -173,6 +174,12 @@
<bundle>mvn:org.eclipse.paho/org.eclipse.paho.client.mqttv3/1.0.2</bundle>
</feature>

<feature name="esh-tp-serial" version="${project.version}">
<capability>esh.tp;feature=serial;version=3.12.0</capability>

<bundle>mvn:org.openhab/nrjavaserial/3.12.0.OH</bundle>
</feature>

<feature name="esh-tp-xtext" description="Xtext - Language Engineering Made Easy" version="${project.version}">
<capability>esh.tp;feature=xtext;version=2.12.0</capability>

Expand Down
Expand Up @@ -173,6 +173,13 @@
version="0.0.0"
unpack="false"/>

<plugin
id="org.eclipse.smarthome.config.serial"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.eclipse.smarthome.core.binding.xml"
download-size="0"
Expand Down
6 changes: 5 additions & 1 deletion targetplatform/smarthome.target
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?><target name="SmartHome" sequenceNumber="119">
<?pde version="3.8"?><target name="SmartHome" sequenceNumber="120">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="com.google.inject" version="3.0.0.v201312141243"/>
Expand Down Expand Up @@ -186,6 +186,10 @@
<unit id="org.eclipse.jetty.xml" version="0.0.0"/>
<repository location="http://download.eclipse.org/jetty/updates/jetty-bundles-9.x/9.3.14.v20161028"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="nrjavaserial.feature.group" version="3.12.0"/>
<repository location="https://dl.bintray.com/openhab/p2/nrjavaserial/3.12.0/"/>
</location>
<location path="${project_loc:targetplatform}/third-party" type="Directory"/>
</locations>
</target>