feat: early interface with Python

This commit is contained in:
2025-03-13 15:38:51 -04:00
parent afe5eae96b
commit 96495b2a85
22 changed files with 623 additions and 6 deletions

View File

@@ -0,0 +1,29 @@
use pyo3::prelude::*;
use crate::{
home_assistant::entity_id::EntityId,
python_utils::{detach, validate_type_by_name},
};
use super::state::State;
#[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(&self, py: &Python, entity_id: EntityId) -> Result<Option<State>, PyErr> {
let args = (entity_id.to_string(),);
let state = self.0.call_method1(*py, "get", args)?;
state.extract(*py)
}
}