Skip to content

Commit

Permalink
Update Binary Input converter
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Jackson <[email protected]>
  • Loading branch information
cdjackson committed Dec 31, 2019
1 parent 5febd00 commit 7ea289b
Show file tree
Hide file tree
Showing 26 changed files with 72 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
import com.zsmartsystems.zigbee.transport.TrustCentreJoinMode;
import com.zsmartsystems.zigbee.transport.ZigBeeTransportFirmwareUpdate;
import com.zsmartsystems.zigbee.transport.ZigBeeTransportTransmit;
import com.zsmartsystems.zigbee.zcl.clusters.ZclBasicCluster;
import com.zsmartsystems.zigbee.zcl.clusters.ZclOtaUpgradeCluster;
import com.zsmartsystems.zigbee.zdo.field.NeighborTable;
import com.zsmartsystems.zigbee.zdo.field.RoutingTable;

Expand Down Expand Up @@ -403,6 +405,22 @@ private synchronized void initialiseZigBee() {
networkManager.addNetworkStateListener(this);
networkManager.addNetworkNodeListener(this);

// Initialise the network
switch (networkManager.initialize()) {
case SUCCESS:
break;
case BAD_RESPONSE:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, ZigBeeBindingConstants.OFFLINE_BAD_RESPONSE);
return;
case COMMUNICATION_ERROR:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, ZigBeeBindingConstants.OFFLINE_COMMS_FAIL);
return;
default:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
ZigBeeBindingConstants.OFFLINE_INITIALIZE_FAIL);
return;
}

int meshUpdateTime = MESH_UPDATE_PERIOD;
if (getConfig().get(CONFIGURATION_MESHUPDATEPERIOD) != null) {
logger.debug("Mesh Update Period {}", getConfig().get(CONFIGURATION_MESHUPDATEPERIOD));
Expand All @@ -429,29 +447,17 @@ private synchronized void initialiseZigBee() {
}
}

// Initialise the network
switch (networkManager.initialize()) {
case SUCCESS:
break;
case BAD_RESPONSE:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, ZigBeeBindingConstants.OFFLINE_BAD_RESPONSE);
return;
case COMMUNICATION_ERROR:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, ZigBeeBindingConstants.OFFLINE_COMMS_FAIL);
return;
default:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
ZigBeeBindingConstants.OFFLINE_INITIALIZE_FAIL);
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.getImplementedClientClusters().stream()
.forEach(clusterId -> networkManager.addSupportedClientCluster(clusterId));
channelFactory.getImplementedServerClusters().stream()
.forEach(clusterId -> networkManager.addSupportedServerCluster(clusterId));

networkManager.addSupportedClientCluster(ZclBasicCluster.CLUSTER_ID);
networkManager.addSupportedClientCluster(ZclOtaUpgradeCluster.CLUSTER_ID);
networkManager.addSupportedServerCluster(ZclBasicCluster.CLUSTER_ID);

// Show the initial network configuration for debugging
ZigBeeChannel currentChannel = networkManager.getZigBeeChannel();
int currentPanId = networkManager.getZigBeePanId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ZigBeeDataStore implements ZigBeeNetworkDataStore {
/**
* The logger.
*/
private final static Logger logger = LoggerFactory.getLogger(ZigBeeDataStore.class);
private final Logger logger = LoggerFactory.getLogger(ZigBeeDataStore.class);

private final String networkStateFilePath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
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 @@ -56,7 +54,7 @@ public class ZigBeeConverterAtmosphericPressure extends ZigBeeBaseChannelConvert

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.thing.Channel;
Expand Down Expand Up @@ -74,7 +72,7 @@ public class ZigBeeConverterBatteryAlarm extends ZigBeeBaseChannelConverter impl

@Override
public Set<Integer> getImplementedClientClusters() {
return Stream.of(ZclPowerConfigurationCluster.CLUSTER_ID).collect(Collectors.toSet());
return Collections.singleton(ZclPowerConfigurationCluster.CLUSTER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.thing.Channel;
Expand Down Expand Up @@ -49,7 +47,7 @@ public class ZigBeeConverterBatteryPercent extends ZigBeeBaseChannelConverter im

@Override
public Set<Integer> getImplementedClientClusters() {
return Stream.of(ZclPowerConfigurationCluster.CLUSTER_ID).collect(Collectors.toSet());
return Collections.singleton(ZclPowerConfigurationCluster.CLUSTER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
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.ElectricPotential;

Expand Down Expand Up @@ -51,7 +49,7 @@ public class ZigBeeConverterBatteryVoltage extends ZigBeeBaseChannelConverter im

@Override
public Set<Integer> getImplementedClientClusters() {
return Stream.of(ZclPowerConfigurationCluster.CLUSTER_ID).collect(Collectors.toSet());
return Collections.singleton(ZclPowerConfigurationCluster.CLUSTER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
*/
package org.openhab.binding.zigbee.internal.converter;

import com.zsmartsystems.zigbee.CommandResult;
import com.zsmartsystems.zigbee.ZigBeeEndpoint;
import com.zsmartsystems.zigbee.zcl.ZclAttribute;
import com.zsmartsystems.zigbee.zcl.ZclAttributeListener;
import com.zsmartsystems.zigbee.zcl.clusters.ZclBinaryInputBasicCluster;
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;

import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.thing.Channel;
import org.eclipse.smarthome.core.thing.ThingUID;
Expand All @@ -27,7 +25,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutionException;
import com.zsmartsystems.zigbee.CommandResult;
import com.zsmartsystems.zigbee.ZigBeeEndpoint;
import com.zsmartsystems.zigbee.zcl.ZclAttribute;
import com.zsmartsystems.zigbee.zcl.ZclAttributeListener;
import com.zsmartsystems.zigbee.zcl.clusters.ZclBinaryInputBasicCluster;
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType;

/**
* Converter for the binary input sensor.
Expand All @@ -40,6 +43,16 @@ public class ZigBeeConverterBinaryInput extends ZigBeeBaseChannelConverter imple

private ZclBinaryInputBasicCluster binaryInputCluster;

@Override
public Set<Integer> getImplementedClientClusters() {
return Collections.singleton(ZclBinaryInputBasicCluster.CLUSTER_ID);
}

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

@Override
public boolean initializeDevice() {
logger.debug("{}: Initialising device binary input cluster", endpoint.getIeeeAddress());
Expand Down Expand Up @@ -68,7 +81,8 @@ public boolean initializeDevice() {

@Override
public boolean initializeConverter() {
binaryInputCluster = (ZclBinaryInputBasicCluster) endpoint.getInputCluster(ZclBinaryInputBasicCluster.CLUSTER_ID);
binaryInputCluster = (ZclBinaryInputBasicCluster) endpoint
.getInputCluster(ZclBinaryInputBasicCluster.CLUSTER_ID);
if (binaryInputCluster == null) {
logger.error("{}: Error opening binary input cluster", endpoint.getIeeeAddress());
return false;
Expand Down Expand Up @@ -101,8 +115,8 @@ public Channel getChannel(ThingUID thingUID, ZigBeeEndpoint endpoint) {
.create(createChannelUID(thingUID, endpoint, ZigBeeBindingConstants.CHANNEL_NAME_BINARYINPUT),
ZigBeeBindingConstants.ITEM_TYPE_SWITCH)
.withType(ZigBeeBindingConstants.CHANNEL_BINARYINPUT)
.withLabel(ZigBeeBindingConstants.CHANNEL_LABEL_BINARYINPUT)
.withProperties(createProperties(endpoint)).build();
.withLabel(ZigBeeBindingConstants.CHANNEL_LABEL_BINARYINPUT).withProperties(createProperties(endpoint))
.build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.PercentType;
Expand Down Expand Up @@ -64,7 +62,7 @@ public class ZigBeeConverterColorTemperature extends ZigBeeBaseChannelConverter

@Override
public Set<Integer> getImplementedClientClusters() {
return Stream.of(ZclColorControlCluster.CLUSTER_ID).collect(Collectors.toSet());
return Collections.singleton(ZclColorControlCluster.CLUSTER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.thing.Channel;
Expand Down Expand Up @@ -49,7 +47,7 @@ public class ZigBeeConverterDoorLock extends ZigBeeBaseChannelConverter implemen

@Override
public Set<Integer> getImplementedClientClusters() {
return Stream.of(ZclDoorLockCluster.CLUSTER_ID).collect(Collectors.toSet());
return Collections.singleton(ZclDoorLockCluster.CLUSTER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.OnOffType;
Expand Down Expand Up @@ -57,7 +55,7 @@ public class ZigBeeConverterFanControl extends ZigBeeBaseChannelConverter implem

@Override
public Set<Integer> getImplementedClientClusters() {
return Stream.of(ZclFanControlCluster.CLUSTER_ID).collect(Collectors.toSet());
return Collections.singleton(ZclFanControlCluster.CLUSTER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.config.core.Configuration;
Expand Down Expand Up @@ -60,7 +58,7 @@ public class ZigBeeConverterIlluminance extends ZigBeeBaseChannelConverter imple

@Override
public Set<Integer> getImplementedClientClusters() {
return Stream.of(ZclIlluminanceMeasurementCluster.CLUSTER_ID).collect(Collectors.toSet());
return Collections.singleton(ZclIlluminanceMeasurementCluster.CLUSTER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
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.Power;

Expand Down Expand Up @@ -53,7 +51,7 @@ public class ZigBeeConverterMeasurementPower extends ZigBeeBaseChannelConverter

@Override
public Set<Integer> getImplementedClientClusters() {
return Stream.of(ZclElectricalMeasurementCluster.CLUSTER_ID).collect(Collectors.toSet());
return Collections.singleton(ZclElectricalMeasurementCluster.CLUSTER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
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.ElectricCurrent;

Expand Down Expand Up @@ -54,7 +52,7 @@ public class ZigBeeConverterMeasurementRmsCurrent extends ZigBeeBaseChannelConve

@Override
public Set<Integer> getImplementedClientClusters() {
return Stream.of(ZclElectricalMeasurementCluster.CLUSTER_ID).collect(Collectors.toSet());
return Collections.singleton(ZclElectricalMeasurementCluster.CLUSTER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
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.ElectricPotential;

Expand Down Expand Up @@ -54,7 +52,7 @@ public class ZigBeeConverterMeasurementRmsVoltage extends ZigBeeBaseChannelConve

@Override
public Set<Integer> getImplementedClientClusters() {
return Stream.of(ZclElectricalMeasurementCluster.CLUSTER_ID).collect(Collectors.toSet());
return Collections.singleton(ZclElectricalMeasurementCluster.CLUSTER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.thing.Channel;
Expand Down Expand Up @@ -47,7 +45,7 @@ public class ZigBeeConverterOccupancy extends ZigBeeBaseChannelConverter impleme

@Override
public Set<Integer> getImplementedClientClusters() {
return Stream.of(ZclOccupancySensingCluster.CLUSTER_ID).collect(Collectors.toSet());
return Collections.singleton(ZclOccupancySensingCluster.CLUSTER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.thing.Channel;
Expand Down Expand Up @@ -48,7 +46,7 @@ public class ZigBeeConverterRelativeHumidity extends ZigBeeBaseChannelConverter

@Override
public Set<Integer> getImplementedClientClusters() {
return Stream.of(ZclRelativeHumidityMeasurementCluster.CLUSTER_ID).collect(Collectors.toSet());
return Collections.singleton(ZclRelativeHumidityMeasurementCluster.CLUSTER_ID);
}

@Override
Expand Down
Loading

0 comments on commit 7ea289b

Please sign in to comment.