2024-05-22 21:05:47 +00:00
|
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
|
|
|
2024-05-21 19:48:14 +00:00
|
|
|
use spaceapi::{
|
2024-05-22 21:05:47 +00:00
|
|
|
sensors::{DoorLockedSensor, SensorMetadataWithLocation, Sensors}, Contact, Feed, Feeds, Location, State, Status, StatusBuilder, Link
|
2024-05-21 19:48:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SPACE_NAME: &str = "Chaospott";
|
2024-05-21 21:44:10 +00:00
|
|
|
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";
|
2024-05-21 21:44:10 +00:00
|
|
|
const SPACE_LOGO: &str = "https://chaospott.de/images/logo.png";
|
2024-05-21 19:48:14 +00:00
|
|
|
|
2024-05-21 21:44:10 +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 {
|
2024-05-21 21:44:10 +00:00
|
|
|
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)
|
2024-05-21 21:44:10 +00:00
|
|
|
.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()
|
|
|
|
})
|
2024-05-22 21:05:47 +00:00
|
|
|
.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
|
2024-05-21 21:44:10 +00:00
|
|
|
.state(state)
|
2024-05-21 19:48:14 +00:00
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
|
2024-05-21 21:44:10 +00:00
|
|
|
status.sensors = Some(sensors);
|
|
|
|
status
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct TheDoors {
|
|
|
|
pub aerie: bool,
|
|
|
|
pub cellar: bool,
|
|
|
|
}
|
2024-05-21 19:48:14 +00:00
|
|
|
|
2024-05-21 21:44:10 +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(),
|
|
|
|
},
|
2024-05-21 21:44:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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(),
|
|
|
|
},
|
2024-05-21 21:44:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2024-05-22 21:05:47 +00:00
|
|
|
|
|
|
|
let time = SystemTime::now()
|
|
|
|
.duration_since(UNIX_EPOCH)
|
|
|
|
.unwrap()
|
|
|
|
.as_secs();
|
|
|
|
|
2024-05-21 21:44:10 +00:00
|
|
|
// Open means that any door is open.
|
|
|
|
let state = State {
|
|
|
|
open: Some(the_doors.aerie || the_doors.cellar),
|
2024-05-22 21:05:47 +00:00
|
|
|
lastchange: Some(time),
|
2024-05-21 21:44:10 +00:00
|
|
|
..State::default()
|
|
|
|
};
|
|
|
|
(sensors, state)
|
2024-05-21 19:48:14 +00:00
|
|
|
}
|