Compare commits

..

No commits in common. "4fcbc6fec7c8ec64d23c66741fe20b52ea004736" and "2e48a97e6e2272051125ce36f839de89b09692c7" have entirely different histories.

3 changed files with 75 additions and 120 deletions

139
Cargo.lock generated
View file

@ -172,9 +172,9 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
] ]
[[package]] [[package]]
@ -183,9 +183,9 @@ version = "0.1.71"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
] ]
[[package]] [[package]]
@ -422,9 +422,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
] ]
[[package]] [[package]]
@ -594,8 +594,8 @@ checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0"
dependencies = [ dependencies = [
"fnv", "fnv",
"ident_case", "ident_case",
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"strsim", "strsim",
"syn 1.0.109", "syn 1.0.109",
] ]
@ -607,7 +607,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
dependencies = [ dependencies = [
"darling_core", "darling_core",
"quote 1.0.35", "quote 1.0.31",
"syn 1.0.109", "syn 1.0.109",
] ]
@ -649,8 +649,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4" checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 1.0.109", "syn 1.0.109",
] ]
@ -696,9 +696,9 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
] ]
[[package]] [[package]]
@ -899,9 +899,9 @@ version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
] ]
[[package]] [[package]]
@ -1287,7 +1287,6 @@ dependencies = [
"never-say-never", "never-say-never",
"reqwest", "reqwest",
"serde", "serde",
"serde_json",
"spaceapi", "spaceapi",
"thiserror", "thiserror",
"time", "time",
@ -1706,9 +1705,9 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
] ]
[[package]] [[package]]
@ -1833,9 +1832,9 @@ version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
] ]
[[package]] [[package]]
@ -1904,9 +1903,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.78" version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -1929,8 +1928,8 @@ checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"itertools", "itertools",
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 1.0.109", "syn 1.0.109",
] ]
@ -1945,11 +1944,11 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.35" version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
] ]
[[package]] [[package]]
@ -2328,8 +2327,8 @@ checksum = "0f82e91eb61cd86d9287303133ee55b54618eccb75a522cc22a42c15f5bda340"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"proc-macro-crate", "proc-macro-crate",
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"ruma-identifiers-validation", "ruma-identifiers-validation",
"serde", "serde",
"syn 1.0.109", "syn 1.0.109",
@ -2415,9 +2414,9 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.195" version = "1.0.171"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
@ -2433,20 +2432,20 @@ dependencies = [
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.195" version = "1.0.171"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
] ]
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.111" version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" checksum = "d03b412469450d4404fe8499a268edd7f8b79fecb074b0d812ad64ca21f4031b"
dependencies = [ dependencies = [
"itoa", "itoa",
"ryu", "ryu",
@ -2613,19 +2612,19 @@ version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"unicode-ident", "unicode-ident",
] ]
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.48" version = "2.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"unicode-ident", "unicode-ident",
] ]
@ -2658,9 +2657,9 @@ version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
] ]
[[package]] [[package]]
@ -2743,9 +2742,9 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
] ]
[[package]] [[package]]
@ -2839,9 +2838,9 @@ version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
] ]
[[package]] [[package]]
@ -3073,9 +3072,9 @@ dependencies = [
"bumpalo", "bumpalo",
"log", "log",
"once_cell", "once_cell",
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -3097,7 +3096,7 @@ version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
dependencies = [ dependencies = [
"quote 1.0.35", "quote 1.0.31",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
] ]
@ -3107,9 +3106,9 @@ version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -3293,7 +3292,7 @@ version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
dependencies = [ dependencies = [
"proc-macro2 1.0.78", "proc-macro2 1.0.66",
"quote 1.0.35", "quote 1.0.31",
"syn 2.0.48", "syn 2.0.26",
] ]

View file

@ -29,4 +29,3 @@ color-eyre = "0.6.2"
tracing = "0.1.37" tracing = "0.1.37"
tracing-error = "0.2.0" tracing-error = "0.2.0"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
serde_json = "1.0.111"

View file

@ -1,5 +1,4 @@
use reqwest::{Client, Url}; use reqwest::{Client, Url};
use serde::Deserialize;
use thiserror::Error; use thiserror::Error;
use tracing::{event, instrument, Level}; use tracing::{event, instrument, Level};
@ -7,10 +6,8 @@ use tracing::{event, instrument, Level};
pub enum Error { pub enum Error {
#[error("invalid URL")] #[error("invalid URL")]
InvalidUrl(#[from] url::ParseError), InvalidUrl(#[from] url::ParseError),
#[error("error retrieving API response")] #[error("invalid response")]
ResponseBody(#[source] reqwest::Error), InvalidResponse(#[source] reqwest::Error),
#[error("invalid JSON in response")]
InvalidJson(#[source] serde_json::Error),
#[error("network request failed")] #[error("network request failed")]
Network(#[source] reqwest::Error), Network(#[source] reqwest::Error),
} }
@ -23,41 +20,6 @@ pub struct ItsApi {
client: Client, client: Client,
} }
fn response_get_lastchange(value: &mut serde_json::Value) -> Option<&mut serde_json::Value> {
value
.as_object_mut()?
.get_mut("state")?
.as_object_mut()?
.get_mut("lastchange")
}
fn response_get_icon(
value: &mut serde_json::Value,
) -> Option<&mut serde_json::Map<String, serde_json::Value>> {
value
.as_object_mut()?
.get_mut("state")?
.as_object_mut()?
.get_mut("icon")?
.as_object_mut()
}
fn patch_response(value: &mut serde_json::Value) {
// https://github.com/home-assistant/core/pull/83871
if let Some(lastchange) = response_get_lastchange(value) {
if let Some(f) = lastchange.as_f64() {
*lastchange = (f as u64).into();
}
}
// https://github.com/home-assistant/core/pull/108596
if let Some(icon) = response_get_icon(value) {
if let Some(closed) = icon.remove("close") {
icon.insert("closed".to_owned(), closed);
}
}
}
impl ItsApi { impl ItsApi {
/// Constructs a new IT-Syndikat API handler. /// Constructs a new IT-Syndikat API handler.
#[instrument] #[instrument]
@ -78,20 +40,15 @@ impl ItsApi {
#[instrument] #[instrument]
pub async fn status(&self) -> Result<spaceapi::Status, Error> { pub async fn status(&self) -> Result<spaceapi::Status, Error> {
event!(Level::DEBUG, "requesting spaceapi status"); event!(Level::DEBUG, "requesting spaceapi status");
let response = self let status = self
.client .client
.get(self.base_url.join("status.php")?) .get(self.base_url.join("status.php")?)
.send() .send()
.await .await
.map_err(Error::Network)? .map_err(Error::Network)?
.bytes() .json()
.await .await
.map_err(Error::ResponseBody)?; .map_err(Error::InvalidResponse)?;
let mut response = serde_json::from_slice(&response).map_err(Error::InvalidJson)?;
patch_response(&mut response);
let status = spaceapi::Status::deserialize(response).map_err(Error::InvalidJson)?;
event!(Level::DEBUG, ?status); event!(Level::DEBUG, ?status);
Ok(status) Ok(status)
@ -113,7 +70,7 @@ impl ItsApi {
.await .await
.map_err(Error::Network)? .map_err(Error::Network)?
.error_for_status() .error_for_status()
.map_err(Error::ResponseBody)?; .map_err(Error::InvalidResponse)?;
Ok(()) Ok(())
} }