Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Tuya into separate bundle #675

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
bin/
target/
**/.settings/org.eclipse.*
*.sh
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ using your real name (sorry, no pseudonyms or anonymous contributions.)
There are several exceptions to the signing requirement. Currently these are:

* Your patch fixes spelling or grammar errors.
* Your patch is a single line change to documentation.
* Your patch is a small change to documentation.

## Community Guidelines

Expand Down
7 changes: 6 additions & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<artifactId>org.openhab.addons.bom.zigbee</artifactId>
<packaging>pom</packaging>

<name>openHAB ZigBee :: BOM :: openHAB ZigBee Binding</name>
<name>openHAB Add-ons :: Bundles :: ZigBee Binding BOM</name>

<dependencies>
<dependency>
Expand Down Expand Up @@ -50,6 +50,11 @@
<artifactId>org.openhab.binding.zigbee.telegesis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.zigbee.tuya</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.zigbee.xbee</artifactId>
Expand Down
15 changes: 10 additions & 5 deletions feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@
<artifactId>org.openhab.binding.zigbee.ember</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.zigbee.telegesis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.zigbee.telegesis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.zigbee.tuya</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.zigbee.xbee</artifactId>
Expand Down
1 change: 1 addition & 0 deletions org.openhab.binding.zigbee.tuya/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
14 changes: 14 additions & 0 deletions org.openhab.binding.zigbee.tuya/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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/org.openhab.binding.zigbee

24 changes: 24 additions & 0 deletions org.openhab.binding.zigbee.tuya/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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.zigbee.reactor</artifactId>
<version>3.2.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.zigbee.tuya</artifactId>

<name>openHAB Add-ons :: Bundles :: ZigBee Tuya Handler</name>

<dependencies>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.zigbee</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2010-2021 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.zigbee.tuya;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.zigbee.ZigBeeBindingConstants;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.type.ChannelTypeUID;

/**
* The {@link TuyaBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Chris Jackson - Initial contribution
*/
@NonNullByDefault
public class TuyaBindingConstants {

// List of Thing Type UIDs
public final static ThingTypeUID THING_TYPE_TUYA_BLIND_AM25 = new ThingTypeUID(ZigBeeBindingConstants.BINDING_ID,
"tuya_am25");

public static final String CHANNEL_NAME_TUYA_BUTTON = "tuyabutton";
public static final String CHANNEL_LABEL_TUYA_BUTTON = "Button";
public static final ChannelTypeUID CHANNEL_TUYA_BUTTON = new ChannelTypeUID("zigbee:tuya_button");

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.openhab.binding.zigbee.tuya.handler;

import org.openhab.binding.zigbee.converter.ZigBeeChannelConverterFactory;
import org.openhab.binding.zigbee.handler.ZigBeeBaseThingHandler;
import org.openhab.binding.zigbee.handler.ZigBeeIsAliveTracker;
import org.openhab.core.thing.Thing;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zsmartsystems.zigbee.ZigBeeEndpoint;
import com.zsmartsystems.zigbee.ZigBeeNode;

/**
* Handler for Tuya AM25 blinds
*
* @author Chris Jackson - Initial Contribution
*
*/
public class TuyaBlindsThingHandler extends ZigBeeBaseThingHandler {
private Logger logger = LoggerFactory.getLogger(TuyaBlindsThingHandler.class);

public TuyaBlindsThingHandler(Thing zigbeeDevice, ZigBeeChannelConverterFactory channelFactory,
ZigBeeIsAliveTracker zigbeeIsAliveTracker) {
super(zigbeeDevice, channelFactory, zigbeeIsAliveTracker);
// TODO Auto-generated constructor stub
}

@Override
protected void doNodeInitialisation(ZigBeeNode node) {
ZigBeeEndpoint endpoint = node.getEndpoint(1);
if (endpoint == null) {
logger.error("{}: Tuya blinds handler couldn't find endpoint 1", node.getIeeeAddress());
return;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Copyright (c) 2010-2021 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.zigbee.tuya.internal;

import java.util.Hashtable;

import org.openhab.binding.zigbee.converter.ZigBeeChannelConverterFactory;
import org.openhab.binding.zigbee.discovery.ZigBeeThingTypeMatcher;
import org.openhab.binding.zigbee.handler.ZigBeeBaseThingHandler;
import org.openhab.binding.zigbee.handler.ZigBeeGenericThingHandler;
import org.openhab.binding.zigbee.handler.ZigBeeIsAliveTracker;
import org.openhab.binding.zigbee.tuya.TuyaBindingConstants;
import org.openhab.binding.zigbee.tuya.handler.TuyaBlindsThingHandler;
import org.openhab.core.config.core.ConfigDescriptionProvider;
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.openhab.core.thing.type.DynamicStateDescriptionProvider;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* The {@link TuyaHandlerFactory} is responsible for creating things and thing
* handlers for Tuya devices.
*
* @author Chris Jackson - Initial contribution
*/
@Component(service = ThingHandlerFactory.class)
public class TuyaHandlerFactory extends BaseThingHandlerFactory {

private final ZigBeeThingTypeMatcher matcher = new ZigBeeThingTypeMatcher();

private ZigBeeChannelConverterFactory zigbeeChannelConverterFactory;
private ZigBeeIsAliveTracker zigbeeIsAliveTracker;

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return matcher.getSupportedThingTypeUIDs().contains(thingTypeUID);
}

@Override
protected ThingHandler createHandler(Thing thing) {
if (!supportsThingType(thing.getThingTypeUID())) {
return null;
}

ZigBeeBaseThingHandler handler;

// Check for thing types with a custom thing handler
if (thing.getThingTypeUID().equals(TuyaBindingConstants.THING_TYPE_TUYA_BLIND_AM25)) {
handler = new TuyaBlindsThingHandler(thing, zigbeeChannelConverterFactory, zigbeeIsAliveTracker);
} else {
handler = new ZigBeeGenericThingHandler(thing, zigbeeChannelConverterFactory, zigbeeIsAliveTracker);
}

bundleContext.registerService(ConfigDescriptionProvider.class.getName(), handler,
new Hashtable<String, Object>());
bundleContext.registerService(DynamicStateDescriptionProvider.class.getName(), handler,
new Hashtable<String, Object>());

return handler;
}

@Reference
protected void setZigBeeChannelConverterFactory(ZigBeeChannelConverterFactory zigbeeChannelConverterFactory) {
this.zigbeeChannelConverterFactory = zigbeeChannelConverterFactory;
}

protected void unsetZigBeeChannelConverterFactory(ZigBeeChannelConverterFactory zigbeeChannelConverterFactory) {
this.zigbeeChannelConverterFactory = null;
}

@Reference
protected void setZigbeeIsAliveTracker(ZigBeeIsAliveTracker zigbeeIsAliveTracker) {
this.zigbeeIsAliveTracker = zigbeeIsAliveTracker;
}

protected void unsetZigbeeIsAliveTracker(ZigBeeIsAliveTracker zigbeeIsAliveTracker) {
this.zigbeeIsAliveTracker = null;
}
}
Loading