feat: static Event and Context types

This commit is contained in:
2025-03-13 16:01:52 -04:00
parent 96495b2a85
commit 95b7f38fc1
5 changed files with 21 additions and 29 deletions

View File

@@ -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,
}