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

Bluetooth Smart binding #2489

Closed
wants to merge 2 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+44 −7
Diff settings

Always

Just for now

Viewing a subset of changes. View all
Prev

[bluetoothsmart] WIP: preparing for the big merge with the parallel PR

Signed-off-by: Vlad Kolotov <vkolotov@gmail.com>
  • Loading branch information...
vkolotov committed Aug 18, 2017
commit 11b55d74c1e12d19c9e841a934535a80ecd22560
@@ -6,7 +6,7 @@ Bundle-Vendor: openHAB
Bundle-Version: 2.2.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ClassPath: .,
lib/tinyb.jar,lib/bluetooth-utils-1.1.jar,lib/bluetooth-gatt-parser-1.3.jar,lib/bluetooth-manager-1.0.jar,lib/commons-beanutils-1.9.3.jar
lib/tinyb.jar,lib/bluetooth-utils-1.4-SNAPSHOT.jar,lib/bluetooth-gatt-parser-1.4-SNAPSHOT.jar,lib/bluetooth-manager-1.1-SNAPSHOT.jar,lib/bluetooth-manager-tinyb-1.0-SNAPSHOT.jar,lib/commons-beanutils-1.9.3.jar
Bundle-NativeCode: lib/libjavatinyb.so; osname=Linux; processor=ARM_le, *
Import-Package: org.openhab.binding.bluetoothsmart,
org.openhab.binding.bluetoothsmart.handler,
@@ -7,8 +7,9 @@ bin.includes = META-INF/,\
about.html,\
lib/tinyb.jar,\
lib/libjavatinyb.so,\
lib/bluetooth-utils-1.1.jar,\
lib/bluetooth-gatt-parser-1.3.jar,\
lib/bluetooth-manager-1.0.jar,\
lib/bluetooth-utils-1.4-SNAPSHOT.jar,\
lib/bluetooth-gatt-parser-1.4-SNAPSHOT.jar,\
lib/bluetooth-manager-1.1-SNAPSHOT.jar,\
lib/bluetooth-manager-tinyb-1.0-SNAPSHOT.jar,\
lib/commons-beanutils-1.9.3.jar
Binary file not shown.
@@ -1,5 +1,8 @@
package org.openhab.binding.bluetoothsmart;
/**
* @author Vlad Kolotov
*/
public interface BluetoothSmartDiscoveryService {
}
@@ -21,6 +21,9 @@
import org.sputnikdev.bluetooth.manager.GattCharacteristic;
import org.sputnikdev.bluetooth.manager.GattService;
/**
* @author Vlad Kolotov
*/
public class BluetoothSmartChannelBuilder {
private Logger logger = LoggerFactory.getLogger(BluetoothSmartChannelBuilder.class);
@@ -74,7 +77,7 @@ public BluetoothSmartChannelBuilder(BluetoothSmartHandler handler) {
}
private Channel buildChannel(Thing thing, GattService service, GattCharacteristic characteristic, Field field) {
URL channelURL = characteristic.getURL().copyWith(field.getName());//this.handler.getURL().copyWith(service.getUUID(), characteristic.getUUID(), field.getName());
URL channelURL = characteristic.getURL().copyWithField(field.getName());//this.handler.getURL().copyWith(service.getUUID(), characteristic.getUUID(), field.getName());
ChannelUID channelUID = new ChannelUID(thing.getUID(), BluetoothSmartUtils.getChannelUID(channelURL));
ChannelTypeUID channelTypeUID = new ChannelTypeUID(BluetoothSmartBindingConstants.BINDING_ID,
@@ -20,6 +20,9 @@
import org.sputnikdev.bluetooth.manager.BluetoothGovernor;
import org.sputnikdev.bluetooth.manager.BluetoothManager;
/**
* @author Vlad Kolotov
*/
class BluetoothSmartHandler<T extends BluetoothGovernor> extends BaseThingHandler {
private Logger logger = LoggerFactory.getLogger(BluetoothSmartHandler.class);
@@ -2,6 +2,9 @@
import org.eclipse.smarthome.core.library.types.OnOffType;
/**
* @author Vlad Kolotov
*/
class BooleanTypeChannelHandler extends SingleChannelHandler<Boolean, OnOffType> {
BooleanTypeChannelHandler(BluetoothSmartHandler handler, String channelID, boolean persistent) {
@@ -5,6 +5,9 @@
import org.eclipse.smarthome.core.types.State;
import org.sputnikdev.bluetooth.URL;
/**
* @author Vlad Kolotov
*/
public interface ChannelHandler {
void init();
@@ -5,6 +5,9 @@
import org.eclipse.smarthome.core.library.types.DateTimeType;
/**
* @author Vlad Kolotov
*/
class DateTimeChannelHandler extends SingleChannelHandler<Date, DateTimeType> {
DateTimeChannelHandler(BluetoothSmartHandler handler, String channelID) {
@@ -2,6 +2,9 @@
import org.eclipse.smarthome.core.library.types.DecimalType;
/**
* @author Vlad Kolotov
*/
class IntegerTypeChannelHandler extends SingleChannelHandler<Integer, DecimalType> {
IntegerTypeChannelHandler(BluetoothSmartHandler handler, String channelID, boolean persistent) {
@@ -26,6 +26,9 @@
import org.sputnikdev.bluetooth.manager.CharacteristicGovernor;
import org.sputnikdev.bluetooth.manager.ValueListener;
/**
* @author Vlad Kolotov
*/
class MultiChannelHandler implements ChannelHandler, ValueListener {
private Logger logger = LoggerFactory.getLogger(MultiChannelHandler.class);
@@ -156,11 +159,11 @@ private State convert(State state, Class<? extends State> typeClass) {
private Channel getChannel(FieldHolder fieldHolder) {
return this.handler.getThing().getChannel(
BluetoothSmartUtils.getChannelUID(url.copyWith(fieldHolder.getField().getName())));
BluetoothSmartUtils.getChannelUID(url.copyWithField(fieldHolder.getField().getName())));
}
private Item getItem(FieldHolder fieldHolder) {
String itemID = BluetoothSmartUtils.getItemUID(url.copyWith(fieldHolder.getField().getName()));
String itemID = BluetoothSmartUtils.getItemUID(url.copyWithField(fieldHolder.getField().getName()));
try {
return this.handler.getItemRegistry().getItem(itemID);
} catch (ItemNotFoundException e) {
@@ -12,6 +12,9 @@
import org.sputnikdev.bluetooth.URL;
import org.sputnikdev.bluetooth.manager.NotReadyException;
/**
* @author Vlad Kolotov
*/
abstract class SingleChannelHandler<V, S extends Command> implements ChannelHandler {
private Logger logger = LoggerFactory.getLogger(SingleChannelHandler.class);
@@ -33,6 +33,8 @@
import org.sputnikdev.bluetooth.gattparser.BluetoothGattParserFactory;
import org.sputnikdev.bluetooth.manager.BluetoothManager;
import org.sputnikdev.bluetooth.manager.impl.BluetoothManagerFactory;
import org.sputnikdev.bluetooth.manager.impl.BluetoothObjectFactory;
import org.sputnikdev.bluetooth.manager.impl.TinyBFactory;
import static org.openhab.binding.bluetoothsmart.BluetoothSmartBindingConstants.THING_TYPE_ADAPTER;
import static org.openhab.binding.bluetoothsmart.BluetoothSmartBindingConstants.THING_TYPE_BLE;
@@ -79,6 +81,7 @@ protected void activate(ComponentContext componentContext) {
extensionFolder = System.getProperty("user.home") + File.separator + ".bluetooth_smart";
}
BundleContext bundleContext = componentContext.getBundleContext();
BluetoothObjectFactory.registerFactory(new TinyBFactory());
bluetoothManager = BluetoothManagerFactory.getManager();
if (refreshRate != null && NumberUtils.isNumber(refreshRate)) {
bluetoothManager.setRefreshRate(NumberUtils.toInt(refreshRate));
@@ -6,6 +6,9 @@
import org.openhab.binding.bluetoothsmart.BluetoothSmartBindingConstants;
import org.sputnikdev.bluetooth.URL;
/**
* @author Vlad Kolotov
*/
public class BluetoothSmartUtils {
private static final String MAC_PART_REGEXP = "(\\w{2}(?=(\\w{2})))";
@@ -20,6 +20,9 @@
import org.sputnikdev.bluetooth.manager.DiscoveredDevice;
import org.sputnikdev.bluetooth.manager.DiscoveredObject;
/**
* @author Vlad Kolotov
*/
public class BluetoothSmartDiscoveryServiceImpl extends AbstractDiscoveryService
implements BluetoothSmartDiscoveryService, DeviceDiscoveryListener, AdapterDiscoveryListener {
ProTip! Use n and p to navigate between commits in a pull request.