-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
[178] Support Discovery of USB dongles (for some Telegesis and one Ember dongle) #179
Merged
tomhoefer
merged 3 commits into
openhab:master
from
hsudbrock:178-support-discovery-of-usb-dongles
Apr 21, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src/main/java/"/> | ||
<classpathentry kind="src" path="src/main/java"/> | ||
<classpathentry kind="src" path="src/test/java"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...hab/binding/zigbee/ember/internal/discovery/ZigBeeEmberUsbSerialDiscoveryParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Copyright (c) 2014-2018 by the respective copyright holders. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.zigbee.ember.internal.discovery; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.openhab.binding.zigbee.ZigBeeBindingConstants.CONFIGURATION_BAUD; | ||
import static org.openhab.binding.zigbee.ZigBeeBindingConstants.CONFIGURATION_FLOWCONTROL; | ||
import static org.openhab.binding.zigbee.ZigBeeBindingConstants.CONFIGURATION_PORT; | ||
import static org.openhab.binding.zigbee.ZigBeeBindingConstants.FLOWCONTROL_CONFIG_SOFTWARE_XONXOFF; | ||
import static org.openhab.binding.zigbee.ember.EmberBindingConstants.THING_TYPE_EMBER; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.eclipse.smarthome.config.discovery.DiscoveryResult; | ||
import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder; | ||
import org.eclipse.smarthome.config.discovery.usbserial.UsbSerialDeviceInformation; | ||
import org.eclipse.smarthome.config.discovery.usbserial.UsbSerialDiscoveryParticipant; | ||
import org.eclipse.smarthome.core.thing.ThingTypeUID; | ||
import org.eclipse.smarthome.core.thing.ThingUID; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
/** | ||
* Discovery for ZigBee USB dongles, integrated in Eclipse SmartHome's USB-serial discovery by implementing | ||
* a component of type {@link UsbSerialDiscoveryParticipant}. | ||
* <p/> | ||
* Currently, this {@link UsbSerialDiscoveryParticipant} supports the ZigBee dongle 'BV AV2010/10' from Bitron Video. | ||
* | ||
* @author Henning Sudbrock - initial contribution | ||
*/ | ||
@Component(service = UsbSerialDiscoveryParticipant.class) | ||
public class ZigBeeEmberUsbSerialDiscoveryParticipant implements UsbSerialDiscoveryParticipant { | ||
|
||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = new HashSet<>(asList(THING_TYPE_EMBER)); | ||
|
||
public static final int SILICON_LABS_USB_VENDOR_ID = 0x10c4; | ||
public static final int BITRON_VIDEO_2010_10_PRODUCT_ID = 0x8b34; | ||
private static final int BITRON_VIDEO_2010_10_BAUD_RATE = 57600; | ||
private static final String BITRON_VIDEO_2010_10_DEFAULT_LABEL = "Bitron Video AV2010/10 Ember ZigBee Dongle"; | ||
|
||
@Override | ||
public Set<ThingTypeUID> getSupportedThingTypeUIDs() { | ||
return SUPPORTED_THING_TYPES; | ||
} | ||
|
||
@Override | ||
public @Nullable DiscoveryResult createResult(UsbSerialDeviceInformation deviceInformation) { | ||
if (isBitronVideoDongle(deviceInformation)) { | ||
return DiscoveryResultBuilder.create(createBitronVideoDongleThingType(deviceInformation)) | ||
.withLabel(createBitronVideoDongleLabel(deviceInformation)) | ||
.withRepresentationProperty(CONFIGURATION_PORT) | ||
.withProperty(CONFIGURATION_PORT, deviceInformation.getSerialPort()) | ||
.withProperty(CONFIGURATION_BAUD, BITRON_VIDEO_2010_10_BAUD_RATE) | ||
.withProperty(CONFIGURATION_FLOWCONTROL, FLOWCONTROL_CONFIG_SOFTWARE_XONXOFF) | ||
.build(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public @Nullable ThingUID getThingUID(UsbSerialDeviceInformation deviceInformation) { | ||
if (isBitronVideoDongle(deviceInformation)) { | ||
return createBitronVideoDongleThingType(deviceInformation); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
private boolean isBitronVideoDongle(UsbSerialDeviceInformation deviceInformation) { | ||
return deviceInformation.getVendorId() == SILICON_LABS_USB_VENDOR_ID | ||
&& deviceInformation.getProductId() == BITRON_VIDEO_2010_10_PRODUCT_ID; | ||
} | ||
|
||
private ThingUID createBitronVideoDongleThingType(UsbSerialDeviceInformation deviceInformation) { | ||
return new ThingUID(THING_TYPE_EMBER, deviceInformation.getSerialNumber()); | ||
} | ||
|
||
private @Nullable String createBitronVideoDongleLabel(UsbSerialDeviceInformation deviceInformation) { | ||
if (deviceInformation.getProduct() != null && !deviceInformation.getProduct().isEmpty()) { | ||
return deviceInformation.getProduct() + " (ZigBee USB dongle)"; | ||
} else { | ||
return BITRON_VIDEO_2010_10_DEFAULT_LABEL; | ||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...binding/zigbee/ember/internal/discovery/ZigBeeEmberUsbSerialDiscoveryParticipantTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Copyright (c) 2014-2018 by the respective copyright holders. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.zigbee.ember.internal.discovery; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.openhab.binding.zigbee.ZigBeeBindingConstants.CONFIGURATION_BAUD; | ||
import static org.openhab.binding.zigbee.ZigBeeBindingConstants.CONFIGURATION_PORT; | ||
import static org.openhab.binding.zigbee.ember.EmberBindingConstants.THING_TYPE_EMBER; | ||
import static org.openhab.binding.zigbee.ember.internal.discovery.ZigBeeEmberUsbSerialDiscoveryParticipant.BITRON_VIDEO_2010_10_PRODUCT_ID; | ||
import static org.openhab.binding.zigbee.ember.internal.discovery.ZigBeeEmberUsbSerialDiscoveryParticipant.SILICON_LABS_USB_VENDOR_ID; | ||
|
||
import org.eclipse.smarthome.config.discovery.DiscoveryResult; | ||
import org.eclipse.smarthome.config.discovery.usbserial.UsbSerialDeviceInformation; | ||
import org.eclipse.smarthome.core.thing.ThingUID; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openhab.binding.zigbee.ember.EmberBindingConstants; | ||
import org.openhab.binding.zigbee.ember.internal.discovery.ZigBeeEmberUsbSerialDiscoveryParticipant; | ||
|
||
/** | ||
* Unit tests for the {@link ZigBeeEmberUsbSerialDiscoveryParticipant}. | ||
*/ | ||
public class ZigBeeEmberUsbSerialDiscoveryParticipantTest { | ||
|
||
private ZigBeeEmberUsbSerialDiscoveryParticipant discoveryParticipant; | ||
|
||
@Before | ||
public void setup() { | ||
discoveryParticipant = new ZigBeeEmberUsbSerialDiscoveryParticipant(); | ||
} | ||
|
||
/** | ||
* If only USB vendor ID or only USB product ID or none of them matches, then no device is discovered. | ||
*/ | ||
@Test | ||
public void testNonEmberDongleNotDiscovered() { | ||
assertNull(discoveryParticipant.getThingUID(forUsbDongle(SILICON_LABS_USB_VENDOR_ID, 0x1234))); | ||
assertNull(discoveryParticipant.getThingUID(forUsbDongle(0xabcd, BITRON_VIDEO_2010_10_PRODUCT_ID))); | ||
assertNull(discoveryParticipant.getThingUID(forUsbDongle(0xabcd, 0x1234))); | ||
|
||
assertNull(discoveryParticipant.createResult(forUsbDongle(SILICON_LABS_USB_VENDOR_ID, 0x1234))); | ||
assertNull(discoveryParticipant.createResult(forUsbDongle(0xabcd, BITRON_VIDEO_2010_10_PRODUCT_ID))); | ||
assertNull(discoveryParticipant.createResult(forUsbDongle(0xabcd, 0x1234))); | ||
} | ||
|
||
/** | ||
* For matching USB vendor and product ID, a suitable thingUID is returned. | ||
*/ | ||
@Test | ||
public void testEmberDongleDiscoveredThingUID() { | ||
ThingUID thingUID = discoveryParticipant.getThingUID( | ||
forUsbDongle(SILICON_LABS_USB_VENDOR_ID, BITRON_VIDEO_2010_10_PRODUCT_ID, "serial", "/dev/ttyUSB0")); | ||
|
||
assertNotNull(thingUID); | ||
assertEquals(thingUID, new ThingUID(THING_TYPE_EMBER, "serial")); | ||
} | ||
|
||
/** | ||
* For matching USB vendor and product ID, a suitable discovery result is returned. | ||
*/ | ||
@Test | ||
public void testEmberDongleDiscoveredDiscoveryResult() { | ||
DiscoveryResult discoveryResult = discoveryParticipant.createResult( | ||
forUsbDongle(SILICON_LABS_USB_VENDOR_ID, BITRON_VIDEO_2010_10_PRODUCT_ID, "serial", "/dev/ttyUSB0")); | ||
|
||
assertNotNull(discoveryResult); | ||
assertEquals(discoveryResult.getThingUID(), new ThingUID(THING_TYPE_EMBER, "serial")); | ||
assertNotNull(discoveryResult.getLabel()); | ||
assertEquals(discoveryResult.getRepresentationProperty(), CONFIGURATION_PORT); | ||
assertEquals(discoveryResult.getProperties().get(CONFIGURATION_PORT), "/dev/ttyUSB0"); | ||
assertNotNull(discoveryResult.getProperties().get(CONFIGURATION_BAUD)); | ||
} | ||
|
||
private UsbSerialDeviceInformation forUsbDongle(int vendorId, int productId, String serial, String device) { | ||
return new UsbSerialDeviceInformation(vendorId, productId, serial, null, null, 0, null, device); | ||
} | ||
|
||
private UsbSerialDeviceInformation forUsbDongle(int vendorId, int productId) { | ||
return new UsbSerialDeviceInformation(vendorId, productId, null, null, null, 0, null, "/dev/ttyUSB0"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src/main/java/"/> | ||
<classpathentry kind="src" path="src/main/java"/> | ||
<classpathentry kind="src" path="src/test/java"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...ing/zigbee/telegesis/internal/discovery/ZigBeeTelegesisUsbSerialDiscoveryParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/** | ||
* Copyright (c) 2014-2018 by the respective copyright holders. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.zigbee.telegesis.internal.discovery; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.openhab.binding.zigbee.ZigBeeBindingConstants.CONFIGURATION_BAUD; | ||
import static org.openhab.binding.zigbee.ZigBeeBindingConstants.CONFIGURATION_PORT; | ||
import static org.openhab.binding.zigbee.telegesis.TelegesisBindingConstants.THING_TYPE_TELEGESIS; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.eclipse.smarthome.config.discovery.DiscoveryResult; | ||
import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder; | ||
import org.eclipse.smarthome.config.discovery.usbserial.UsbSerialDeviceInformation; | ||
import org.eclipse.smarthome.config.discovery.usbserial.UsbSerialDiscoveryParticipant; | ||
import org.eclipse.smarthome.core.thing.ThingTypeUID; | ||
import org.eclipse.smarthome.core.thing.ThingUID; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
/** | ||
* Discovery for ZigBee USB dongles, integrated in Eclipse SmartHome's USB-serial discovery by implementing | ||
* a component of type {@link UsbSerialDiscoveryParticipant}. | ||
* <p/> | ||
* Currently, this {@link UsbSerialDiscoveryParticipant} supports three USB dongles built around | ||
* a SiLabs EM357 ZigBee chip and a CP210x USB to UART bridge. | ||
* | ||
* @author Henning Sudbrock - initial contribution | ||
*/ | ||
@Component(service = UsbSerialDiscoveryParticipant.class) | ||
public class ZigBeeTelegesisUsbSerialDiscoveryParticipant implements UsbSerialDiscoveryParticipant { | ||
|
||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = new HashSet<>(asList(THING_TYPE_TELEGESIS)); | ||
|
||
public static final int SILICON_LABS_USB_VENDOR_ID = 0x10c4; | ||
|
||
/** | ||
* For the {@link ZigBeeTelegesisUsbSerialDiscoveryParticipant#SILICON_LABS_USB_VENDOR_ID}, this USB product ID | ||
* is used for the Telegesis ZigBee dongle model ETRX3USB+8M, as well as for one version of the QIVICON ZigBee stick | ||
* (which is also produced by Telegesis). | ||
*/ | ||
public static final int QIVICON_DONGLE_V1_AND_TELEGESIS_USB_PRODUCT_ID = 0x8293; | ||
|
||
/** | ||
* For the {@link ZigBeeTelegesisUsbSerialDiscoveryParticipant#SILICON_LABS_USB_VENDOR_ID}, this USB product ID | ||
* is used for one version of the QIVICON ZigBee stick. | ||
*/ | ||
public static final int QIVICON_DONGLE_V2_USB_PRODUCT_ID = 0x89fb; | ||
|
||
private static final int QIVICON_DONGLE_BAUD_RATE = 19200; | ||
|
||
private static final String QIVICON_DONGLE_DEFAULT_LABEL = "Telegesis ZigBee Dongle"; | ||
|
||
@Override | ||
public Set<ThingTypeUID> getSupportedThingTypeUIDs() { | ||
return SUPPORTED_THING_TYPES; | ||
} | ||
|
||
@Override | ||
public @Nullable DiscoveryResult createResult(UsbSerialDeviceInformation deviceInformation) { | ||
if (isQiviconTelegesisDongle(deviceInformation)) { | ||
return DiscoveryResultBuilder.create(createQiviconTelegesisDongleThingType(deviceInformation)) | ||
.withLabel(createQiviconTelegesisDongleLabel(deviceInformation)) | ||
.withRepresentationProperty(CONFIGURATION_PORT) | ||
.withProperty(CONFIGURATION_PORT, deviceInformation.getSerialPort()) | ||
.withProperty(CONFIGURATION_BAUD, QIVICON_DONGLE_BAUD_RATE).build(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public @Nullable ThingUID getThingUID(UsbSerialDeviceInformation deviceInformation) { | ||
if (isQiviconTelegesisDongle(deviceInformation)) { | ||
return createQiviconTelegesisDongleThingType(deviceInformation); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
private boolean isQiviconTelegesisDongle(UsbSerialDeviceInformation deviceInformation) { | ||
return deviceInformation.getVendorId() == SILICON_LABS_USB_VENDOR_ID | ||
&& (deviceInformation.getProductId() == QIVICON_DONGLE_V1_AND_TELEGESIS_USB_PRODUCT_ID | ||
|| deviceInformation.getProductId() == QIVICON_DONGLE_V2_USB_PRODUCT_ID); | ||
} | ||
|
||
private ThingUID createQiviconTelegesisDongleThingType(UsbSerialDeviceInformation deviceInformation) { | ||
return new ThingUID(THING_TYPE_TELEGESIS, deviceInformation.getSerialNumber()); | ||
} | ||
|
||
private @Nullable String createQiviconTelegesisDongleLabel(UsbSerialDeviceInformation deviceInformation) { | ||
if (deviceInformation.getProduct() != null && !deviceInformation.getProduct().isEmpty()) { | ||
return deviceInformation.getProduct() + " (ZigBee USB dongle)"; | ||
} else { | ||
return QIVICON_DONGLE_DEFAULT_LABEL; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a minor comment - such constants have been documented for the Telegesis dongle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I commented only those constants for the Telegesis dongle where I found documentation useful (i.e., those constants where there are multiple different dongles which might or might not have the same product ID - having in mind that there are two dongles that look alike but have different product IDs, and two dongles that don't look alike but have the same product ID, which I wanted to clarify using those constants). Here, I don't think that additional documentation is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok