chaospott-status/src/status.rs

109 lines
3.5 KiB
Rust

use std::time::{SystemTime, UNIX_EPOCH};
use spaceapi::{
sensors::{DoorLockedSensor, SensorMetadataWithLocation, Sensors}, Contact, Feed, Feeds, Location, State, Status, StatusBuilder, Link
};
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()
})
.feeds(Feeds {
blog: Some(Feed {
type_: Some("application/rss+xml".into()),
url: String::from("https://chaospott.de/feed.xml")
}),
calendar: Some(Feed {
type_: Some("ical".into()),
url: String::from("https://cloud.chaospott.de/remote.php/dav/public-calendars/5HM7B0ZOLEYC3QD0?export")
}),
..Default::default()
})
.add_project("https://wiki.chaospott.de/projekte:start")
.add_project("https://git.chaospott.de/")
.add_link(Link {
name: String::from("Sibyllinische Neuigkeiten"),
description: Some("In unserem Podcast berichten wir über unser Clubleben und unterhalten uns über verschiedene Technikthemen.".into()),
url: String::from("https://podcast.chaospott.de/")
})
// TODO state needs icon URLs for open and closed
.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));
let time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
// Open means that any door is open.
let state = State {
open: Some(the_doors.aerie || the_doors.cellar),
lastchange: Some(time),
..State::default()
};
(sensors, state)
}