This commit is contained in:
Mateusz Gruszczyński
2026-08-23 23:20:00 +02:00
parent 8bb12a1782
commit b23578a0c8
34 changed files with 2300 additions and 447 deletions
+16 -1
View File
@@ -1,10 +1,24 @@
use std::time::Duration;
use anyhow::{anyhow, bail, Context, Result};
use serde_json::Value;
use url::Url;
use crate::models::HomeAssistantSettings;
fn request_client(default_client: &reqwest::Client, settings: &HomeAssistantSettings) -> Result<reqwest::Client> {
if !settings.allow_invalid_tls {
return Ok(default_client.clone());
}
reqwest::Client::builder()
.timeout(Duration::from_secs(10))
.user_agent(concat!("gree-controller/", env!("CARGO_PKG_VERSION")))
.danger_accept_invalid_certs(true)
.danger_accept_invalid_hostnames(true)
.build()
.context("cannot build Home Assistant HTTPS client")
}
pub async fn read_temperature(
client: &reqwest::Client,
default_client: &reqwest::Client,
settings: &HomeAssistantSettings,
entity_override: Option<&str>,
) -> Result<f64> {
@@ -19,6 +33,7 @@ pub async fn read_temperature(
let path = format!("api/states/{}", entity.trim_start_matches('/'));
base = base.join(&path).context("cannot build Home Assistant API URL")?;
let client = request_client(default_client, settings)?;
let response = client.get(base)
.bearer_auth(settings.token.trim())
.header("Accept", "application/json")