-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow different types of write #55
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -596,21 +596,28 @@ def read_value(self, offset=0): | |
error = _error_from_dbus_error(e) | ||
self.service.device.characteristic_read_value_failed(self, error=error) | ||
|
||
def write_value(self, value, offset=0): | ||
def write_value(self, value, offset=0, with_response=True): | ||
""" | ||
Attempts to write a value to the characteristic. | ||
|
||
Success or failure will be notified by calls to `write_value_succeeded` or `write_value_failed` respectively. | ||
|
||
:param value: array of bytes to be written | ||
:param offset: offset from where to start writing the bytes (defaults to 0) | ||
:param with_response: whether a response should be requested for the write (defaults to True) | ||
""" | ||
bytes = [dbus.Byte(b) for b in value] | ||
|
||
if with_response == True: | ||
write_type = "request" | ||
else: | ||
write_type = "command" | ||
|
||
try: | ||
self._object.WriteValue( | ||
bytes, | ||
{'offset': dbus.UInt16(offset, variant_level=1)}, | ||
{'offset': dbus.UInt16(offset, variant_level=1), | ||
'type': write_type}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your PR! It's important that we don't break existing projects using this library. Since this parameter was previously not specified, what is the default value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I read the PR, the PR proposes the |
||
reply_handler=self._write_value_succeeded, | ||
error_handler=self._write_value_failed, | ||
dbus_interface='org.bluez.GattCharacteristic1') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write_type = 'request' if with_response else 'command'
might be more appropriate here, or if more explicit code is preferred: