Closed lucasvr closed 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:
OnOffCluster
already implements the Handler
trait, which has three callbacks: read
, write
and invoke
.What @andreilitvin was recently working on is much more promising IMO:
Handler
and AsyncHandler
traits, we can have cluster-specific "callback" traits that provide a callback API which is specific for the concrete cluster, and captures in the type system e.g. the exact attribute value being read/written, as well as the e.g. the concrete command being invoked, along with its parameters and return dataThanks for the pointer. No worries, let's wait for his PR to land then. I'll close this one for now.
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 timeOnOffCluster::set(value: bool)
is called with a different value than the previous one.