feat: input_number signal support, implement Clone for a lot of error types

This commit is contained in:
2026-07-14 22:53:42 -04:00
parent 38c30d87d0
commit e3c54a996e
10 changed files with 196 additions and 32 deletions

View File

@@ -1,4 +1,4 @@
use std::convert::Infallible;
use std::{convert::Infallible, sync::Arc};
use pyo3::{
types::PyAnyMethods as _, Borrowed, Bound, FromPyObject, IntoPyObject, Py, PyAny, PyErr, Python,
@@ -33,22 +33,26 @@ impl<'py> IntoPyObject<'py> for &HomeAssistant {
}
}
#[derive(Debug, Snafu)]
#[derive(Debug, Clone, Snafu)]
pub enum GetStatesError {
/// couldn't get the `states` attribute on the Home Assistant object
GetStatesAttributeError { source: PyErr },
GetStatesAttributeError { source: Arc<PyErr> },
/// couldn't extract the `states` as a [`StateMachine`]
ExtractStateMachineError { source: TypeByNameValidationError },
ExtractStateMachineError {
source: Arc<TypeByNameValidationError>,
},
}
#[derive(Debug, Snafu)]
#[derive(Debug, Clone, Snafu)]
pub enum GetServicesError {
/// couldn't get the `services` attribute on the Home Assistant object
GetServicesAttributeError { source: PyErr },
GetServicesAttributeError { source: Arc<PyErr> },
/// couldn't extract the `states` as a [`ServiceRegistry`]
ExtractServiceRegistryError { source: TypeByNameValidationError },
ExtractServiceRegistryError {
source: Arc<TypeByNameValidationError>,
},
}
impl HomeAssistant {
@@ -74,15 +78,23 @@ impl HomeAssistant {
let states = self
.0
.getattr(py, "states")
.map_err(Arc::new)
.context(GetStatesAttributeSnafu)?;
states.extract(py).context(ExtractStateMachineSnafu)
states
.extract(py)
.map_err(Arc::new)
.context(ExtractStateMachineSnafu)
}
pub fn services(&self, py: Python<'_>) -> Result<ServiceRegistry, GetServicesError> {
let services = self
.0
.getattr(py, "services")
.map_err(Arc::new)
.context(GetServicesAttributeSnafu)?;
services.extract(py).context(ExtractServiceRegistrySnafu)
services
.extract(py)
.map_err(Arc::new)
.context(ExtractServiceRegistrySnafu)
}
}