feat(driver-kasa): support color temperature
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
|
||||||
use palette::{encoding::Srgb, Hsv, IntoColor};
|
use palette::{encoding::Srgb, Hsv, IntoColor};
|
||||||
use protocol::light::{GetState, Kelvin, SetState, TurnToColor, TurnToTemperature};
|
use protocol::light::{GetState, SetState, TurnToColor, TurnToTemperature};
|
||||||
use snafu::{ResultExt, Snafu};
|
use snafu::{ResultExt, Snafu};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
connection::{HandleError, LB130USHandle},
|
connection::{HandleError, LB130USHandle},
|
||||||
messages::{
|
messages::{
|
||||||
Angle, Hsb, LightState, Off, On, Percentage, SetLightHsv, SetLightLastOn, SetLightOff,
|
Angle, Hsb, LightState, Off, On, Percentage, SetLightHsv, SetLightKelvin, SetLightLastOn,
|
||||||
SetLightStateArgs, SetLightTo,
|
SetLightOff, SetLightStateArgs, SetLightTo,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -64,11 +64,33 @@ impl SetState for LB130USHandle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TurnToTemperature for LB130USHandle {
|
#[derive(Debug, Snafu)]
|
||||||
type Error = Infallible; // TODO
|
#[snafu(module)]
|
||||||
|
pub enum TurnToTemperatureError {
|
||||||
|
HandleError { source: HandleError },
|
||||||
|
}
|
||||||
|
|
||||||
async fn turn_to_temperature(&mut self, temperature: Kelvin) -> Result<(), Self::Error> {
|
impl TurnToTemperature for LB130USHandle {
|
||||||
todo!()
|
type Error = TurnToTemperatureError;
|
||||||
|
|
||||||
|
async fn turn_to_temperature(
|
||||||
|
&mut self,
|
||||||
|
temperature: protocol::light::Kelvin,
|
||||||
|
) -> Result<(), Self::Error> {
|
||||||
|
// TODO: re-evaluate saturating
|
||||||
|
let color_temp = crate::messages::Kelvin::new_saturating(temperature.get());
|
||||||
|
|
||||||
|
self.set_light_state(SetLightStateArgs {
|
||||||
|
to: SetLightTo::Kelvin(SetLightKelvin {
|
||||||
|
on_off: On,
|
||||||
|
color_temp,
|
||||||
|
}),
|
||||||
|
transition: None,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.context(turn_to_temperature_error::HandleSnafu)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -388,13 +388,19 @@ pub struct SetLightHsv {
|
|||||||
pub hsb: Hsb,
|
pub hsb: Hsb,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct SetLightKelvin {
|
||||||
|
pub on_off: On,
|
||||||
|
pub color_temp: Kelvin,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum SetLightTo {
|
pub enum SetLightTo {
|
||||||
Off(SetLightOff),
|
Off(SetLightOff),
|
||||||
LastOn(SetLightLastOn),
|
LastOn(SetLightLastOn),
|
||||||
Hsv(SetLightHsv),
|
Hsv(SetLightHsv),
|
||||||
// TODO: kelvin
|
Kelvin(SetLightKelvin),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, derive_more::From)]
|
#[derive(Debug, Clone, derive_more::From)]
|
||||||
|
|||||||
Reference in New Issue
Block a user