Module homey.ble_peripheral

Classes

class BlePeripheral

A BLE peripheral.

This class must not be initialized by the developer, but retrieved by calling BleAdvertisement.connect().

Ancestors

Instance variables

var id : Final[str]

The ID of the peripheral assigned by Homey.

var uuid : Final[str]
prop address : str

The MAC address of the peripheral.

prop address_type : Literal['random', 'public', 'unknown']

The type of address used by the peripheral.

prop connectable : bool

Whether the peripheral allows connections.

prop state : Literal['error', 'connecting', 'connected', 'disconnecting', 'disconnected']
prop connected : bool

Whether the peripheral is currently connected to the Homey.

prop rssi : int

Received signal strength indicator of the peripheral.

prop services : tuple[BleService, ...]

BleServices on the peripheral.

Note that this is only filled with services that have been discovered by BlePeripheral.discover_services() or BlePeripheral.discover_all()

Methods

async def connect(self) ‑> Self

Raises

NotConnected
Raised if the connection attempt failed.
async def disconnect(self) ‑> None
async def get_service(self, uuid) ‑> BleService

Get the service with the given UUID.

Raises

NotConnected: NotFound:

async def discover_services(self, uuid_filter: list[str] | None = None) ‑> tuple[BleService, ...]

Discover the services of this peripheral.

Args

uuid_filter
A collection of peripheral UUIDs to limit the discovery to.

Raises

NotConnected:

async def discover_all(self) ‑> tuple[BleService, ...]

Discover all services and characteristics of this peripheral.

Raises

NotConnected:

async def update_rssi(self) ‑> int
async def read(self, service_uuid: str, characteristic_uuid: str) ‑> bytes

Read the current value of the characteristic of the service with the given UUIDs.

Raises

NotConnected: NotFound:

async def write(self, service_uuid: str, characteristic_uuid: str, data: bytes) ‑> None

Write the data to the characteristic of the service with the given UUIDs.

Raises

NotConnected: NotFound:

def on_disconnect(self, f: Callable[[], None]) ‑> Self

The disconnect event is fired when the peripheral is disconnected.

Args

f
A callback that receives no data.

Inherited members