feat: make the input_number attributes and signal support any numeric type
This commit is contained in:
@@ -4,12 +4,12 @@ use super::InputNumberMode;
|
|||||||
|
|
||||||
#[derive(Debug, FromPyObject)]
|
#[derive(Debug, FromPyObject)]
|
||||||
#[pyo3(from_item_all)]
|
#[pyo3(from_item_all)]
|
||||||
pub struct InputNumberAttributes {
|
pub struct InputNumberAttributes<Numeric> {
|
||||||
initial: Option<f64>,
|
initial: Option<Numeric>,
|
||||||
editable: bool,
|
editable: bool,
|
||||||
min: f64,
|
min: Numeric,
|
||||||
max: f64,
|
max: Numeric,
|
||||||
step: f64,
|
step: Numeric,
|
||||||
mode: InputNumberMode,
|
mode: InputNumberMode,
|
||||||
// todo: CustomUnitOfMeasurement type? probably not?
|
// todo: CustomUnitOfMeasurement type? probably not?
|
||||||
unit_of_measurement: Option<String>,
|
unit_of_measurement: Option<String>,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{future::Future, sync::Arc};
|
use std::{future::Future, str::FromStr, sync::Arc};
|
||||||
|
|
||||||
use emitter_and_signal::{Signal, SignalExt};
|
use emitter_and_signal::{Signal, SignalExt};
|
||||||
use pyo3::{Py, PyAny, PyErr, Python};
|
use pyo3::{FromPyObject, Py, PyAny, PyErr, Python};
|
||||||
use snafu::{ResultExt, Snafu};
|
use snafu::{ResultExt, Snafu};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -32,26 +32,30 @@ pub enum CreateSignalError {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn signal<'py>(
|
pub fn signal<
|
||||||
|
'py,
|
||||||
|
Numeric: 'static + uom::num::Num + Clone + Send + Sync + FromStr + for<'a, 'py2> FromPyObject<'a, 'py2>,
|
||||||
|
>(
|
||||||
py: Python<'py>,
|
py: Python<'py>,
|
||||||
home_assistant: &'py HomeAssistant,
|
home_assistant: &'py HomeAssistant,
|
||||||
object_id: ObjectId,
|
object_id: ObjectId,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
Signal<Option<Arc<Result<HomeAssistantState<f64>, StateObjectSignalError<Arc<PyErr>>>>>>,
|
Signal<
|
||||||
|
Option<Arc<Result<HomeAssistantState<Numeric>, StateObjectSignalError<Arc<PyErr>>>>>,
|
||||||
|
>,
|
||||||
impl Future<Output = Result<(), emitter_and_signal::signal::JoinError>>,
|
impl Future<Output = Result<(), emitter_and_signal::signal::JoinError>>,
|
||||||
),
|
),
|
||||||
CreateSignalError,
|
CreateSignalError,
|
||||||
> {
|
> {
|
||||||
let entity_id = EntityId(Domain::InputNumber, object_id);
|
let entity_id = EntityId(Domain::InputNumber, object_id);
|
||||||
|
|
||||||
let (signal, task1) =
|
let (signal, task1) = StateObject::<
|
||||||
StateObject::<HomeAssistantState<f64>, InputNumberAttributes, Py<PyAny>>::signal(
|
HomeAssistantState<Numeric>,
|
||||||
py,
|
InputNumberAttributes<Numeric>,
|
||||||
home_assistant,
|
Py<PyAny>,
|
||||||
entity_id,
|
>::signal(py, home_assistant, entity_id)
|
||||||
)
|
.context(StateObjectSignalSnafu)?;
|
||||||
.context(StateObjectSignalSnafu)?;
|
|
||||||
|
|
||||||
let (signal, task2) = signal
|
let (signal, task2) = signal
|
||||||
.map(|state_object_arc_result_option| {
|
.map(|state_object_arc_result_option| {
|
||||||
|
|||||||
Reference in New Issue
Block a user