use ::api;
pub trait StatusModifier: Send + Sync {
fn modify(&self, status: &mut api::Status);
}
pub struct StateFromPeopleNowPresent;
impl StatusModifier for StateFromPeopleNowPresent {
fn modify(&self, status: &mut api::Status) {
let people_now_present: Option<u64> = status.sensors.as_ref()
.map(|sensors| sensors.people_now_present[0].value)
.into();
if let Some(count) = people_now_present {
status.state.open = Some(count > 0);
if count == 1 {
status.state.message = Some(format!("{} person here right now", count));
} else if count > 1 {
status.state.message = Some(format!("{} people here right now", count));
}
}
}
}