Skip to content

Commit 2f2e064

Browse files
committed
Allow different types of write
Some devices are sensitive about the type of write performed. Add support for choosing whether or not a response is requested.
1 parent e1b147d commit 2f2e064

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

gatt/gatt_linux.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def read_value(self, offset=0):
596596
error = _error_from_dbus_error(e)
597597
self.service.device.characteristic_read_value_failed(self, error=error)
598598

599-
def write_value(self, value, offset=0):
599+
def write_value(self, value, offset=0, with_response=True):
600600
"""
601601
Attempts to write a value to the characteristic.
602602
@@ -607,10 +607,16 @@ def write_value(self, value, offset=0):
607607
"""
608608
bytes = [dbus.Byte(b) for b in value]
609609

610+
if with_response == True:
611+
write_type = "request"
612+
else:
613+
write_type = "command"
614+
610615
try:
611616
self._object.WriteValue(
612617
bytes,
613-
{'offset': dbus.UInt16(offset, variant_level=1)},
618+
{'offset': dbus.UInt16(offset, variant_level=1),
619+
'type': write_type},
614620
reply_handler=self._write_value_succeeded,
615621
error_handler=self._write_value_failed,
616622
dbus_interface='org.bluez.GattCharacteristic1')

0 commit comments

Comments
 (0)