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 : strThe 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 : boolWhether the peripheral allows connections.
state
var state : Literal['error', 'connecting', 'connected', 'disconnecting', 'disconnected']connected
var connected : boolWhether the peripheral is currently connected to the Homey.
rssi
var rssi : intReceived 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) ‑> SelfRaises
NotConnected- Raised if the connection attempt failed.
disconnect
async def disconnect(self) ‑> Noneget_service
async def get_service(self, uuid) ‑> BleServiceGet 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
| Name | Type | Description |
|---|---|---|
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) ‑> intread
async def read(self, service_uuid: str, characteristic_uuid: str) ‑> bytesRead 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) ‑> NoneWrite the data to the characteristic of the service with the given UUIDs.
Raises
NotConnected: NotFound:
on_disconnect
def on_disconnect(self, f: Callable[[], None]) ‑> SelfThe disconnect event is fired when the peripheral is disconnected.
Args
| Name | Type | Description |
|---|---|---|
f |
Callable[[], None] | A callback that receives no data. |