Struct foxbox_thinkerbell::ast::Match [] [src]

pub struct Match<Ctx> where Ctx: Context {
    pub source: Vec<GetterSelector>,
    pub kind: ChannelKind,
    pub range: Range,
    pub duration: Option<Duration>,
    pub phantom: PhantomData<Ctx>,
}

An individual match.

Matchs always take the form: "data received from getter channel enters given range".

A condition is true if any of the corresponding getter channels yielded a value that enters the given range.

JSON

A match is represented as an object with the following fields:

extern crate foxbox_thinkerbell;
extern crate foxbox_taxonomy;

use foxbox_thinkerbell::ast::*;
use foxbox_taxonomy::services::*;
use foxbox_taxonomy::parse::*;

let source = r#"{
  "source": [{"id": "my getter"}],
  "kind": "OvenTemperature",
  "range": {"Geq": {"Temperature": {"C": 300}}},
  "duration": 3600
}"#;

let match_ = Match::<UncheckedCtx>::from_str(&source).unwrap();
assert_eq!(match_.kind, ChannelKind::OvenTemperature);

Fields

source

The set of getters to watch. Note that the set of getters may change (e.g. when devices are added/removed) without rebooting the script.

kind

The kind of channel expected from source, e.g. "the current time of day", "is the door opened?", etc. During compilation, we make sure that we restrict to the elements of source that offer kind.

range

The range of values for which the condition is considered met. During compilation, we check that the type of range is compatible with that of getter.

duration

If specified, the values must remain in the range for at least duration before the match is considered valid. This is useful for sensors that may oscillate around a threshold or for detecting e.g. that a door has been forgotten open.

phantom

Trait Implementations

impl Parser<Match<UncheckedCtx>> for Match<UncheckedCtx>

fn description() -> String

fn parse(path: Path, source: &mut JSON) -> Result<Self, ParseError>

fn from_str(source: &str) -> Result<T, ParseError>

fn take(path: Path, source: &mut Value, field_name: &str) -> Result<T, ParseError>

fn take_opt(path: Path, source: &mut Value, field_name: &str) -> Option<Result<T, ParseError>>

fn take_vec_opt(path: Path, source: &mut Value, field_name: &str) -> Option<Result<Vec<T>, ParseError>>

fn take_vec(path: Path, source: &mut Value, field_name: &str) -> Result<Vec<T>, ParseError>