readValue triggers onNext for observeValueUpdateAndSetNotification
Describe the bug
Normal behavior
For any characteristic that can notify, subscribe to observeValueUpdateAndSetNotification. onNext is called everytime the hardware notifies the characteristic.
Now at any time, call readValue on the same characteristic. As readValue is a PrimitiveSequence, the onSuccess callback is called with the updated characteristic value
I am using CharacteristicIdentifier for both notify and read subscriptions.
Potential Issue
Right before onSuccess is called on the readValue observable, I noticed that the onNext callback of observeValueUpdateAndSetNotification is also called. In my case, it results in a double notification and so a double management of the read value which could have unexpected behavior
To Reproduce Steps to reproduce the behavior:
- Subscribe to
observeValueUpdateAndSetNotificationand print any notified value on characteristic - Call
readValueon this same characteristic - Observe the
observeValueUpdateAndSetNotificationbeing called
Expected behavior The notification callback should not be triggered
Environment:
- OS: iOS 9/10/11/12
- Library version 5.1.3
- Swift version 4.2
As far as I know this is the default behaviour of vanilla iOS API. There is a single callback for wether the value of a characteristic was updated by a notification or a read. I may be wrong but sorting it in the library may introduce some edge cases when a notification would be triggered at the time a read would happen. Thoughts?
I agree, the default behavior of the iOS API has a unique callback func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) .
The use of the RxBluetoothKit API seem misleading to me in that case because you can subscribe to readValue and you have a onSuccess call. By default I wouldn't expect any other callback/observer to be triggered.
Is this bothering only me ? If it's the case, this issue can be closed and I will adapt my code properly. I would like to have the opinion of a contributor though
We will get back to the topic next week probably