added migrated 2.x add-ons

Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
Kai Kreuzer
2020-09-21 01:58:32 +02:00
parent bbf1a7fd29
commit 6df6783b60
11662 changed files with 1302875 additions and 11 deletions

View File

@@ -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="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<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>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.openhab.binding.orvibo</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>

View File

@@ -0,0 +1,20 @@
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-addons
== Third-party Content
s20-sdk
* License: MIT License
* Project: https://github.com/tavalin/orvibo-sdk
* Source: https://github.com/tavalin/orvibo-sdk

View File

@@ -0,0 +1,53 @@
# Orvibo Binding
This binding integrates Orvibo devices that communicate using UDP.
Primarily this was designed for S20 Wifi Sockets but other products using the same protocol may be implemented in future.
## Supported Things
* S20 Wifi Sockets
## Discovery
This binding can automatically discover devices that have already been added to the Wifi network. Please see the check your instruction manual or the help guide in the app for instructions on how to add your device to your Wifi network.
## Binding Configuration
This binding does not require any special configuration.
## Thing Configuration
This is optional, it is recommended to let the binding discover and add Orvibo devices.
To manually configure an S20 Thing you must specify its deviceId (MAC address).
In the thing file, this looks like:
```
Thing orvibo:s20:mysocket [ deviceId="AABBCCDDEEFF"]
```
## Channels
### S20:
| Channel | Description | Example |
|---------|-------------------------------|---------------------------|
| power | Current power state of switch | orvibo:s20:mysocket:power |
## Items:
```
Switch MySwitch "Switch state [%s]" { channel="orvibo:s20:mysocket:power" }
```
## Example Sitemap
Using the above things channels and items
Sitemap:
```
sitemap demo label="Main Menu" {
Frame {
Switch item=MySwitch
}
}
```

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.openhab.binding.orvibo</artifactId>
<name>openHAB Add-ons :: Bundles :: Orvibo Binding</name>
<properties>
<dep.noembedding>commons-collections4</dep.noembedding>
</properties>
<dependencies>
<dependency>
<groupId>com.github.tavalin.orvibo-sdk</groupId>
<artifactId>s20-sdk</artifactId>
<version>0.0.6-nmu1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.orvibo-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>
<feature name="openhab-binding-orvibo" description="Orvibo Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle dependency="true">mvn:org.apache.commons/commons-collections4/4.1</bundle>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.orvibo/${project.version}</bundle>
</feature>
</features>

View File

@@ -0,0 +1,40 @@
/**
* Copyright (c) 2010-2020 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
*/
package org.openhab.binding.orvibo.internal;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import com.github.tavalin.s20.S20Client;
/**
* Bundle activator for the Orvibo Binding.
*
* @author Daniel Walters - Initial contribution
*
*/
public class OrviboActivator implements BundleActivator {
private S20Client s20Client;
@Override
public void start(BundleContext context) throws Exception {
s20Client = S20Client.getInstance();
s20Client.connect();
}
@Override
public void stop(BundleContext context) throws Exception {
s20Client.disconnect();
}
}

View File

@@ -0,0 +1,37 @@
/**
* Copyright (c) 2010-2020 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
*/
package org.openhab.binding.orvibo.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;
/**
* The {@link OrviboBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Daniel Walters - Initial contribution
*/
@NonNullByDefault
public class OrviboBindingConstants {
public static final String BINDING_ID = "orvibo";
// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_S20 = new ThingTypeUID(BINDING_ID, "s20");
// List of all Channel ids
public static final String CHANNEL_S20_SWITCH = "power";
// List of all Config properties
public static final String CONFIG_PROPERTY_DEVICE_ID = "deviceId";
}

View File

@@ -0,0 +1,52 @@
/**
* Copyright (c) 2010-2020 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
*/
package org.openhab.binding.orvibo.internal;
import static org.openhab.binding.orvibo.internal.OrviboBindingConstants.THING_TYPE_S20;
import java.util.Collections;
import java.util.Set;
import org.openhab.binding.orvibo.internal.handler.S20Handler;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.BaseThingHandlerFactory;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerFactory;
import org.osgi.service.component.annotations.Component;
/**
* The {@link OrviboHandlerFactory} is responsible for creating things and thing
* handlers.
*
* @author Daniel Walters - Initial contribution
*/
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.orvibo")
public class OrviboHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_S20);
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
}
@Override
protected ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (thingTypeUID.equals(THING_TYPE_S20)) {
return new S20Handler(thing);
}
return null;
}
}

View File

@@ -0,0 +1,121 @@
/**
* Copyright (c) 2010-2020 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
*/
package org.openhab.binding.orvibo.internal.discovery;
import java.net.SocketException;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.orvibo.internal.OrviboBindingConstants;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.tavalin.s20.S20Client;
import com.github.tavalin.s20.S20Client.SocketDiscoveryListener;
import com.github.tavalin.s20.Socket;
/**
* The {@link SocketDiscoveryService} class defines a service used
* to discover S20 sockets on the local netowork.
*
* @author Daniel Walters - Initial contribution
*/
@Component(service = DiscoveryService.class, immediate = true, configurationPid = "discovery.orvibo")
public class SocketDiscoveryService extends AbstractDiscoveryService implements SocketDiscoveryListener {
private final Logger logger = LoggerFactory.getLogger(SocketDiscoveryService.class);
private static final int SEARCH_TIME = 60;
private S20Client s20Client;
public SocketDiscoveryService() throws SocketException {
super(getSupportedThingTypeUIDs(), SEARCH_TIME);
}
private static Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return Collections.singleton(OrviboBindingConstants.THING_TYPE_S20);
}
@Override
protected void activate(Map<String, Object> configProperties) {
try {
s20Client = S20Client.getInstance();
super.activate(configProperties);
} catch (SocketException ex) {
logger.error("Error occurred while activating S20 discovery service: {}", ex.getMessage(), ex);
}
}
@Override
protected void startScan() {
if (s20Client != null) {
logger.debug("starting manual scan");
s20Client.addSocketDiscoveryListener(this);
s20Client.globalDiscovery();
for (final Socket socket : s20Client.getAllSockets().values()) {
doThingDiscovered(socket);
}
} else {
logger.debug("Client not initialised");
}
}
@Override
protected void startBackgroundDiscovery() {
if (s20Client != null) {
logger.debug("starting automatic background scan");
s20Client.addSocketDiscoveryListener(this);
s20Client.globalDiscovery();
} else {
logger.debug("Client not initialised");
}
}
@Override
protected void stopBackgroundDiscovery() {
s20Client.removeSocketDiscoveryListener(this);
}
@Override
public void socketDiscovered(Socket socket) {
doThingDiscovered(socket);
}
private DiscoveryResult createDiscoveryResult(Socket socket) {
ThingUID thingUID = getUID(socket);
String label = socket.getLabel();
if (StringUtils.isBlank(label)) {
label = "S20";
}
return DiscoveryResultBuilder.create(thingUID).withLabel(label)
.withProperty(OrviboBindingConstants.CONFIG_PROPERTY_DEVICE_ID, socket.getDeviceId()).build();
}
private ThingUID getUID(Socket socket) {
ThingUID thingUID = new ThingUID(OrviboBindingConstants.THING_TYPE_S20, socket.getDeviceId());
return thingUID;
}
private void doThingDiscovered(Socket socket) {
DiscoveryResult discoveryResult = createDiscoveryResult(socket);
thingDiscovered(discoveryResult);
}
}

View File

@@ -0,0 +1,125 @@
/**
* Copyright (c) 2010-2020 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
*/
package org.openhab.binding.orvibo.internal.handler;
import static org.openhab.binding.orvibo.internal.OrviboBindingConstants.CHANNEL_S20_SWITCH;
import java.net.SocketException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang.StringUtils;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.types.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.tavalin.s20.S20Client;
import com.github.tavalin.s20.Socket;
import com.github.tavalin.s20.Socket.SocketStateListener;
import com.github.tavalin.s20.entities.Types.PowerState;
/**
* The {@link S20Handler} is responsible for handling commands, which are
* sent to one of the channels.
*
* @author Daniel Walters - Initial contribution
*/
public class S20Handler extends BaseThingHandler implements SocketStateListener {
private final Logger logger = LoggerFactory.getLogger(S20Handler.class);
private Socket socket;
private S20Client client;
private ScheduledFuture<?> subscribeHandler;
private long refreshInterval = 15;
private Runnable subscribeTask = () -> {
if (socket != null) {
socket.subscribe();
}
};
public S20Handler(Thing thing) {
super(thing);
}
@Override
public void initialize() {
configure();
}
@Override
public void dispose() {
subscribeHandler.cancel(true);
socket.removeSocketStateListener(this);
}
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (channelUID.getId().equals(CHANNEL_S20_SWITCH)) {
try {
if (command == OnOffType.ON) {
socket.on();
} else if (command == OnOffType.OFF) {
socket.off();
}
} catch (SocketException e) {
logger.error("Error issuing command {} to socket {}", command, channelUID.getId());
}
}
}
private void configure() {
try {
client = S20Client.getInstance();
String deviceId = thing.getUID().getId();
socket = client.socketWithDeviceId(deviceId);
socket.addSocketStateListener(this);
socket.findOnNetwork();
subscribeHandler = scheduler.scheduleWithFixedDelay(subscribeTask, 0, refreshInterval, TimeUnit.SECONDS);
updateStatus(ThingStatus.ONLINE);
} catch (SocketException ex) {
logger.error("Error occurred while initializing S20 handler: {}", ex.getMessage(), ex);
}
}
@Override
public void socketDidChangeLabel(Socket socket, String label) {
if (!StringUtils.isBlank(label)) {
logger.debug("Updating thing label to {}", label);
thing.setLabel(label);
}
}
@Override
public void socketDidChangePowerState(Socket socket, PowerState state) {
logger.debug("Received power state: {}", state);
if (socket.getDeviceId().equals(thing.getUID().getId())) {
if (state == PowerState.ON) {
updateState(CHANNEL_S20_SWITCH, OnOffType.ON);
} else if (state == PowerState.OFF) {
updateState(CHANNEL_S20_SWITCH, OnOffType.OFF);
}
}
}
@Override
public void socketDidInitialisation(Socket socket) {
if (thing.getStatus() != ThingStatus.ONLINE) {
updateStatus(ThingStatus.ONLINE);
}
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<binding:binding id="orvibo" 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>Orvibo Binding</name>
<description>This is the binding for Orvibo devices.</description>
<author>Daniel Walters</author>
</binding:binding>

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="orvibo"
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">
<thing-type id="s20">
<label>Orvibo S20 Smart Wifi Socket</label>
<description>This is an Orvibo S20 Smart Wifi Socket</description>
<channels>
<channel id="power" typeId="power"/>
</channels>
<config-description>
<parameter name="deviceId" type="text" required="true">
<label>MAC Address</label>
<description>The MAC address identifies a specific S20 Socket.</description>
<required>true</required>
</parameter>
</config-description>
</thing-type>
<channel-type id="power">
<item-type>Switch</item-type>
<label>Power</label>
<description>Switch on/off your S20 Socket.</description>
</channel-type>
</thing:thing-descriptions>