chore: extract python_utils and home-assistant to their own crates
This commit is contained in:
34
home-assistant/src/state_machine.rs
Normal file
34
home-assistant/src/state_machine.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user