feat: input_number signal support, implement Clone for a lot of error types
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user