project-chip / rs-matter

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

How to actually implement an LED light in onff_light example? #101

Open jasta opened 11 months ago

jasta commented 11 months ago

I'm confused where I would add user code to actually do something with the on/off commands are received, am I missing something from the example code? It would seem that this is internally handled by OnOffCluster with no ability for me to observe changes like we see with other clusters like MediaPlaybackCluster. Perhaps we could include some simple print debugging or something when the user code would be expected to interact with a physical device to make this clearer for folks?

ivmarkov commented 11 months ago

This question has popped up before, but I can't find a link to it, and yes - we should be clearer in the examples and in a future guide as to what the user is supposed to do.

The TL;DR is: OnOffCluster is just an example implementation. You are not supposed to use it in production. Roll your own.

Longer story: A cluster is really a combination of two things, that don't necessarily need to come together, and I'm not sure we need to provide support for the second one (see below):

Also, there are multiple places where you can plug yourself in the framework - ordered in increasing level of control and decreasing level of "out of the box" experience with the lib. It is just that currently these are not well documented. As in, e.g. you can "pass" on the whole callback (a.k.a. "Handler") approach for your custom clusters, as long as you are willing to spin your own async loop and not re-use the giant future.

ivmarkov commented 11 months ago

Forgot to add: for the "system" clusters which are required by the Matter spec so that e.g. your provisioning works, we obviously provide both metadata and concrete Handler implementation. However for the user clusters - the things which describe your actual devices/peripherals, I'm not convinced we need to provide "ready to use" Handlers. What would they do, after all? They still need to get some sort of "user callback", so we would end up with a Handler impl (which is already a callback), that delegates to the "real" user callback. A bit pointless, specifically for "simple" user clusters.