Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We need an API to monitor changes to the properties of one or more devices #28

Closed
Yoric opened this issue Feb 6, 2016 · 2 comments
Closed

Comments

@Yoric
Copy link

Yoric commented Feb 6, 2016

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.

Cc @mcav, @jedireza, @davidflanagan .

@mcav
Copy link
Contributor

mcav commented Mar 4, 2016

Is this issue obsoleted by the taxonomy work?

@Yoric
Copy link
Author

Yoric commented Mar 4, 2016

Let's say that it's replaced by "Let's integrate the Taxonomy".

@Yoric Yoric closed this as completed Mar 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants