From e1d1c09db0fa6404c85428f2101678de9b944dde Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Thu, 14 Nov 2019 05:46:49 +0000 Subject: [PATCH] Add methods to get supported cluster list from converters Signed-off-by: Chris Jackson --- .../converter/ZigBeeBaseChannelConverter.java | 15 +++++++ .../ZigBeeChannelConverterFactory.java | 23 ++++++++-- .../handler/ZigBeeCoordinatorHandler.java | 20 ++++++--- .../ZigBeeChannelConverterFactoryImpl.java | 45 +++++++++++++++++++ .../ZigBeeConverterAtmosphericPressure.java | 14 ++++++ pom.xml | 2 +- 6 files changed, 109 insertions(+), 10 deletions(-) diff --git a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/converter/ZigBeeBaseChannelConverter.java b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/converter/ZigBeeBaseChannelConverter.java index aa8b62cfa..24bf43dd6 100644 --- a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/converter/ZigBeeBaseChannelConverter.java +++ b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/converter/ZigBeeBaseChannelConverter.java @@ -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; @@ -213,6 +214,20 @@ public boolean initializeDevice() { return true; } + /** + * Gets the cluster IDs that are supported by the converter + * + * @return Set of cluster IDs supported by the converter + */ + public abstract Set getSupportedClientClusters(); + + /** + * Gets the cluster IDs that are supported by the converter + * + * @return Set of cluster IDs supported by the converter + */ + public abstract Set getSupportedServerClusters(); + /** * 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 diff --git a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/converter/ZigBeeChannelConverterFactory.java b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/converter/ZigBeeChannelConverterFactory.java index b223492df..4947c557c 100644 --- a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/converter/ZigBeeChannelConverterFactory.java +++ b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/converter/ZigBeeChannelConverterFactory.java @@ -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; @@ -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 getSupportedClientClusters(); + + /** + * Gets the cluster IDs that are supported by all converters known to the system + * + * @return Set of cluster IDs supported by the system + */ + Set getSupportedServerClusters(); } diff --git a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeCoordinatorHandler.java b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeCoordinatorHandler.java index 7ab622d8a..3c1021e3a 100644 --- a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeCoordinatorHandler.java +++ b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeCoordinatorHandler.java @@ -41,6 +41,7 @@ import org.eclipse.smarthome.core.thing.binding.BaseBridgeHandler; import org.eclipse.smarthome.core.types.Command; import org.openhab.binding.zigbee.ZigBeeBindingConstants; +import org.openhab.binding.zigbee.converter.ZigBeeChannelConverterFactory; import org.openhab.binding.zigbee.internal.ZigBeeDataStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -72,7 +73,6 @@ import com.zsmartsystems.zigbee.transport.TrustCentreJoinMode; import com.zsmartsystems.zigbee.transport.ZigBeeTransportFirmwareUpdate; import com.zsmartsystems.zigbee.transport.ZigBeeTransportTransmit; -import com.zsmartsystems.zigbee.zcl.clusters.ZclIasZoneCluster; import com.zsmartsystems.zigbee.zdo.field.NeighborTable; import com.zsmartsystems.zigbee.zdo.field.RoutingTable; @@ -132,6 +132,11 @@ public abstract class ZigBeeCoordinatorHandler extends BaseBridgeHandler private final Object reconnectLock = new Object(); private boolean currentReconnectAttemptFinished = false; + /** + * The factory to create the converters for the different channels. + */ + private final ZigBeeChannelConverterFactory channelFactory; + /** * Default ZigBeeAlliance09 link key */ @@ -140,8 +145,9 @@ public abstract class ZigBeeCoordinatorHandler extends BaseBridgeHandler private static final long RECONNECT_RATE = 5; - public ZigBeeCoordinatorHandler(Bridge coordinator) { + public ZigBeeCoordinatorHandler(Bridge coordinator, ZigBeeChannelConverterFactory channelFactory) { super(coordinator); + this.channelFactory = channelFactory; } @Override @@ -439,6 +445,13 @@ private synchronized void initialiseZigBee() { return; } + // Add all the clusters that we are supporting. + // If we don't do this, the framework will reject any packets for clusters we have not stated support for. + channelFactory.getSupportedClientClusters().stream() + .forEach(clusterId -> networkManager.addSupportedClientCluster(clusterId)); + channelFactory.getSupportedServerClusters().stream() + .forEach(clusterId -> networkManager.addSupportedServerCluster(clusterId)); + // Show the initial network configuration for debugging ZigBeeChannel currentChannel = networkManager.getZigBeeChannel(); int currentPanId = networkManager.getZigBeePanId(); @@ -495,9 +508,6 @@ private synchronized void initialiseZigBee() { } initializeDongleSpecific(); - - // Add the IAS Zone cluster to the network manager so we respond to the MatchDescriptor - networkManager.addSupportedCluster(ZclIasZoneCluster.CLUSTER_ID); } private void startZigBeeNetwork() { diff --git a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeChannelConverterFactoryImpl.java b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeChannelConverterFactoryImpl.java index 7414f8d26..b72a62f6c 100644 --- a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeChannelConverterFactoryImpl.java +++ b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeChannelConverterFactoryImpl.java @@ -18,6 +18,8 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import org.eclipse.smarthome.core.thing.Channel; import org.eclipse.smarthome.core.thing.ThingUID; @@ -132,4 +134,47 @@ public void removeZigBeeChannelConverterProvider(ZigBeeChannelConverterProvider channelMap.keySet().removeAll(zigBeeChannelConverterProvider.getChannelConverters().keySet()); } + /** + * Gets the cluster IDs that are supported by the converter + * + * @return Set of cluster IDs supported by the converter. The Set will be ordered by ascending ID + */ + @Override + public Set getSupportedClientClusters() { + Set clusters = new TreeSet<>(); + try { + for (Class converter : channelMap.values()) { + Constructor constructor = converter.getConstructor(); + ZigBeeBaseChannelConverter instance = constructor.newInstance(); + + clusters.addAll(instance.getSupportedClientClusters()); + } + } catch (Exception e) { + logger.error("Unable to consolidate client cluster IDs", e); + } + + return clusters; + } + + /** + * Gets the cluster IDs that are supported by the converter + * + * @return Set of cluster IDs supported by the converter. The Set will be ordered by ascending ID + */ + @Override + public Set getSupportedServerClusters() { + Set clusters = new TreeSet<>(); + try { + for (Class converter : channelMap.values()) { + Constructor constructor = converter.getConstructor(); + ZigBeeBaseChannelConverter instance = constructor.newInstance(); + + clusters.addAll(instance.getSupportedServerClusters()); + } + } catch (Exception e) { + logger.error("Unable to consolidate server cluster IDs", e); + } + + return clusters; + } } diff --git a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeConverterAtmosphericPressure.java b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeConverterAtmosphericPressure.java index e3033884a..af039fe12 100644 --- a/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeConverterAtmosphericPressure.java +++ b/org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/internal/converter/ZigBeeConverterAtmosphericPressure.java @@ -16,7 +16,11 @@ import static org.eclipse.smarthome.core.library.unit.MetricPrefix.HECTO; import java.math.BigDecimal; +import java.util.Collections; +import java.util.Set; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.measure.quantity.Pressure; @@ -50,6 +54,16 @@ public class ZigBeeConverterAtmosphericPressure extends ZigBeeBaseChannelConvert private ZclPressureMeasurementCluster cluster; + @Override + public Set getSupportedClientClusters() { + return Stream.of(ZclPressureMeasurementCluster.CLUSTER_ID).collect(Collectors.toSet()); + } + + @Override + public Set getSupportedServerClusters() { + return Collections.emptySet(); + } + /** * If enhancedScale is null, then the binding will use the MeasuredValue report, * otherwise it will use the ScaledValue report diff --git a/pom.xml b/pom.xml index 69d053306..e636db266 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ false - 1.2.3 + 1.2.6-SNAPSHOT 1.24.3 true 0.8.0