feat: static Attributes type

This commit is contained in:
2025-03-13 16:15:46 -04:00
parent d9960a1650
commit 28ad5d7345
3 changed files with 13 additions and 9 deletions

View File

@@ -24,12 +24,16 @@ impl<'py> FromPyObject<'py> for Type {
#[derive(Debug, FromPyObject)] #[derive(Debug, FromPyObject)]
#[pyo3(from_item_all)] #[pyo3(from_item_all)]
pub struct Data<OldStateContextEvent, NewStateContextEvent> { pub struct Data<OldAttributes, OldStateContextEvent, NewAttributes, NewStateContextEvent> {
pub entity_id: EntityId, pub entity_id: EntityId,
pub old_state: Option<State<OldStateContextEvent>>, pub old_state: Option<State<OldAttributes, OldStateContextEvent>>,
pub new_state: Option<State<NewStateContextEvent>>, pub new_state: Option<State<NewAttributes, NewStateContextEvent>>,
} }
/// A state changed event is fired when on state write the state is changed. /// A state changed event is fired when on state write the state is changed.
pub type Event<OldStateContextEvent, NewStateContextEvent, Context> = pub type Event<OldAttributes, OldStateContextEvent, NewAttributes, NewStateContextEvent, Context> =
super::super::event::Event<Type, Data<OldStateContextEvent, NewStateContextEvent>, Context>; super::super::event::Event<
Type,
Data<OldAttributes, OldStateContextEvent, NewAttributes, NewStateContextEvent>,
Context,
>;

View File

@@ -6,10 +6,10 @@ use crate::{arbitrary::map::Map, home_assistant::entity_id::EntityId};
use super::event::context::context::Context; use super::event::context::context::Context;
#[derive(Debug, FromPyObject)] #[derive(Debug, FromPyObject)]
pub struct State<ContextEvent> { pub struct State<Attributes, ContextEvent> {
pub entity_id: EntityId, pub entity_id: EntityId,
pub state: String, pub state: String,
pub attributes: Map, pub attributes: Attributes,
pub last_changed: Option<DateTime<Utc>>, pub last_changed: Option<DateTime<Utc>>,
pub last_reported: Option<DateTime<Utc>>, pub last_reported: Option<DateTime<Utc>>,
pub last_updated: Option<DateTime<Utc>>, pub last_updated: Option<DateTime<Utc>>,

View File

@@ -21,11 +21,11 @@ impl<'py> FromPyObject<'py> for StateMachine {
} }
impl StateMachine { impl StateMachine {
pub fn get<ContextEvent: for<'py> FromPyObject<'py>>( pub fn get<Attributes: for<'py> FromPyObject<'py>, ContextEvent: for<'py> FromPyObject<'py>>(
&self, &self,
py: &Python, py: &Python,
entity_id: EntityId, entity_id: EntityId,
) -> Result<Option<State<ContextEvent>>, PyErr> { ) -> Result<Option<State<Attributes, ContextEvent>>, PyErr> {
let args = (entity_id.to_string(),); let args = (entity_id.to_string(),);
let state = self.0.call_method1(*py, "get", args)?; let state = self.0.call_method1(*py, "get", args)?;
state.extract(*py) state.extract(*py)