how to stop printing result again and again. So how to stop getting value again and again

46 Views Asked by At
import gatt

class AnyDeviceManager(gatt.Device):
    def device_discovered(self,device):
        print("Discovered [%s] %s" % (device.mac_address,device.alias()))
    
manager = AnyDeviceManager(adapter_name='hci0')
manager.start_discovery()
manager.run()

how to stop printing results again and again. So how do stop getting value again and again

1

There are 1 best solutions below

0
ukBaz On

It would seem that you need to track which devices have already been discovered.

There are different ways to do this depending what you want to do with the information.

One example would be:

class AnyDeviceManager(gatt.Device):
    device = {}

    def device_discovered(self, device):
        if device.mac_address not in AnyDeviceManager.device:
            print("Discovered [%s] %s" % (device.mac_address, device.alias()))
            AnyDeviceManager.device[device.mac_address] = device