Shared¶
Tools¶
Utility functions for python-bluezero.
-
bluezero.tools.
bitwise_and_2lists
(list1, list2)¶ Takes two bit patterns of equal length and performs the logical inclusive AND operation on each pair of corresponding bits
-
bluezero.tools.
bitwise_or_2lists
(list1, list2)¶ Takes two bit patterns of equal length and performs the logical inclusive OR operation on each pair of corresponding bits
-
bluezero.tools.
bitwise_xor_2lists
(list1, list2)¶ Takes two bit patterns of equal length and performs the logical inclusive XOR operation on each pair of corresponding bits
-
bluezero.tools.
bytes_to_xyz
(byte_array)¶ Split 6 byte long in integers representing x, y & z
Parameters: byte_array – Returns:
-
bluezero.tools.
create_module_logger
(module_name)¶ helper function to create logger in Bluezero modules
-
bluezero.tools.
get_fn_parameters
(fn)¶ return the number of input parameters of the fn , None on error
-
bluezero.tools.
int_to_uint16
(value_in)¶ Convert integer to Unsigned 16 bit little endian integer
Parameters: value_in – Integer < 65535 (0xFFFF) Returns:
-
bluezero.tools.
int_to_uint32
(value_in)¶ Convert integer to unsigned 32-bit (little endian)
Parameters: value_in – Returns:
-
bluezero.tools.
sint16_to_int
(byte_array)¶ Convert a signed 16-bit integer to integer
Parameters: byte_array – Returns:
-
bluezero.tools.
url_to_advert
(url, frame_type, tx_power)¶ Encode as specified https://github.com/google/eddystone/blob/master/eddystone-url/README.md
Parameters: url – Returns:
Constants¶
Global constants file for the python-bluezero project.
This file is a single location for the different object paths that are used as constants around the python-bluezero library.
Example: |
---|
from bluezero import constants
my_function(constants.CONST_1, constants.CONST_2)
-
bluezero.constants.
ADAPTER_INTERFACE
= 'org.bluez.Adapter1'¶ BlueZ DBus adapter interface
-
bluezero.constants.
BLUEZ_SERVICE_NAME
= 'org.bluez'¶ BlueZ DBus Service Name
-
bluezero.constants.
DBUS_OM_IFACE
= 'org.freedesktop.DBus.ObjectManager'¶ The DBus Object Manager interface
-
bluezero.constants.
DBUS_PROP_IFACE
= 'org.freedesktop.DBus.Properties'¶ DBus Properties interface
-
bluezero.constants.
DEVICE_INTERFACE
= 'org.bluez.Device1'¶ BlueZ DBus device Interface
-
bluezero.constants.
GATT_CHRC_IFACE
= 'org.bluez.GattCharacteristic1'¶ BlueZ DBus GATT Characteristic Interface
-
bluezero.constants.
GATT_DESC_IFACE
= 'org.bluez.GattDescriptor1'¶ BlueZ DBus GATT Descriptor Interface
-
bluezero.constants.
GATT_MANAGER_IFACE
= 'org.bluez.GattManager1'¶ BlueZ DBus GATT manager Interface
-
bluezero.constants.
GATT_PROFILE_IFACE
= 'org.bluez.GattProfile1'¶ BlueZ DBus GATT Profile Interface
-
bluezero.constants.
GATT_SERVICE_IFACE
= 'org.bluez.GattService1'¶ BlueZ DBus GATT Service Interface
-
bluezero.constants.
LE_ADVERTISEMENT_IFACE
= 'org.bluez.LEAdvertisement1'¶ BlueZ DBus Advertisement Interface
-
bluezero.constants.
LE_ADVERTISING_MANAGER_IFACE
= 'org.bluez.LEAdvertisingManager1'¶ BlueZ DBus Advertising Manager Interface
-
bluezero.constants.
MEDIA_PLAYER_IFACE
= 'org.bluez.MediaPlayer1'¶ BlueZ DBus Media player Interface
DBus Tools¶
Utility functions for DBus use within Bluezero.
-
bluezero.dbus_tools.
bluez_experimental_mode
()¶ Return True if the BlueZ daemon service is in experimental mode :return: True if experimental enabled
-
bluezero.dbus_tools.
bluez_version
()¶ get the version of the BlueZ daemon being used on the system
Returns: String of BlueZ version
-
bluezero.dbus_tools.
bytes_to_dbusarray
(bytesarray)¶ Helper function to represent Python bytearray as D-Bus Byte array
-
bluezero.dbus_tools.
get
(dbus_prop_obj, dbus_iface, prop_name, default=None)¶ Get a property from a D-Bus object and provide a default if the property does not exist. Similar to the “get” functionality on a python dictionary. :param dbus_prop_obj: The output object from dbus_tools.get_props :param dbus_iface: D-Bus Interface name e.g. ‘org.bluez.Device1’ :param prop_name: The name of the property :param default: What value to return if the property does not exist. :return: The property value if it exists or the default value
-
bluezero.dbus_tools.
get_adapter_address_from_dbus_path
(path)¶ Return the address of the adapter from the a DBus path
-
bluezero.dbus_tools.
get_dbus_iface
(iface, dbus_obj)¶ Return the DBus interface object for given interface and DBus object :param iface: :param dbus_obj: :return:
-
bluezero.dbus_tools.
get_dbus_obj
(dbus_path)¶ Get the the DBus object for the given path :param dbus_path: :return:
-
bluezero.dbus_tools.
get_dbus_path
(adapter=None, device=None, service=None, characteristic=None, descriptor=None)¶ Return a DBus path for the given properties :param adapter: Adapter address :param device: Device address :param service: GATT Service UUID :param characteristic: GATT Characteristic UUID :param descriptor: GATT Descriptor UUID :return: DBus path
-
bluezero.dbus_tools.
get_device_address_from_dbus_path
(path)¶ [Deprecated] Function to get the address of a remote device from a given D-Bus path. Path must include device part (e.g. dev_XX_XX_XX_XX_XX_XX)
-
bluezero.dbus_tools.
get_device_addresses
(name_contains)¶ Finds device whose name contains the string :param name_contains: String to be found in device name :return: List of dictionaries wth Device address and name
-
bluezero.dbus_tools.
get_iface
(adapter=None, device=None, service=None, characteristic=None, descriptor=None)¶ For the given list of properties return the deepest interface :param adapter: Adapter address :param device: Device address :param service: GATT Service UUID :param characteristic: GATT Characteristic UUID :param descriptor: GATT Descriptor UUID :return: DBus Interface
-
bluezero.dbus_tools.
get_mac_addr_from_dbus_path
(path)¶ [Deprecated] Function to get the address of a remote device from a given D-Bus path. Path must include device part (e.g. dev_XX_XX_XX_XX_XX_XX)
-
bluezero.dbus_tools.
get_managed_objects
()¶ Return the objects currently managed by the DBus Object Manager.
-
bluezero.dbus_tools.
get_methods
(adapter=None, device=None, service=None, characteristic=None, descriptor=None)¶ Get methods available for the specified :param adapter: Adapter Address :param device: Device Address :param service: GATT Service UUID :param characteristic: GATT Characteristic UUID :param descriptor: GATT Descriptor UUID :return: Object of the DBus methods available
-
bluezero.dbus_tools.
get_profile_path
(adapter, device, profile)¶ Return a DBus path for the given properties :param adapter: Adapter address :param device: Device address :param profile: :return:
-
bluezero.dbus_tools.
get_props
(adapter=None, device=None, service=None, characteristic=None, descriptor=None)¶ Get properties for the specified object :param adapter: Adapter Address :param device: Device Address :param service: GATT Service UUID :param characteristic: GATT Characteristic UUID :param descriptor: GATT Descriptor UUID :return: Object of the DBus properties available
-
bluezero.dbus_tools.
get_services
(path_obj)¶ Return a list of GATT Service UUIDs for a given Bluetooth device D-Bus path
Parameters: path_obj – D-Bus path for remote Bluetooth device Returns: List of GATT Service UUIDs
-
bluezero.dbus_tools.
interfaces_added
(path, interfaces)¶ Callback for when an interface is added :param path: :param interfaces: :return:
-
bluezero.dbus_tools.
properties_changed
(interface, changed, invalidated, path)¶ Callback for when properties are changed :param interface: :param changed: :param invalidated: :param path: :return:
-
bluezero.dbus_tools.
str_to_dbusarray
(word)¶ Helper function to represent Python string as D-Dbus Byte array
Async Tools¶
Collection of functions to work with the GLib Event Loop
-
class
bluezero.async_tools.
EventLoop
¶ Facade class to help with using GLib event loop
-
is_running
()¶ Check if event loop is running
-
quit
()¶ Stop event loop
-
run
()¶ Run event loop
-
-
bluezero.async_tools.
add_timer_ms
(time, callback, data=None)¶ Call given callback every x milliseconds
-
bluezero.async_tools.
add_timer_seconds
(time, callback, data=None)¶ Call given callback every x seconds