bluetooth_mesh.models

class bluetooth_mesh.models.Model(element)[source]

Base class for mesh models.

MODEL_ID = (None, None)
OPCODES = []
PUBLISH = False
SUBSCRIBE = False
async bind(app_key_index)[source]

Bind to application key with index app_key_index.

You probably don’t want to call this directly, see Model.subscribe() instead.

Parameters:

app_key_index (int) –

Return type:

ModelBindStatus

Returns:

A tuple of: - unicast address of the element the bound model belongs to - index of the bound application key - class object of the bound model

async bulk_query(requests, statuses, *, send_interval=0.5, progress_callback=None, timeout=5.0)[source]

Bulk query

Parameters:
  • requests (Mapping[Hashable, Callable[[], Awaitable[None]]]) –

  • statuses (Mapping[Hashable, Future]) –

  • send_interval (float) –

  • progress_callback (Optional[Callable[[Hashable, Any, Mapping, Mapping], None]]) –

  • timeout (float) –

Return type:

Mapping[Hashable, Any]

dev_key_message_received(source, remote, net_index, message)[source]
expect_app(source, app_index, destination, opcode, params)[source]

Create an asyncio.Future that gets fulfilled when a specific application message is received.

opcode is the expected message’s numeric opcode, as defined in the mesh spec. See bluetooth_mesh.messages for a list of well-known opcodes.

params define the message contents. After a received message is parsed using bluetooth_mesh.messages.AccessMessage, it’s compared recursively, key-by-key, with params. If all keys match, the future’s result is set to the parsed message. If the keys are not specified, they will be ignored.

One can specify wildcards by specifying key value as typing.Any or (Ellipsis) - these match with anything, including composite fields.

Parameters:
  • source (int) – Sender address

  • app_index (int) – Index of the application key

  • destination (Union[int, UUID, None]) – Destination address

  • opcode (int) – Expected message opcode.

  • params (Mapping[str, Any]) – Expected message parameters.

Return type:

Future

expect_dev(source, net_index, opcode, params)[source]

Create an asyncio.Future that gets fulfilled when a specific device message is received.

Unlike application keys, device keys are bound to all subnets, so you need to explicitly provide net_index.

See expect_app()

Parameters:
  • source (int) – Sender address

  • net_index (int) – Index of the network key

  • opcode (int) – Expected message opcode.

  • params (Mapping[str, Any]) – Expected message parameters.

Return type:

Future

message_received(source, app_index, destination, message)[source]
async query(request, status, *, send_interval=0.2, timeout=2.0)[source]

Query

Parameters:
  • request (Callable[[], Awaitable[None]]) –

  • status (Future) –

  • send_interval (float) –

  • timeout (float) –

Return type:

Any

async repeat(request, *, retransmissions=6, send_interval=0.05)[source]

Application retransmissions

Parameters:
  • request (Callable[[], Awaitable]) –

  • retransmissions (int) –

  • send_interval (float) –

async send_app(destination, app_index, opcode, params)[source]

Send a message using an application key.

Parameters:
  • destination (int) – Destination address

  • app_index (int) – Index of the application key

  • opcode (int) – Message opcode.

  • params (Mapping[str, Any]) – Message parameters.

async send_dev(destination, net_index, opcode, params)[source]

Send a message using a device key.

destination determines which device key is going to be used. For local destinations, the key is always known, but if destination is a remote node, the caller must first import its device key using import_remote_node().

Unlike application keys, device keys are bound to all subnets, so you need to explicitly provide net_index.

See send_app()

Parameters:
  • destination (int) – Destination address

  • net_index (int) – Index of the network key

  • opcode (int) – Message opcode.

  • params (Mapping[str, Any]) – Message parameters.

async subscribe(app_keys, subscription_address, callback)[source]

Subscribe to messages sent to subscription_address and encrypted with either of application keys

This method ensures that the application key is bound to the model.

This causes callback to be called whenerver such message is received.

Parameters:
  • app_keys (Sequence[Tuple[int, int, ApplicationKey]]) –

  • subscription_address (int) –

  • callback (Callable[[int, Union[int, UUID], int, Mapping[str, Any]], None]) –

Return type:

ModelSubscriptionStatus

Returns:

A tuple of: - unicast address of the element the bound model belongs to - subscription address (usually a group address) - class object of the bound model

tid()[source]
Return type:

int

async unsubscribe(subscription_address=None, callback=None)[source]

Unubscribe from messages sent to subscription_address, or clear subscriptions if subscription_address is not provided.

Return type:

ModelSubscriptionStatus

Returns:

A tuple of: - unicast address of the element the bound model belongs to - subscription address (usually a group address) - class object of the bound model

update_configuration(configuration)[source]

Foundation Models

class bluetooth_mesh.models.ConfigServer(element)[source]
class bluetooth_mesh.models.ConfigClient(element)[source]
class bluetooth_mesh.models.HealthServer(element)[source]
class bluetooth_mesh.models.HealthClient(element)[source]

Generic Models

class bluetooth_mesh.models.GenericOnOffServer(element)[source]
class bluetooth_mesh.models.GenericOnOffClient(element)[source]

Silvair Vendor Models

class bluetooth_mesh.models.DebugClient(element)[source]
class bluetooth_mesh.models.NetworkDiagnosticClient(element)[source]
class bluetooth_mesh.models.NetworkDiagnosticSetupClient(element)[source]