chrysn / aiocoap

The Python CoAP library
Other
262 stars 119 forks source link

Possible to only alert subset of resource observers? #346

Closed tautologyclub closed 1 month ago

tautologyclub commented 1 month ago

I have a bunch of clients who wants async updates via GET /messages?deviceId={id} using the OBSERVE option. But these messages are addressed to a single device, identified via deviceId (passed along as a query option in the GET). When the server receives a message intended for device foo, I don't want device bar to be alerted.

It's not clear to me how I would do this using ObservableResource since the updated_state() method will alert ALL observers. Redesigning it so that there is one proper endpoint per device would be doable, but if possible I'd MUCH prefer using the query option method.

It looks somwhat trivial to implement by overriding updated_state method but if aiocoap can do this natively then I'd obviously prefer that :)

tautologyclub commented 1 month ago

I think I can partially answer my own question:

You can call trigger on the observation object itself, so you just need to keep track of the observations to be able to do this.

tautologyclub commented 1 month ago

Yep works great