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; const SPACE_URL: &str = "https://chaospott.de"; const SPACE_LOGO: &str = "https://chaospott.de/images/logo.png"; // TODO: Add missing information pub fn status(sensors: Sensors, state: State) -> Status { let mut status = StatusBuilder::v14(SPACE_NAME) .location(Location { address: Some(SPACE_ADDRESS.into()), lat: SPACE_LOCATION_LAT, lon: SPACE_LOCATION_LON, ..Default::default() }) .url(SPACE_URL) .logo(SPACE_LOGO) .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) .build() .unwrap(); status.sensors = Some(sensors); status } pub struct TheDoors { pub aerie: bool, pub cellar: bool, } pub fn get_aerie(open: bool) -> DoorLockedSensor { DoorLockedSensor { value: open, metadata: SensorMetadataWithLocation { name: None, description: None, location: "aerie".to_string(), }, } } pub fn get_cellar(open: bool) -> DoorLockedSensor { DoorLockedSensor { value: open, 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) }