mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 13:21:53 +01:00
Added maven archetype project to generate binding skeletons (#589)
This archetype generates bindings for the new bnd based build system. It also updates specific bundle files that need information about the new binding. This doesn't yet include generation of test projects. Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
This commit is contained in:
parent
bc91446ae1
commit
ff57db8396
2
pom.xml
2
pom.xml
@ -775,7 +775,7 @@ Import-Package: \\
|
||||
<module>demo</module>
|
||||
<module>bundles</module>
|
||||
<module>features</module>
|
||||
<!--<module>tools</module> -->
|
||||
<module>tools</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
17
tools/archetype/binding/.project
Normal file
17
tools/archetype/binding/.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.openhab.archetype.binding</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
59
tools/archetype/binding/pom.xml
Normal file
59
tools/archetype/binding/pom.xml
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.openhab.core</groupId>
|
||||
<artifactId>org.openhab.core.tools.archetypes</artifactId>
|
||||
<version>2.5.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>org.openhab.core.tools.archetypes.binding</artifactId>
|
||||
<packaging>maven-archetype</packaging>
|
||||
|
||||
<name>openHAB Core :: Tools :: Archetypes :: Binding</name>
|
||||
<description>This is the Maven-Archetype for building new bindings for openHAB.</description>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>archetype-resources/pom.xml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<filtering>false</filtering>
|
||||
<directory>src/main/resources</directory>
|
||||
<excludes>
|
||||
<exclude>archetype-resources/pom.xml</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-archetype-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<escapeString>@</escapeString>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>org.apache.maven.archetype</groupId>
|
||||
<artifactId>archetype-packaging</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,157 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2019 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
|
||||
nl = System.getProperty("line.separator")
|
||||
bundleName = request.getProperties().get('bindingIdCamelCase')
|
||||
githubUser = request.getProperties().get('githubUser')
|
||||
outputDirectory = new File(request.getOutputDirectory())
|
||||
|
||||
/**
|
||||
* Find which bundle the new binding should be added
|
||||
*/
|
||||
def String findAfterBundle(newBundle, codeownersFile) {
|
||||
def codeowners = codeownersFile.getText('UTF-8') + '/bundles/' + newBundle
|
||||
def lines = codeowners.split('\n').sort()
|
||||
def lastIndex
|
||||
|
||||
lines.eachWithIndex { line, index ->
|
||||
if (line.contains(newBundle)) {
|
||||
lastIndex = index-1
|
||||
}
|
||||
}
|
||||
return lines[lastIndex].replaceAll(/\/bundles\/([^\/]+)\/.+/, '$1')
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the new bundle to the CODEWONERS file
|
||||
*/
|
||||
def addUserToCodewoners(githubUser, codeownersFile, bundleAfter, newBundle) {
|
||||
def newContent = ''
|
||||
def lines = codeownersFile.eachLine { line, index ->
|
||||
newContent += line + nl
|
||||
if (line.contains(bundleAfter)) {
|
||||
newContent += '/bundles/' + newBundle + '/ @' + githubUser + nl
|
||||
}
|
||||
}
|
||||
codeownersFile.write(newContent)
|
||||
println 'Added github user to CODEOWNERS file'
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the new bundle to the addons bom pom.xml
|
||||
*/
|
||||
def addBundleToBom(bundleAfter, newBundle) {
|
||||
def bomDependency =
|
||||
''' <dependency>
|
||||
<groupId>org.openhab.addons.bundles</groupId>
|
||||
<artifactId>###</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
'''.replace('###', newBundle)
|
||||
def bomFile = new File(outputDirectory, '../bom/openhab-addons/pom.xml')
|
||||
def newContent = ''
|
||||
def insertIndex = 0;
|
||||
def lines = bomFile.eachLine { line, index ->
|
||||
newContent += line + nl
|
||||
if (line.contains(bundleAfter)) {
|
||||
insertIndex = index + 2
|
||||
}
|
||||
if (insertIndex > 0 && index == insertIndex) {
|
||||
newContent += bomDependency
|
||||
insertIndex = 0
|
||||
}
|
||||
}
|
||||
bomFile.write(newContent)
|
||||
println 'Added bundle to bom pom'
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the new bundle to the feature.xml
|
||||
*/
|
||||
def addBundleToFeature(bundleAfter, newBundle, bundleName) {
|
||||
def feature = '''
|
||||
<feature name="##1" description="##2 Binding" version="${project.version}">
|
||||
<feature>openhab-runtime-base</feature>
|
||||
<bundle start-level="80">mvn:org.openhab.addons.bundles/##3/${project.version}</bundle>
|
||||
</feature>
|
||||
'''.replace('##1', newBundle.replace('org.', '').replace('.', '-')).replace('##2', bundleName).replace('##3', newBundle)
|
||||
def bomFile = new File(outputDirectory, '../features/karaf/openhab-addons/src/main/feature/feature.xml')
|
||||
def newContent = ''
|
||||
def insertIndex = 0;
|
||||
def lines = bomFile.eachLine { line, index ->
|
||||
newContent += line + nl
|
||||
if (line.contains(bundleAfter) && line.contains('<bundle')) {
|
||||
insertIndex = index + 1
|
||||
}
|
||||
if (insertIndex > 0 && index == insertIndex) {
|
||||
newContent += feature
|
||||
insertIndex = 0
|
||||
}
|
||||
}
|
||||
bomFile.write(newContent)
|
||||
println 'Added bundle to feature.xml'
|
||||
}
|
||||
|
||||
//
|
||||
/**
|
||||
* Fix the bundle parent pom. The maven archytype adds the bundle, but add the end of the module list.
|
||||
* It also modifies the first and last line
|
||||
*/
|
||||
def fixBundlePom(bundleAfter, newBundle) {
|
||||
def bomFile = new File(outputDirectory, 'pom.xml')
|
||||
def module = ' <module>' + newBundle + '</module>'
|
||||
def newContent = ''
|
||||
def insertIndex = 0;
|
||||
def lines = bomFile.eachLine { line, index ->
|
||||
if (!line.contains(module)) {
|
||||
// filter out the already added module by the achetype
|
||||
newContent += line + nl
|
||||
}
|
||||
if (line.contains(bundleAfter)) {
|
||||
insertIndex = index
|
||||
}
|
||||
if (insertIndex > 0 && index == insertIndex) {
|
||||
newContent += module + nl
|
||||
insertIndex = 0
|
||||
}
|
||||
}
|
||||
bomFile.write(newContent)
|
||||
println 'Fix bundle parent pom.xml'
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Main
|
||||
def newBundle = request.getPackage()
|
||||
def codeownersFile = new File(outputDirectory, '../CODEOWNERS')
|
||||
|
||||
if (codeownersFile.exists()) {
|
||||
def bundleAfter = findAfterBundle(newBundle, codeownersFile)
|
||||
println 'Add new bundle after: ' + bundleAfter
|
||||
addUserToCodewoners(githubUser, codeownersFile, bundleAfter, newBundle)
|
||||
addBundleToBom(bundleAfter, newBundle)
|
||||
addBundleToFeature(bundleAfter, newBundle, bundleName)
|
||||
fixBundlePom(bundleAfter, newBundle)
|
||||
|
||||
println ''
|
||||
println '*********************************************'
|
||||
println ''
|
||||
println ' Start your new binding on a new git branch:'
|
||||
println ''
|
||||
println ' git checkout -b ' + bundleName.toLowerCase()
|
||||
println ''
|
||||
println '*********************************************'
|
||||
println ''
|
||||
} else {
|
||||
println 'Could not find the CODEOWNERS files to perform additional annotations: ' + codeownersFile
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
<archetype-descriptor xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
|
||||
name="openHAB Binding Archetype" partial="false">
|
||||
|
||||
<requiredProperties>
|
||||
<requiredProperty key="vendorName">
|
||||
<defaultValue>openHAB</defaultValue>
|
||||
</requiredProperty>
|
||||
<requiredProperty key="namespace">
|
||||
<defaultValue>org.openhab</defaultValue>
|
||||
</requiredProperty>
|
||||
<requiredProperty key="author">
|
||||
</requiredProperty>
|
||||
<requiredProperty key="githubUser">
|
||||
</requiredProperty>
|
||||
<requiredProperty key="bindingId">
|
||||
</requiredProperty>
|
||||
<requiredProperty key="bindingIdCamelCase">
|
||||
</requiredProperty>
|
||||
<requiredProperty key="startYear">
|
||||
<defaultValue>2010</defaultValue>
|
||||
</requiredProperty>
|
||||
</requiredProperties>
|
||||
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="false" encoding="UTF-8">
|
||||
<directory></directory>
|
||||
<includes>
|
||||
<include>NOTICE</include>
|
||||
<include>pom.xml</include>
|
||||
<include>.project</include>
|
||||
<include>.classpath</include>
|
||||
<include>README.md</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet filtered="true" packaged="false" encoding="UTF-8">
|
||||
<directory>src/main/resources/ESH-INF</directory>
|
||||
<includes>
|
||||
<include>**/*.*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<!-- Java files -->
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</archetype-descriptor>
|
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>${artifactId}</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,13 @@
|
||||
This content is produced and maintained by the openHAB project.
|
||||
|
||||
* Project home: https://www.openhab.org
|
||||
|
||||
== Declared Project Licenses
|
||||
|
||||
This program and the accompanying materials are made available under the terms
|
||||
of the Eclipse Public License 2.0 which is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/.
|
||||
|
||||
== Source Code
|
||||
|
||||
https://github.com/openhab/openhab-core
|
@ -0,0 +1,56 @@
|
||||
# ${bindingIdCamelCase} Binding
|
||||
|
||||
_Give some details about what this binding is meant for - a protocol, system, specific device._
|
||||
|
||||
_If possible, provide some resources like pictures, a YouTube video, etc. to give an impression of what can be done with this binding. You can place such resources into a `doc` folder next to this README.md._
|
||||
|
||||
#[[##]]# Supported Things
|
||||
|
||||
_Please describe the different supported things / devices within this section._
|
||||
_Which different types are supported, which models were tested etc.?_
|
||||
_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/ESH-INF/thing``` of your binding._
|
||||
|
||||
#[[##]]# Discovery
|
||||
|
||||
_Describe the available auto-discovery features here. Mention for what it works and what needs to be kept in mind when using it._
|
||||
|
||||
#[[##]]# Binding Configuration
|
||||
|
||||
_If your binding requires or supports general configuration settings, please create a folder ```cfg``` and place the configuration file ```<bindingId>.cfg``` inside it. In this section, you should link to this file and provide some information about the options. The file could e.g. look like:_
|
||||
|
||||
```
|
||||
# Configuration for the Philips Hue Binding
|
||||
#
|
||||
# Default secret key for the pairing of the Philips Hue Bridge.
|
||||
# It has to be between 10-40 (alphanumeric) characters
|
||||
# This may be changed by the user for security reasons.
|
||||
secret=openHABSecret
|
||||
```
|
||||
|
||||
_Note that it is planned to generate some part of this based on the information that is available within ```src/main/resources/ESH-INF/binding``` of your binding._
|
||||
|
||||
_If your binding does not offer any generic configurations, you can remove this section completely._
|
||||
|
||||
#[[##]]# Thing Configuration
|
||||
|
||||
_Describe what is needed to manually configure a thing, either through the (Paper) UI or via a thing-file. This should be mainly about its mandatory and optional configuration parameters. A short example entry for a thing file can help!_
|
||||
|
||||
_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/ESH-INF/thing``` of your binding._
|
||||
|
||||
#[[##]]# Channels
|
||||
|
||||
_Here you should provide information about available channel types, what their meaning is and how they can be used._
|
||||
|
||||
_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/ESH-INF/thing``` of your binding._
|
||||
|
||||
| channel | type | description |
|
||||
|----------|--------|------------------------------|
|
||||
| control | Switch | This is the control channel |
|
||||
|
||||
#[[##]]# Full Example
|
||||
|
||||
_Provide a full usage example based on textual configuration files (*.things, *.items, *.sitemap)._
|
||||
|
||||
#[[##]]# Any custom content here!
|
||||
|
||||
_Feel free to add additional sections for whatever you think should also be mentioned about your binding!_
|
@ -0,0 +1,16 @@
|
||||
<?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">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.openhab.addons.bundles</groupId>
|
||||
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
|
||||
<version>@${version}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
|
||||
<name>openHAB Add-ons :: Bundles :: ${bindingIdCamelCase} Binding</name>
|
||||
|
||||
</project>
|
@ -0,0 +1,37 @@
|
||||
#set( $dt = $package.getClass().forName("java.util.Date").newInstance() )
|
||||
#set( $year = $dt.getYear() + 1900 )
|
||||
#set( $copyright = "Contributors to the ${vendorName} project" )
|
||||
/**
|
||||
* Copyright (c) ${startYear},${year} ${copyright}
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package ${package}.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.smarthome.core.thing.ThingTypeUID;
|
||||
|
||||
/**
|
||||
* The {@link ${bindingIdCamelCase}BindingConstants} class defines common constants, which are
|
||||
* used across the whole binding.
|
||||
*
|
||||
* @author ${author} - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ${bindingIdCamelCase}BindingConstants {
|
||||
|
||||
private static final String BINDING_ID = "${bindingId}";
|
||||
|
||||
// List of all Thing Type UIDs
|
||||
public static final ThingTypeUID THING_TYPE_SAMPLE = new ThingTypeUID(BINDING_ID, "sample");
|
||||
|
||||
// List of all Channel ids
|
||||
public static final String CHANNEL_1 = "channel1";
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#set( $dt = $package.getClass().forName("java.util.Date").newInstance() )
|
||||
#set( $year = $dt.getYear() + 1900 )
|
||||
#set( $copyright = "Contributors to the ${vendorName} project" )
|
||||
/**
|
||||
* Copyright (c) ${startYear},${year} ${copyright}
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package ${package}.internal;
|
||||
|
||||
/**
|
||||
* The {@link ${bindingIdCamelCase}Configuration} class contains fields mapping thing configuration parameters.
|
||||
*
|
||||
* @author ${author} - Initial contribution
|
||||
*/
|
||||
public class ${bindingIdCamelCase}Configuration {
|
||||
|
||||
/**
|
||||
* Sample configuration parameter. Replace with your own.
|
||||
*/
|
||||
public String config1;
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
#set( $dt = $package.getClass().forName("java.util.Date").newInstance() )
|
||||
#set( $year = $dt.getYear() + 1900 )
|
||||
#set( $copyright = "Contributors to the ${vendorName} project" )
|
||||
/**
|
||||
* Copyright (c) ${startYear},${year} ${copyright}
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package ${package}.internal;
|
||||
|
||||
import static ${package}.internal.${bindingIdCamelCase}BindingConstants.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import ${package}.internal.${bindingIdCamelCase}Configuration;
|
||||
import org.eclipse.smarthome.core.thing.ChannelUID;
|
||||
import org.eclipse.smarthome.core.thing.Thing;
|
||||
import org.eclipse.smarthome.core.thing.ThingStatus;
|
||||
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
|
||||
import org.eclipse.smarthome.core.types.Command;
|
||||
import org.eclipse.smarthome.core.types.RefreshType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The {@link ${bindingIdCamelCase}Handler} is responsible for handling commands, which are
|
||||
* sent to one of the channels.
|
||||
*
|
||||
* @author ${author} - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ${bindingIdCamelCase}Handler extends BaseThingHandler {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(${bindingIdCamelCase}Handler.class);
|
||||
|
||||
@Nullable
|
||||
private ${bindingIdCamelCase}Configuration config;
|
||||
|
||||
public ${bindingIdCamelCase}Handler(Thing thing) {
|
||||
super(thing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||
if (CHANNEL_1.equals(channelUID.getId())) {
|
||||
if (command instanceof RefreshType) {
|
||||
// TODO: handle data refresh
|
||||
}
|
||||
|
||||
// TODO: handle command
|
||||
|
||||
// Note: if communication with thing fails for some reason,
|
||||
// indicate that by setting the status with detail information:
|
||||
// updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
||||
// "Could not control device at IP address x.x.x.x");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
// logger.debug("Start initializing!");
|
||||
config = getConfigAs(${bindingIdCamelCase}Configuration.class);
|
||||
|
||||
// TODO: Initialize the handler.
|
||||
// The framework requires you to return from this method quickly. Also, before leaving this method a thing
|
||||
// status from one of ONLINE, OFFLINE or UNKNOWN must be set. This might already be the real thing status in
|
||||
// case you can decide it directly.
|
||||
// In case you can not decide the thing status directly (e.g. for long running connection handshake using WAN
|
||||
// access or similar) you should set status UNKNOWN here and then decide the real status asynchronously in the
|
||||
// background.
|
||||
|
||||
// set the thing status to UNKNOWN temporarily and let the background task decide for the real status.
|
||||
// the framework is then able to reuse the resources from the thing handler initialization.
|
||||
// we set this upfront to reliably check status updates in unit tests.
|
||||
updateStatus(ThingStatus.UNKNOWN);
|
||||
|
||||
// Example for background initialization:
|
||||
scheduler.execute(() -> {
|
||||
boolean thingReachable = true; // <background task with long running initialization here>
|
||||
// when done do:
|
||||
if (thingReachable) {
|
||||
updateStatus(ThingStatus.ONLINE);
|
||||
} else {
|
||||
updateStatus(ThingStatus.OFFLINE);
|
||||
}
|
||||
});
|
||||
|
||||
// logger.debug("Finished initializing!");
|
||||
|
||||
// Note: When initialization can NOT be done set the status with more details for further
|
||||
// analysis. See also class ThingStatusDetail for all available status details.
|
||||
// Add a description to give user information to understand why thing does not work as expected. E.g.
|
||||
// updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||
// "Can not access device as username and/or password are invalid");
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
#set( $dt = $package.getClass().forName("java.util.Date").newInstance() )
|
||||
#set( $year = $dt.getYear() + 1900 )
|
||||
#set( $copyright = "Contributors to the ${vendorName} project" )
|
||||
/**
|
||||
* Copyright (c) ${startYear},${year} ${copyright}
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package ${package}.internal;
|
||||
|
||||
import static ${package}.internal.${bindingIdCamelCase}BindingConstants.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import ${package}.internal.${bindingIdCamelCase}Handler;
|
||||
import org.eclipse.smarthome.core.thing.Thing;
|
||||
import org.eclipse.smarthome.core.thing.ThingTypeUID;
|
||||
import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory;
|
||||
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
|
||||
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
|
||||
/**
|
||||
* The {@link ${bindingIdCamelCase}HandlerFactory} is responsible for creating things and thing
|
||||
* handlers.
|
||||
*
|
||||
* @author ${author} - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
@Component(configurationPid = "binding.${bindingId}", service = ThingHandlerFactory.class)
|
||||
public class ${bindingIdCamelCase}HandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_SAMPLE);
|
||||
|
||||
@Override
|
||||
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
|
||||
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable ThingHandler createHandler(Thing thing) {
|
||||
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
|
||||
|
||||
if (THING_TYPE_SAMPLE.equals(thingTypeUID)) {
|
||||
return new ${bindingIdCamelCase}Handler(thing);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<binding:binding id="${bindingId}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:binding="https://openhab.org/schemas/binding/v1.0.0"
|
||||
xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd">
|
||||
|
||||
<name>${bindingIdCamelCase} Binding</name>
|
||||
<description>This is the binding for ${bindingIdCamelCase}.</description>
|
||||
<author>${author}</author>
|
||||
|
||||
</binding:binding>
|
@ -0,0 +1,13 @@
|
||||
# FIXME: please substitute the xx_XX with a proper locale, ie. de_DE
|
||||
# FIXME: please do not add the file to the repo if you add or change no content
|
||||
# binding
|
||||
binding.${bindingId}.name = <Your localized Binding name>
|
||||
binding.${bindingId}.description = <Your localized Binding description>
|
||||
|
||||
# thing types
|
||||
thing-type.${bindingId}.sample.label = <Your localized Thing label>
|
||||
thing-type.${bindingId}.sample.description = <Your localized Thing description>
|
||||
|
||||
# channel types
|
||||
channel-type.${bindingId}.sample-channel.label = <Your localized Channel label>
|
||||
channel-type.${bindingId}.sample-channel.description = <Your localized Channel description>
|
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<thing:thing-descriptions bindingId="${bindingId}"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
|
||||
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
|
||||
|
||||
<!-- Sample Thing Type -->
|
||||
<thing-type id="sample">
|
||||
<label>${bindingIdCamelCase} Binding Thing</label>
|
||||
<description>Sample thing for ${bindingIdCamelCase} Binding</description>
|
||||
|
||||
<channels>
|
||||
<channel id="channel1" typeId="sample-channel" />
|
||||
</channels>
|
||||
|
||||
<config-description>
|
||||
<parameter name="config1" type="text" required="true">
|
||||
<label>Sample parameter</label>
|
||||
<description>This is a sample text configuration parameter.</description>
|
||||
</parameter>
|
||||
</config-description>
|
||||
|
||||
</thing-type>
|
||||
|
||||
<!-- Sample Channel Type -->
|
||||
<channel-type id="sample-channel">
|
||||
<item-type>${bindingId}Item</item-type>
|
||||
<label>${bindingIdCamelCase} Binding Channel</label>
|
||||
<description>Sample channel for ${bindingIdCamelCase} Binding</description>
|
||||
</channel-type>
|
||||
|
||||
</thing:thing-descriptions>
|
45
tools/archetype/pom.xml
Normal file
45
tools/archetype/pom.xml
Normal file
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.openhab.core</groupId>
|
||||
<artifactId>org.openhab.core.tools</artifactId>
|
||||
<version>2.5.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>org.openhab.core.tools.archetypes</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>openHAB Core :: Tools :: Archetypes</name>
|
||||
|
||||
<modules>
|
||||
<module>binding</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.mycila</groupId>
|
||||
<artifactId>license-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Disabled sat because nothing to check, and it actually breaks on spotbugs -->
|
||||
<plugin>
|
||||
<groupId>org.openhab.tools.sat</groupId>
|
||||
<artifactId>sat-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sat-all</id>
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
</project>
|
21
tools/pom.xml
Normal file
21
tools/pom.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.openhab.core</groupId>
|
||||
<artifactId>org.openhab.core.reactor</artifactId>
|
||||
<version>2.5.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>org.openhab.core.tools</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>openHAB Core :: Tools</name>
|
||||
|
||||
<modules>
|
||||
<module>archetype</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
Loading…
Reference in New Issue
Block a user