Пример #1
0
 def buildFromScanEntry(scanEntry: ScanEntry) -> Optional["OralBAdvertise"]:
     vendorSpecificData = scanEntry.getValueText(ScanEntry.MANUFACTURER)
     parser = OralBAdvertise(vendorSpecificData)
     if parser.isValid:
         return parser
     else:
         return None
Пример #2
0
    def handleDiscovery(self, device: ScanEntry, isNew: bool, isData: bool):
        if not isNew:
            return

        device_name = device.getValueText(ScanEntry.COMPLETE_LOCAL_NAME)

        if not isinstance(device_name,
                          str) or not device_name.startswith("Snooz"):
            return

        advertisement = device.getValue(ScanEntry.MANUFACTURER)

        # unexpected data
        if len(advertisement) < 3:
            return

        if advertisement[:3] == b"\xFF\xFF\x08":
            _LOGGER.warning(
                f"Discovered {device_name} ({device.addr}) but it is not in pairing mode."
            )
            return

        token = b64encode(advertisement[3:]).decode("UTF-8")

        snooz_device = DiscoveredSnooz(device_name, token, device)

        self.devices.append(snooz_device)
Пример #3
0
    def _get_dev_name_from_scan_entry(self, dev: ScanEntry):
        dev_name = None

        # Attempt to load from Scandata
        for scan_data in dev.getScanData():
            if scan_data[1] == 'Short Local Name':
                dev_name = scan_data[2]

        # Iterate through the dataTags if the above fails
        if dev_name is None:
            try:
                for idx, label in scan_data.dataTags:
                    if label == 'Short Local Name':
                        dev_name = dev.getValueText(idx)
            except AttributeError:
                pass

        # Load using handles if the above fails
        if dev_name is None:
            dev_name = dev.getValueText(8)

        return dev_name
Пример #4
0
 def is_turn_touch(device: btle.ScanEntry) -> bool:
     """Determine whether a ScanEntry (device) is a Turn Touch."""
     short_name = device.getValueText(BLE_SHORT_DEVICE_NAME)
     name = device.getValueText(BLE_COMPLETE_DEVICE_NAME)
     return name == TT_DEVICE_NAME or short_name == TT_SHORT_DEVICE_NAME
Пример #5
0
    def relay_ble_advertisement(self, scanEntry:  ScanEntry): 
        """
        Send the BLE packet to the connected service running on iOS 
        """
        ### Message format 
        # 1 byte type - 4 bytes message length - message 
        ###

        name = scanEntry.getValueText( ScanEntry.COMPLETE_LOCAL_NAME)
        if not name: 
            name = scanEntry.getValueText( ScanEntry.SHORT_LOCAL_NAME)
        
        # services_16 = scanEntry.getValueText(ScanEntry.INCOMPLETE_16B_SERVICES)
        # services_32 = scanEntry.getValueText(ScanEntry.INCOMPLETE_32B_SERVICES)
        # services_128 = scanEntry.getValueText(ScanEntry.INCOMPLETE_128B_SERVICES)
        # print("Services 16B: \n\t{}\nServices 32B: \n\t{}\nServices 128B: \n\t{}".format(services_16, services_32 , services_128 ))
        DBG("Raw Data: {}".format(scanEntry.rawData), logLevel=LogLevel.DEBUG)
        raw_data_hex = ""
        if scanEntry.rawData: 
            raw_data_hex = scanEntry.rawData.hex()

        packet_content = {
            "manufacturerDataHex": scanEntry.getValueText(ScanEntry.MANUFACTURER), 
            "macAddress": scanEntry.addr, 
            "rssi": scanEntry.rssi,
            "name": name, 
            "flags": scanEntry.getValueText( ScanEntry.FLAGS), 
            "addressType": scanEntry.addrType,
            "connectable": scanEntry.connectable, 
            "rawData": raw_data_hex, 
            #"scanData": {tag: scanEntry.getValueText(k) for k, tag in scanEntry.dataTags.items()}
        }

        # Check for additional content in this advertisement 

        # Get service UUIDs 
        serviceUUIDs = list()
        if scanEntry.getValueText(ScanEntry.INCOMPLETE_16B_SERVICES):
            serviceUUIDs.append(scanEntry.getValueText(ScanEntry.INCOMPLETE_16B_SERVICES))

        if scanEntry.getValueText(ScanEntry.INCOMPLETE_32B_SERVICES):
            serviceUUIDs.append(scanEntry.getValueText(ScanEntry.INCOMPLETE_32B_SERVICES))
        
        if scanEntry.getValueText(ScanEntry.INCOMPLETE_128B_SERVICES):
            serviceUUIDs.append(scanEntry.getValueText(ScanEntry.INCOMPLETE_128B_SERVICES))

        if scanEntry.getValueText(ScanEntry.COMPLETE_16B_SERVICES):
            serviceUUIDs.append(scanEntry.getValueText(ScanEntry.COMPLETE_16B_SERVICES))

        if scanEntry.getValueText(ScanEntry.COMPLETE_32B_SERVICES):
            serviceUUIDs.append(scanEntry.getValueText(ScanEntry.COMPLETE_32B_SERVICES))

        if scanEntry.getValueText(ScanEntry.COMPLETE_128B_SERVICES):
            serviceUUIDs.append(scanEntry.getValueText(ScanEntry.COMPLETE_128B_SERVICES))

        if len(serviceUUIDs) > 0: 
            packet_content["serviceUUIDs"] = serviceUUIDs 

        # Get service data 
        if scanEntry.getValueText(ScanEntry.SERVICE_DATA_16B): 
            packet_content["serviceData16Bit"] = scanEntry.getValueText(ScanEntry.SERVICE_DATA_16B)
        
        if scanEntry.getValueText(ScanEntry.SERVICE_DATA_32B): 
            packet_content["serviceData32Bit"] = scanEntry.getValueText(ScanEntry.SERVICE_DATA_32B)
        
        if scanEntry.getValueText(ScanEntry.SERVICE_DATA_128B): 
            packet_content["serviceData128Bit"] = scanEntry.getValueText(ScanEntry.SERVICE_DATA_128B)

        
        DBG("Encoding json: ", packet_content)
        json_packet = json.dumps(packet_content).encode() 
        
        # Message type for advertisements is 0
        self.send_packet_over_socket(packet_type=0, packet_data=json_packet)