codewars Bluetooth

class codewars.bluetooth.Bluetooth[source]

This is a simple wrapper of the python package PyBluez.

Note

Do not forget to intstall the dependency. sudo apt-get install libbluetooth-dev

discover(duration: int = 10, flush_cache: bool = True, lookup_names: bool = False)[source]

Look for available bluetooth devices, returns a list with available bt adresses

Parameters
  • duration – Default: 10 Type: int Description: The duration of the time to search for new devices

  • flush_cach – Default: True Type: bool Description: Flush found devices when discovering again

  • lookup_names – Default: False Type: bool Description: Discover the names of the devicovered devices

Returns

Type: List Content: Strings Description: A list of BT adresses that are discovered. If None are discoverd the list will be empty

Return type

List

Note

When turning lookup_adress to True the list that returns will contain Tuples instead of Strings.

information(btAddr: list = [])[source]

Fetch information about a bluetooth adress

Parameters

btAddr – Default: [] Type: List Description: List of Bluetooth adressess

Returns

Type: List Content: Dict Description: Information for each inserted btAddr

Dict content:
  • date : Scan run date => Str

  • adress : BT Adress => Str

  • valid : Is adress valid? => Bool

Return type

List

Note

If nothing is found this will return None

isDiscovering()[source]

Check if this class is currently discovering

Returns

True: When this class is currently looking for devices False: When this class is not trying to find new devices

Return type

Bool

isValid(btAddr: str)[source]

Check if a BlueTooth adress is valid

Parameters

btAddr – Type: String Description: A bluetooth adress

Returns

True: When adress is valid False: When adress is invalid

Return type

Bool

run_until_discovered(duration=10)[source]

Runs until bluetooth device is discovered. When a device is found execute the scan method.

Parameters

duration – Default: 10 Type: int Description: The duration of the time to search for new devices

Note

You can set the duration for each search in this method. You cannot time the duration of the full discovery. This method ONLY returns when a discovery has been made.

Returns

Type: List Content: Same content as the method information returns

Return type

List

scan()[source]

Scan fetched nearby devices, when this class gets initialized it scans once. This take up about 10 seconds. If no other method is declared this method scans the devices which where gathered while initializing.

If however discover for example is used then this method will scan those results.

Returns

Type: List Content: Same content as the method information returns

Return type

List