diff --git a/src/home_assistant/entity_id.rs b/src/home_assistant/entity_id.rs index 0a7bb81..ef3356a 100644 --- a/src/home_assistant/entity_id.rs +++ b/src/home_assistant/entity_id.rs @@ -1,6 +1,6 @@ -use std::{fmt::Display, str::FromStr}; +use std::{convert::Infallible, fmt::Display, str::FromStr}; -use pyo3::{exceptions::PyValueError, prelude::*}; +use pyo3::{exceptions::PyValueError, prelude::*, types::PyString}; use snafu::{ResultExt, Snafu}; use super::{ @@ -58,3 +58,14 @@ impl<'py> FromPyObject<'py> for EntityId { Ok(entity_id) } } + +impl<'py> IntoPyObject<'py> for &EntityId { + type Target = PyString; + type Output = Bound<'py, Self::Target>; + type Error = Infallible; + + fn into_pyobject(self, py: Python<'py>) -> Result { + let s = self.to_string(); + s.into_pyobject(py) + } +}