1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use ::api;
use ::api::optional::Optional;
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()
.and_then(|sensors| sensors.people_now_present.as_ref())
.map(|people_now_present| 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 = Optional::Value(format!("{} person here right now", count));
} else if count > 1 {
status.state.message = Optional::Value(format!("{} people here right now", count));
}
}
}
}