1786288245
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#[allow(clippy::all)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum AppError {
|
||||
#[error("HASS_URL is not set")]
|
||||
@@ -16,7 +17,7 @@ pub enum AppError {
|
||||
SlintPlatform(#[from] slint::PlatformError),
|
||||
|
||||
#[error(transparent)]
|
||||
HomeAssistant(#[from] Box<hass_rs::HassError>),
|
||||
HomeAssistant(#[from] hass_rs::HassError),
|
||||
|
||||
#[error("Entity {0} not found")]
|
||||
NoEntity(String),
|
||||
|
||||
@@ -24,7 +24,6 @@ async fn handle_command(
|
||||
client
|
||||
.call_service("light".into(), service.into(), Some(payload))
|
||||
.await
|
||||
.map_err(Box::new)
|
||||
.map_err(Into::into)
|
||||
} else {
|
||||
Err(AppError::NoEntity(entity_id))
|
||||
@@ -39,7 +38,6 @@ async fn handle_command(
|
||||
client
|
||||
.call_service("climate".into(), service.into(), Some(payload))
|
||||
.await
|
||||
.map_err(Box::new)
|
||||
.map_err(Into::into)
|
||||
} else {
|
||||
Err(AppError::NoEntity(entity_id))
|
||||
@@ -56,7 +54,6 @@ async fn handle_command(
|
||||
client
|
||||
.call_service("climate".into(), "set_temperature".into(), Some(payload))
|
||||
.await
|
||||
.map_err(Box::new)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
@@ -86,14 +83,11 @@ pub async fn hass(
|
||||
|
||||
let url = format!("{}://{}/api/websocket", scheme, url.authority());
|
||||
|
||||
let mut client = HassClient::new(&url).await.map_err(Box::new)?;
|
||||
client
|
||||
.auth_with_longlivedtoken(&hass_token)
|
||||
.await
|
||||
.map_err(Box::new)?;
|
||||
let mut client = HassClient::new(&url).await?;
|
||||
client.auth_with_longlivedtoken(&hass_token).await?;
|
||||
|
||||
let mut state = HashMap::<String, HassEntity>::new();
|
||||
let states = client.get_states().await.map_err(Box::new)?;
|
||||
let states = client.get_states().await?;
|
||||
|
||||
states.iter().for_each(|entity| {
|
||||
state.insert(entity.entity_id.clone(), entity.clone());
|
||||
@@ -103,10 +97,7 @@ pub async fn hass(
|
||||
initial_state.sort_by(|a, b| a.entity_id.cmp(&b.entity_id));
|
||||
s2c_tx.send(EventMessage::InitialState(initial_state)).ok();
|
||||
|
||||
let mut event_receiver = client
|
||||
.subscribe_event("state_changed")
|
||||
.await
|
||||
.map_err(Box::new)?;
|
||||
let mut event_receiver = client.subscribe_event("state_changed").await?;
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
|
||||
@@ -13,6 +13,7 @@ use crate::{
|
||||
messages::{CommandMessage, EventMessage},
|
||||
};
|
||||
|
||||
#[allow(clippy::result_large_err)]
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), AppError> {
|
||||
dotenvy::dotenv().ok();
|
||||
|
||||
Reference in New Issue
Block a user