blatann.gatt.gatts_attribute module¶
- class blatann.gatt.gatts_attribute.GattsAttributeProperties(read=True, write=False, security_level=SecurityLevel.OPEN, max_length=20, variable_length=True, read_auth=False, write_auth=False)¶
Bases:
object
- class blatann.gatt.gatts_attribute.GattsAttribute(ble_device, peer, parent, uuid, handle, properties, initial_value=b'', string_encoding='utf8')¶
Bases:
Attribute
Represents the server-side interface of a single attribute which lives inside a Characteristic.
- property parent: GattsCharacteristic¶
Read Only
Gets the parent characteristic which owns this attribute
- property read_in_process: bool¶
Read Only
Gets whether or not the client is in the process of reading out this attribute
- set_value(value)¶
Sets the value of the attribute.
- Parameters
value – The value to set to. Must be an iterable type such as a str, bytes, or list of uint8 values, or a BleDataStream object. Length must be less than the attribute’s max length. If a str is given, it will be encoded using the string_encoding property.
- Raises
InvalidOperationException if value length is too long
- get_value()¶
Fetches the attribute’s value from hardware and updates the local copy. This isn’t often necessary and should instead use the value property to avoid unnecessary reads from the hardware.
- Return type
- property on_write: Event[GattsAttribute, WriteEventArgs]¶
Event generated whenever a client writes to this attribute.
- Returns
an Event which can have handlers registered to and deregistered from
- property on_read: Event[GattsAttribute, None]¶
Event generated whenever a client requests to read from this attribute. At this point, the application may choose to update the value of the attribute to a new value using set_value.
Note
This will only be triggered if the attribute was configured with the read_auth property
A good example of using this is a “system time” characteristic which reports the application’s current system time in seconds. Instead of updating this characteristic every second, it can be “lazily” updated only when read.
NOTE: if there are multiple handlers subscribed to this and each set the value differently, it may cause undefined behavior.
- Returns
an Event which can have handlers registered to and deregistered from