BlePeripheral

homey.ble_peripheral

A BLE peripheral.

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

Ancestors

  • SimpleClass
  • homey.util.event_emitter.EventEmitter
  • typing.Generic

Instance variables

id

var id : Final[str]

The ID of the peripheral assigned by Homey.

uuid

var uuid : Final[str]

address

var address : str

The MAC address of the peripheral.

address_type

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

The type of address used by the peripheral.

connectable

var connectable : bool

Whether the peripheral allows connections.

state

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

connected

var connected : bool

Whether the peripheral is currently connected to the Homey.

rssi

var rssi : int

Received signal strength indicator of the peripheral.

services

var 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

connect

async def connect(self) ‑> Self

Raises

NotConnected
Raised if the connection attempt failed.

disconnect

async def disconnect(self) ‑> None

get_service

async def get_service(self, uuid) ‑> BleService

Get the service with the given UUID.

Raises

NotConnected: NotFound:

discover_services

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

Discover the services of this peripheral.

Args

NameTypeDescription
uuid_filter list[str] | None A collection of peripheral UUIDs to limit the discovery to.

Raises

NotConnected:

discover_all

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

Discover all services and characteristics of this peripheral.

Raises

NotConnected:

update_rssi

async def update_rssi(self) ‑> int

read

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:

write

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:

on_disconnect

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

The disconnect event is fired when the peripheral is disconnected.

Args

NameTypeDescription
f Callable[[], None] A callback that receives no data.

Inherited members