From e877587fd444cc56b57b65c20f2a8112073f32f9 Mon Sep 17 00:00:00 2001 From: Kyle Potts Date: Fri, 9 Apr 2021 20:36:18 -0400 Subject: [PATCH 1/3] run fmt --- .idea/.gitignore | 3 +++ .idea/homeassistant-rs.iml | 12 ++++++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ Cargo.toml | 1 + src/lib.rs | 3 ++- src/rest.rs | 1 - src/types.rs | 5 ++--- 8 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/homeassistant-rs.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/homeassistant-rs.iml b/.idea/homeassistant-rs.iml new file mode 100644 index 0000000..9b4cf84 --- /dev/null +++ b/.idea/homeassistant-rs.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..5317b9f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 16378bf..ee47392 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,5 @@ license = "Apache-2.0" futures = "0.3" reqwest = { version = "0.10", features = ["json"] } serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" chrono = "0.4" diff --git a/src/lib.rs b/src/lib.rs index 769177f..e7c3450 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,8 +61,9 @@ pub struct LongLivedToken { impl HomeAssistantAPI { pub fn new(instance_url: String, client_id: String) -> Arc> { let token = Token::None; + let http_instance_url = format!("http://{}", instance_url); let ret = Arc::new(RwLock::new(Self { - instance_url, + instance_url: http_instance_url, token, client_id, self_reference: Weak::new(), diff --git a/src/rest.rs b/src/rest.rs index 7e20a91..060a881 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -318,7 +318,6 @@ impl Rest { drop(read_lock); let response = request.send().await?; - let resp_json: Vec = response.json().await?; Ok(resp_json) diff --git a/src/types.rs b/src/types.rs index 7dff448..806b730 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; - +use serde_json::Value; #[derive(Serialize, Deserialize, Debug)] pub struct HaEntityAttribute { pub friendly_name: Option, @@ -141,10 +141,9 @@ pub struct ServiceObject { #[derive(Serialize, Deserialize, Debug)] pub struct StateObject { - pub attributes: std::collections::HashMap, + pub attributes: Value, pub entity_id: String, pub last_changed: String, - pub last_updated: Option, pub state: String, } From 06d36b4bf5a5800f2b880fb915d780e30c00877b Mon Sep 17 00:00:00 2001 From: Kyle Potts Date: Fri, 9 Apr 2021 20:38:43 -0400 Subject: [PATCH 2/3] lets not add idea files --- .idea/.gitignore | 3 --- .idea/homeassistant-rs.iml | 12 ------------ .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 4 files changed, 29 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/homeassistant-rs.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/homeassistant-rs.iml b/.idea/homeassistant-rs.iml deleted file mode 100644 index 9b4cf84..0000000 --- a/.idea/homeassistant-rs.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 5317b9f..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 92ae5cfa507a10c71385f04b9bced6957e6e517f Mon Sep 17 00:00:00 2001 From: Kyle Potts Date: Sat, 10 Apr 2021 08:23:07 -0400 Subject: [PATCH 3/3] instead of just Value have Map --- src/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.rs b/src/types.rs index 806b730..c6a15ee 100644 --- a/src/types.rs +++ b/src/types.rs @@ -141,7 +141,7 @@ pub struct ServiceObject { #[derive(Serialize, Deserialize, Debug)] pub struct StateObject { - pub attributes: Value, + pub attributes: std::collections::HashMap, pub entity_id: String, pub last_changed: String, pub state: String,