project-chip / rs-matter

Rust implementation of the Matter protocol. Status: Experimental
Apache License 2.0
303 stars 43 forks source link

OnOffCluster: add an optional callback to new() #153

Closed lucasvr closed 3 months ago

lucasvr commented 3 months ago

Users of rs-matter may want to execute their own logic when a cluster switches state. This commit adds a callback: Option<&'a dyn Fn(bool)> parameter to OnOffCluster::new(). If set, that callback executes each time OnOffCluster::set(value: bool) is called with a different value than the previous one.

ivmarkov commented 3 months ago

I don't think we should do this. The OnOffCluster handler is just a "sample" handler which is not intended for production use. (So actually I would accept a patch that documents this.)

In general - and putting aside the system / Matter clusters on Endpoint 0, the philosophy of the rs-matter crate is that with regards to cluster callbacks (i.e. things that implement the Handler or AsyncHandler traits), these things have to be implemented by the user itself, and there is not much point in providing "ready made" trait implementations, because these tend to be of little use, and in fact end up as being "double callbacks", just like what you just suggested:

What @andreilitvin was recently working on is much more promising IMO:

lucasvr commented 3 months ago

Thanks for the pointer. No worries, let's wait for his PR to land then. I'll close this one for now.