Most Apps (both Control and Monitor) will need to monitor changes to device properties.
For instance:
the Remote Control for temperature needs to display the room temperature, in real-time;
an Intrusion Monitor App needs to be informed whenever presence sensors change value;
a plant watering monitor app needs to determine when the humidity goes below some value;
...
To implement any of these apps, we need an API that will monitor a set of properties of devices and callback each time the value of a given property of a given device enter/leaves some interval (or at each change if no interval is specified).
We need this API at least in WebSocket, as all consumers can be built on top of WebSocket. Ideally, we'd like to provide a concise JS API on top of the WebSocket API. It would be useful to have this API available to Rust code, too, for the sake of the rules engine and Monitor Workers.
I'll describe a pseudo-API in Rust, because I have attempted to do it in other languages and it was actually more complicated:
trait Watcher {
/// Create a new watcher.
pub fn new() -> Watcher;
/// Watch a property of a device.
///
/// If the device is smart enough,
///
/// # Example
///
/// let witness = watcher.add(&the_terminator,
/// &InputCapability::DetectSarahConnor,
/// &Range::any(),
/// &tx);
///
/// Until `witness` is dropped, whenever property `DetectSarahConnor` of `the_terminator`
/// changes, the watcher will send a message on `tx`.
///
/// let witness_2 = watcher.add(&the_terminator,
/// &InputCapability::Ammo,
/// &Range::boundary(100),
/// &tx_2);
///
/// Until `witness_2` is dropped, whenever property `Ammo` of `the_terminator` goes
/// above/beyond 100, the watcher will send a message on `tx_2`.
pub fn<T> add(&mut self, &Device, &InputCapability<T>, &Range<T>, &Sender<T>) -> Witness;
}
/// A structure used to stop watching a property once it is dropped.
pub struct Witness {
// ...
}
This depends heavily on our ongoing efforts on Taxonomy.
Note that JS versions of this API will most likely use a addEventListener/removeEventListener pair, rather than channels (unless streams have been standardized by then). The server will monitor WebSocket disconnection to ensure garbage-collection of Watcher.
Most Apps (both Control and Monitor) will need to monitor changes to device properties.
For instance:
To implement any of these apps, we need an API that will monitor a set of properties of devices and callback each time the value of a given property of a given device enter/leaves some interval (or at each change if no interval is specified).
We need this API at least in WebSocket, as all consumers can be built on top of WebSocket. Ideally, we'd like to provide a concise JS API on top of the WebSocket API. It would be useful to have this API available to Rust code, too, for the sake of the rules engine and Monitor Workers.
I'll describe a pseudo-API in Rust, because I have attempted to do it in other languages and it was actually more complicated:
This depends heavily on our ongoing efforts on Taxonomy.
Note that JS versions of this API will most likely use a
addEventListener
/removeEventListener
pair, rather than channels (unless streams have been standardized by then). The server will monitor WebSocket disconnection to ensure garbage-collection ofWatcher
.Cc @mcav, @jedireza, @davidflanagan .