def findCharacteristics(self, mac, conn=''): logging.debug("Searching characteristics") if conn == '': conn = Connector(mac) conn.connect() if not conn.isconnected: conn.connect() if not conn.isconnected: return value = '' characteristics = [] try: characteristics = conn.getCharacteristics(0x0001, retry=2) except Exception as e: logging.debug(str(e)) try: characteristics = conn.getCharacteristics(0x0001, retry=2) except Exception as e: logging.debug(str(e)) try: characteristics = conn.getCharacteristics(0x0001, retry=2) except Exception as e: logging.debug(str(e)) conn.disconnect() color_characteristic = next( iter( filter(lambda el: el.uuid == COLOR_CHARACTERISTIC_UUID, characteristics))) effect_characteristic = next( iter( filter(lambda el: el.uuid == EFFECT_CHARACTERISTIC_UUID, characteristics))) logging.debug('Found ' + hex(color_characteristic.getHandle()) + ' ' + hex(effect_characteristic.getHandle())) return [ hex(color_characteristic.getHandle()), hex(effect_characteristic.getHandle()) ]
def findVersion(self,mac): conn = Connector(mac) conn.connect() if not conn.isconnected: conn.connect() if not conn.isconnected: return value='' characteristics = conn.getCharacteristics() for char in characteristics: try: if char.supportsRead(): valueChar = char.read() if valueChar and valueChar[0:3] == 'BTL' and len(valueChar)>6 and len(valueChar)>len(value): value = valueChar except Exception,e: continue