chore: extract python_utils and home-assistant to their own crates

This commit is contained in:
2025-04-21 21:26:14 -04:00
parent e4fd9844cc
commit f8b269b6ce
36 changed files with 76 additions and 40 deletions

View File

@@ -0,0 +1,34 @@
use super::entity_id::EntityId;
use super::state_object::StateObject;
use pyo3::prelude::*;
use python_utils::{detach, validate_type_by_name};
#[derive(Debug)]
pub struct StateMachine(Py<PyAny>);
impl<'py> FromPyObject<'py> for StateMachine {
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
// region: Validation
validate_type_by_name(ob, "StateMachine")?;
// endregion: Validation
Ok(Self(detach(ob)))
}
}
impl StateMachine {
pub fn get<
'py,
State: FromPyObject<'py>,
Attributes: FromPyObject<'py>,
ContextEvent: FromPyObject<'py>,
>(
&self,
py: Python<'py>,
entity_id: EntityId,
) -> PyResult<Option<StateObject<State, Attributes, ContextEvent>>> {
let args = (entity_id.to_string(),);
let state = self.0.call_method1(py, "get", args)?;
state.extract(py)
}
}