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

Add methods to get supported cluster list from converters #517

Merged
merged 6 commits into from
Jan 2, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import java.util.HashSet;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.cc2531.internal.CC2531Configuration;
import org.openhab.binding.zigbee.converter.ZigBeeChannelConverterFactory;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
import org.openhab.binding.zigbee.handler.ZigBeeSerialPort;
import org.osgi.service.component.annotations.Activate;
Expand All @@ -41,15 +41,15 @@
*
* @author Chris Jackson - Initial contribution
*/
@NonNullByDefault
public class CC2531Handler extends ZigBeeCoordinatorHandler {
private final Logger logger = LoggerFactory.getLogger(CC2531Handler.class);

private final SerialPortManager serialPortManager;

@Activate
public CC2531Handler(Bridge coordinator, SerialPortManager serialPortManager) {
super(coordinator);
public CC2531Handler(Bridge coordinator, SerialPortManager serialPortManager,
ZigBeeChannelConverterFactory channelFactory) {
super(coordinator, channelFactory);
this.serialPortManager = serialPortManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.cc2531.CC2531BindingConstants;
import org.openhab.binding.zigbee.cc2531.handler.CC2531Handler;
import org.openhab.binding.zigbee.converter.ZigBeeChannelConverterFactory;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
Expand All @@ -53,11 +54,23 @@ public class CC2531HandlerFactory extends BaseThingHandlerFactory {

private final SerialPortManager serialPortManager;

@Nullable
private ZigBeeChannelConverterFactory zigbeeChannelConverterFactory;

@Activate
public CC2531HandlerFactory(final @Reference SerialPortManager serialPortManager) {
this.serialPortManager = serialPortManager;
}

@Reference
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the @Reference directly on the field would remove the need for the set and unset methods.

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

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

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
Expand All @@ -69,7 +82,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {

ZigBeeCoordinatorHandler coordinator = null;
if (thingTypeUID.equals(CC2531BindingConstants.THING_TYPE_CC2531)) {
coordinator = new CC2531Handler((Bridge) thing, serialPortManager);
coordinator = new CC2531Handler((Bridge) thing, serialPortManager, zigbeeChannelConverterFactory);
}

if (coordinator != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.smarthome.core.thing.binding.firmware.ProgressStep;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.ZigBeeBindingConstants;
import org.openhab.binding.zigbee.converter.ZigBeeChannelConverterFactory;
import org.openhab.binding.zigbee.ember.internal.EmberConfiguration;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
import org.openhab.binding.zigbee.handler.ZigBeeSerialPort;
Expand Down Expand Up @@ -77,8 +78,9 @@ public class EmberHandler extends ZigBeeCoordinatorHandler implements FirmwareUp

private @Nullable ScheduledFuture<?> pollingJob;

public EmberHandler(Bridge coordinator, SerialPortManager serialPortManager) {
super(coordinator);
public EmberHandler(Bridge coordinator, SerialPortManager serialPortManager,
ZigBeeChannelConverterFactory channelFactory) {
super(coordinator, channelFactory);
this.serialPortManager = serialPortManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.converter.ZigBeeChannelConverterFactory;
import org.openhab.binding.zigbee.ember.EmberBindingConstants;
import org.openhab.binding.zigbee.ember.handler.EmberHandler;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
Expand All @@ -53,11 +54,23 @@ public class EmberHandlerFactory extends BaseThingHandlerFactory {

private final SerialPortManager serialPortManager;

@Nullable
private ZigBeeChannelConverterFactory zigbeeChannelConverterFactory;

@Activate
public EmberHandlerFactory(final @Reference SerialPortManager serialPortManager) {
this.serialPortManager = serialPortManager;
}

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

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

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
Expand All @@ -69,7 +82,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {

ZigBeeCoordinatorHandler emberHandler = null;
if (thingTypeUID.equals(EmberBindingConstants.THING_TYPE_EMBER)) {
emberHandler = new EmberHandler((Bridge) thing, serialPortManager);
emberHandler = new EmberHandler((Bridge) thing, serialPortManager, zigbeeChannelConverterFactory);
}

if (emberHandler != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.smarthome.core.thing.binding.firmware.ProgressStep;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.ZigBeeBindingConstants;
import org.openhab.binding.zigbee.converter.ZigBeeChannelConverterFactory;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
import org.openhab.binding.zigbee.handler.ZigBeeSerialPort;
import org.openhab.binding.zigbee.telegesis.internal.TelegesisConfiguration;
Expand All @@ -50,15 +51,15 @@
*
* @author Chris Jackson - Initial contribution
*/
// @NonNullByDefault
public class TelegesisHandler extends ZigBeeCoordinatorHandler implements FirmwareUpdateHandler {
private final Logger logger = LoggerFactory.getLogger(TelegesisHandler.class);

private final SerialPortManager serialPortManager;

@Activate
public TelegesisHandler(Bridge coordinator, SerialPortManager serialPortManager) {
super(coordinator);
public TelegesisHandler(Bridge coordinator, SerialPortManager serialPortManager,
ZigBeeChannelConverterFactory channelFactory) {
super(coordinator, channelFactory);
this.serialPortManager = serialPortManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.converter.ZigBeeChannelConverterFactory;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
import org.openhab.binding.zigbee.telegesis.TelegesisBindingConstants;
import org.openhab.binding.zigbee.telegesis.handler.TelegesisHandler;
Expand All @@ -53,11 +54,23 @@ public class TelegesisHandlerFactory extends BaseThingHandlerFactory {

private final SerialPortManager serialPortManager;

@Nullable
private ZigBeeChannelConverterFactory zigbeeChannelConverterFactory;

@Activate
public TelegesisHandlerFactory(final @Reference SerialPortManager serialPortManager) {
this.serialPortManager = serialPortManager;
}

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

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

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
Expand All @@ -69,7 +82,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {

ZigBeeCoordinatorHandler coordinator = null;
if (thingTypeUID.equals(TelegesisBindingConstants.THING_TYPE_TELEGESIS)) {
coordinator = new TelegesisHandler((Bridge) thing, serialPortManager);
coordinator = new TelegesisHandler((Bridge) thing, serialPortManager, zigbeeChannelConverterFactory);
}

if (coordinator != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.ZigBeeBindingConstants;
import org.openhab.binding.zigbee.converter.ZigBeeChannelConverterFactory;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
import org.openhab.binding.zigbee.handler.ZigBeeSerialPort;
import org.openhab.binding.zigbee.xbee.internal.XBeeConfiguration;
Expand All @@ -36,15 +37,15 @@
*
* @author Chris Jackson - Initial contribution
*/
// @NonNullByDefault
public class XBeeHandler extends ZigBeeCoordinatorHandler {
private final Logger logger = LoggerFactory.getLogger(XBeeHandler.class);

private final SerialPortManager serialPortManager;

@Activate
public XBeeHandler(Bridge coordinator, SerialPortManager serialPortManager) {
super(coordinator);
public XBeeHandler(Bridge coordinator, SerialPortManager serialPortManager,
ZigBeeChannelConverterFactory channelFactory) {
super(coordinator, channelFactory);
this.serialPortManager = serialPortManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Map;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.Thing;
Expand All @@ -28,6 +27,7 @@
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zigbee.converter.ZigBeeChannelConverterFactory;
import org.openhab.binding.zigbee.handler.ZigBeeCoordinatorHandler;
import org.openhab.binding.zigbee.xbee.XBeeBindingConstants;
import org.openhab.binding.zigbee.xbee.handler.XBeeHandler;
Expand All @@ -42,7 +42,6 @@
*
* @author Chris Jackson - Initial contribution
*/
@NonNullByDefault
@Component(service = ThingHandlerFactory.class, configurationPid = "org.openhab.binding.zigbee.xbee")
public class XBeeHandlerFactory extends BaseThingHandlerFactory {

Expand All @@ -53,11 +52,23 @@ public class XBeeHandlerFactory extends BaseThingHandlerFactory {

private final SerialPortManager serialPortManager;

@Nullable
private ZigBeeChannelConverterFactory zigbeeChannelConverterFactory;

@Activate
public XBeeHandlerFactory(final @Reference SerialPortManager serialPortManager) {
this.serialPortManager = serialPortManager;
}

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

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

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
Expand All @@ -69,7 +80,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {

ZigBeeCoordinatorHandler coordinator = null;
if (thingTypeUID.equals(XBeeBindingConstants.THING_TYPE_XBEE)) {
coordinator = new XBeeHandler((Bridge) thing, serialPortManager);
coordinator = new XBeeHandler((Bridge) thing, serialPortManager, zigbeeChannelConverterFactory);
}

if (coordinator != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public class ZigBeeBindingConstants {
public static final String THING_PROPERTY_STACKCOMPLIANCE = "zigbee_stkcompliance";
public static final String THING_PROPERTY_DEVICE_INITIALIZED = "zigbee_device_initialised";
public static final String THING_PROPERTY_MANUFACTURERCODE = "zigbee_manufacturercode";
public static final String THING_PROPERTY_MACADDRESS = "zigbee_macaddress";

// List of all configuration parameters
public static final String CONFIGURATION_PANID = "zigbee_panid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;

import org.eclipse.jdt.annotation.NonNull;
Expand Down Expand Up @@ -213,6 +214,20 @@ public boolean initializeDevice() {
return true;
}

/**
* Gets the cluster IDs that are implemented within the converter on the client side.
*
* @return Set of cluster IDs supported by the converter
*/
public abstract Set<Integer> getImplementedClientClusters();

/**
* Gets the cluster IDs that are implemented within the converter on the server side.
*
* @return Set of cluster IDs supported by the converter
*/
public abstract Set<Integer> getImplementedServerClusters();

/**
* Initialise the converter. This is called by the {@link ZigBeeThingHandler} when the channel is created. The
* converter should initialise any internal states, open any clusters, add reporting and binding that it needs to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.binding.zigbee.converter;

import java.util.Collection;
import java.util.Set;

import org.eclipse.smarthome.core.thing.Channel;
import org.eclipse.smarthome.core.thing.ThingUID;
Expand Down Expand Up @@ -50,13 +51,27 @@ public interface ZigBeeChannelConverterFactory {
/**
* Creates a channel converter for the requested {@link ChannelTypeUID}
*
* @param thingHandler the {@link ZigBeeThingHandler} for this channel
* @param channel the {@link Channel} to create the converter for
* @param thingHandler the {@link ZigBeeThingHandler} for this channel
* @param channel the {@link Channel} to create the converter for
* @param coordinatorHandler the {@link ZigBeeCoordinatorHandler}
* @param ieeeAddress the {@link IeeeAddress} of the device
* @param endpointId the endpoint ID for this channel on the device
* @param ieeeAddress the {@link IeeeAddress} of the device
* @param endpointId the endpoint ID for this channel on the device
* @return the {@link ZigBeeBaseChannelConverter} or null if the channel is not supported
*/
ZigBeeBaseChannelConverter createConverter(ZigBeeThingHandler thingHandler, Channel channel,
ZigBeeCoordinatorHandler coordinatorHandler, IeeeAddress ieeeAddress, int endpointId);

/**
* Gets the cluster IDs that are supported by all converters known to the system
*
* @return Set of cluster IDs supported by the system
*/
Set<Integer> getImplementedClientClusters();

/**
* Gets the cluster IDs that are supported by all converters known to the system
*
* @return Set of cluster IDs supported by the system
*/
Set<Integer> getImplementedServerClusters();
}
Loading