chore+feat(home-assistant): update to pyo3 0.27 and update extraction errors, switch out SmolStr for Arc<str>, tighten up light service calls and implement some for notify, start implementing units of measurement like for power

This commit is contained in:
2026-01-07 02:10:03 -05:00
parent 97aef026b2
commit fa36b39e81
35 changed files with 1255 additions and 259 deletions

View File

@@ -1,5 +1,7 @@
use super::service::{turn_off::TurnOff, turn_on::TurnOn};
use super::{state::LightState, GetStateObjectError, HomeAssistantLight};
use super::{GetStateObjectError, HomeAssistantLight};
use crate::home_assistant::GetServicesError;
use crate::service_registry::CallServiceError;
use crate::{
event::context::context::Context,
state::{ErrorState, HomeAssistantState, UnexpectedState},
@@ -35,21 +37,31 @@ impl GetState for HomeAssistantLight {
}
}
#[derive(Debug, Snafu)]
pub enum SetStateError {
/// couldn't get the service registry
GetServicesError { source: GetServicesError },
/// couldn't call the service
CallServiceError { source: CallServiceError },
}
impl SetState for HomeAssistantLight {
type Error = PyErr;
type Error = SetStateError;
async fn set_state(&mut self, state: protocol::light::State) -> Result<(), Self::Error> {
let context: Option<Context<()>> = None;
let target: Option<()> = None;
let services = Python::with_gil(|py| self.home_assistant.services(py))?;
let services =
Python::attach(|py| self.home_assistant.services(py)).context(GetServicesSnafu)?;
let _: IsNone = match state {
protocol::light::State::Off => {
services
.call_service(
TurnOff {
entity_id: self.entity_id(),
object_id: self.object_id.clone(),
},
context,
target,
@@ -61,7 +73,7 @@ impl SetState for HomeAssistantLight {
services
.call_service(
TurnOn {
entity_id: self.entity_id(),
object_id: self.object_id.clone(),
},
context,
target,
@@ -69,7 +81,8 @@ impl SetState for HomeAssistantLight {
)
.await
}
}?;
}
.context(CallServiceSnafu)?;
Ok(())
}