<commit_before>import abc

# Eddystone Protocol specification
# https://github.com/google/eddystone/blob/master/protocol-specification.md
# Bluetooth Service UUID used by Eddystone
#  16bit: 0xfeaa
#  64bit: 0000FEAA-0000-1000-8000-00805F9B34FB

eddystone_uuid = '0000FEAA-0000-1000-8000-00805F9B34FB'


class BleCommunication(object):
    '''Bluetooth LE communication'''
    __metaclass__ = abc.ABCMeta

    @abc.abstractmethod
    def get_data(mac):
        pass

    @abc.abstractmethod
    def find_ble_devices():
        pass


class BleCommunicationDummy(BleCommunication):
    '''TODO: Find some working BLE implementation for Windows and OSX'''

    @staticmethod
    def get_data(mac):
        return '0x0201060303AAFE1616AAFE10EE037275752E7669232A6843744641424644'

    @staticmethod
    def find_ble_devices():
        return [
                ('BC-2C-6A-1E-59-3D', ''),
                ('AA-2C-6A-1E-59-3D', '')
        ]


class BleCommunicationNix(BleCommunication):
    '''Bluetooth LE communication for Linux'''

    @staticmethod
    def get_data(mac):
        # Do imports inside functions so they are not loaded during init
        from gattlib import GATTRequester

        try:
            req = GATTRequester(mac, True)
            data = req.read_by_uuid(eddystone_uuid)[0]
            req.disconnect()
        except Exception as ex:
            print(ex)
            data = None

        return data

    @staticmethod
    def find_ble_devices():
        # Do imports inside functions so they are not loaded during init
        from gattlib import DiscoveryService

        service = DiscoveryService("hci0")
        devices = service.discover(2)
        return devices.items()
<commit_msg>Added device id to GATTRequester<commit_after>import abc

# Eddystone Protocol specification
# https://github.com/google/eddystone/blob/master/protocol-specification.md
# Bluetooth Service UUID used by Eddystone
#  16bit: 0xfeaa (65194)
#  64bit: 0000FEAA-0000-1000-8000-00805F9B34FB

eddystone_uuid = '0000FEAA-0000-1000-8000-00805F9B34FB'
eddystone_handle = 65194

class BleCommunication(object):
    '''Bluetooth LE communication'''
    __metaclass__ = abc.ABCMeta

    @abc.abstractmethod
    def get_data(mac):
        pass

    @abc.abstractmethod
    def find_ble_devices():
        pass


class BleCommunicationDummy(BleCommunication):
    '''TODO: Find some working BLE implementation for Windows and OSX'''

    @staticmethod
    def get_data(mac):
        return '0x0201060303AAFE1616AAFE10EE037275752E7669232A6843744641424644'

    @staticmethod
    def find_ble_devices():
        return [
            ('BC-2C-6A-1E-59-3D', ''),
            ('AA-2C-6A-1E-59-3D', '')
        ]


class BleCommunicationNix(BleCommunication):
    '''Bluetooth LE communication for Linux'''

    @staticmethod
    def get_data(mac):
        # Do imports inside functions so they are not loaded during init
        from gattlib import GATTRequester

        print('Reading data from: ' + mac)

        try:
            req = GATTRequester(mac, False, "hci0")
            req.connect()
            data = req.read_by_uuid(eddystone_uuid)[0]
            req.disconnect()
        except Exception as ex:
            print(ex)
            data = None

        return data

    @staticmethod
    def find_ble_devices():
        # Do imports inside functions so they are not loaded during init
        from gattlib import DiscoveryService

        service = DiscoveryService("hci0")
        devices = service.discover(2)
        return devices.items()

{'fraction_non_alphanumeric': 0.08806978052898143, 'fraction_numerical': 0.06893640967923466, 'mean_word_length': 2.6725206611570247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1195927', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1090, 'n_words': 255}