chaospott-status/src/status.rs

84 lines
2.6 KiB
Rust
Raw Normal View History

2024-05-21 19:48:14 +00:00
use spaceapi::{
sensors::{DoorLockedSensor, SensorMetadataWithLocation, Sensors},
Contact, Location, State, Status, StatusBuilder,
};
const SPACE_NAME: &str = "Chaospott";
const SPACE_ADDRESS: &str = "Sibyllastr. 9, 45136 Essen, Germany";
const SPACE_LOCATION_LAT: f64 = 51.438476;
const SPACE_LOCATION_LON: f64 = 7.024991;
2024-05-21 19:48:14 +00:00
const SPACE_URL: &str = "https://chaospott.de";
const SPACE_LOGO: &str = "https://chaospott.de/images/logo.png";
2024-05-21 19:48:14 +00:00
// TODO: Add missing information
pub fn status(sensors: Sensors, state: State) -> Status {
2024-05-21 19:48:14 +00:00
let mut status = StatusBuilder::v14(SPACE_NAME)
.location(Location {
address: Some(SPACE_ADDRESS.into()),
lat: SPACE_LOCATION_LAT,
lon: SPACE_LOCATION_LON,
2024-05-21 19:48:14 +00:00
..Default::default()
})
.url(SPACE_URL)
.logo(SPACE_LOGO)
2024-05-21 19:48:14 +00:00
.contact(Contact {
email: Some("info@chaospott.de".into()),
irc: Some("irc://irc.hackint.org/#chaospott".into()),
issue_mail: Some("support@chaospott.de".into()),
mastodon: Some("https://chaos.social/@chaospott".into()),
matrix: Some("#chaospott:matrix.chaospott.de".into()),
ml: Some("discuss@lists.chaospott.de".into()),
mumble: Some("mumble://mumble.chaospott.de".into()),
phone: Some("+49 201 85892243".into()),
..Default::default()
})
// .add_issue_report_channel(IssueReportChannel::IssueMail)
// .add_issue_report_channel(IssueReportChannel::Ml)
.state(state)
2024-05-21 19:48:14 +00:00
.build()
.unwrap();
status.sensors = Some(sensors);
status
}
pub struct TheDoors {
pub aerie: bool,
pub cellar: bool,
}
2024-05-21 19:48:14 +00:00
pub fn get_aerie(open: bool) -> DoorLockedSensor {
DoorLockedSensor {
value: open,
2024-05-21 19:48:14 +00:00
metadata: SensorMetadataWithLocation {
name: None,
description: None,
location: "aerie".to_string(),
},
}
}
pub fn get_cellar(open: bool) -> DoorLockedSensor {
DoorLockedSensor {
value: open,
2024-05-21 19:48:14 +00:00
metadata: SensorMetadataWithLocation {
name: None,
description: None,
location: "cellar".to_string(),
},
}
}
pub fn update(the_doors: TheDoors) -> (Sensors, State) {
let mut sensors = Sensors::default();
sensors.door_locked.push(get_aerie(the_doors.aerie));
sensors.door_locked.push(get_cellar(the_doors.cellar));
// Open means that any door is open.
let state = State {
open: Some(the_doors.aerie || the_doors.cellar),
..State::default()
};
(sensors, state)
2024-05-21 19:48:14 +00:00
}