Skip to content

Commit

Permalink
Add methods to get supported cluster list from converters
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Jackson <[email protected]>
  • Loading branch information
cdjackson committed Nov 17, 2019
1 parent c3a280a commit e1d1c09
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 10 deletions.
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 supported by the converter
*
* @return Set of cluster IDs supported by the converter
*/
public abstract Set<Integer> getSupportedClientClusters();

/**
* Gets the cluster IDs that are supported by the converter
*
* @return Set of cluster IDs supported by the converter
*/
public abstract Set<Integer> 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
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> 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<Integer> getSupportedServerClusters();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
*/
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Integer> getSupportedClientClusters() {
Set<Integer> clusters = new TreeSet<>();
try {
for (Class<? extends ZigBeeBaseChannelConverter> converter : channelMap.values()) {
Constructor<? extends ZigBeeBaseChannelConverter> 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<Integer> getSupportedServerClusters() {
Set<Integer> clusters = new TreeSet<>();
try {
for (Class<? extends ZigBeeBaseChannelConverter> converter : channelMap.values()) {
Constructor<? extends ZigBeeBaseChannelConverter> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -50,6 +54,16 @@ public class ZigBeeConverterAtmosphericPressure extends ZigBeeBaseChannelConvert

private ZclPressureMeasurementCluster cluster;

@Override
public Set<Integer> getSupportedClientClusters() {
return Stream.of(ZclPressureMeasurementCluster.CLUSTER_ID).collect(Collectors.toSet());
}

@Override
public Set<Integer> getSupportedServerClusters() {
return Collections.emptySet();
}

/**
* If enhancedScale is null, then the binding will use the MeasuredValue report,
* otherwise it will use the ScaledValue report
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<properties>
<report.fail.on.error>false</report.fail.on.error>
<zsmartsystems.version>1.2.3</zsmartsystems.version>
<zsmartsystems.version>1.2.6-SNAPSHOT</zsmartsystems.version>
<spotless.version>1.24.3</spotless.version>
<spotless.check.skip>true</spotless.check.skip> <!-- Spotless disabled for now -->
<sat.version>0.8.0</sat.version>
Expand Down

0 comments on commit e1d1c09

Please sign in to comment.