feat: static Event
and Context
types
This commit is contained in:
@@ -1,24 +1,14 @@
|
||||
use pyo3::prelude::*;
|
||||
|
||||
use crate::home_assistant::event::event::Event;
|
||||
|
||||
use super::id::Id;
|
||||
|
||||
/// The context that triggered something.
|
||||
#[derive(Debug, FromPyObject)]
|
||||
pub struct Context {
|
||||
pub struct Context<Event> {
|
||||
pub id: Id,
|
||||
pub user_id: Option<String>,
|
||||
pub parent_id: Option<String>,
|
||||
/// In order to prevent cycles, the user must extract this to an [`Event<Arbitrary>`](super::event::Event) themself (or even specify a specific type parameter!)
|
||||
origin_event: Py<PyAny>,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn origin_event<'py, Type: FromPyObject<'py>, Data: FromPyObject<'py>>(
|
||||
&self,
|
||||
py: Python<'py>,
|
||||
) -> PyResult<Event<Type, Data>> {
|
||||
self.origin_event.extract(py)
|
||||
}
|
||||
/// In order to prevent cycles, the user must decide to pass [`Py<PyAny>`] for the `Event` type here
|
||||
/// or for the `Context` type in [`Event`]
|
||||
pub origin_event: Event,
|
||||
}
|
||||
|
Reference in New Issue
Block a user