Added temperature to air_filter
This commit is contained in:
parent
bab85a092e
commit
f7b709a2c7
|
@ -1,3 +1,4 @@
|
||||||
|
#![allow(non_snake_case)]
|
||||||
use automation_cast::Cast;
|
use automation_cast::Cast;
|
||||||
use google_home_macro::traits;
|
use google_home_macro::traits;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
@ -33,6 +34,13 @@ traits! {
|
||||||
query_only_humidity_setting: Option<bool>,
|
query_only_humidity_setting: Option<bool>,
|
||||||
|
|
||||||
fn humidity_ambient_percent(&self) -> Result<isize, ErrorCode>,
|
fn humidity_ambient_percent(&self) -> Result<isize, ErrorCode>,
|
||||||
|
},
|
||||||
|
"action.devices.traits.TemperatureControl" => trait TemperatureSetting {
|
||||||
|
query_only_temperature_control: Option<bool>,
|
||||||
|
// TODO: Add rename
|
||||||
|
temperatureUnitForUX: TemperatureUnit,
|
||||||
|
|
||||||
|
fn temperature_ambient_celsius(&self) -> f32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,3 +61,11 @@ pub struct AvailableSpeeds {
|
||||||
pub speeds: Vec<Speed>,
|
pub speeds: Vec<Speed>,
|
||||||
pub ordered: bool,
|
pub ordered: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub enum TemperatureUnit {
|
||||||
|
#[serde(rename = "C")]
|
||||||
|
Celsius,
|
||||||
|
#[serde(rename = "F")]
|
||||||
|
Fahrenheit,
|
||||||
|
}
|
||||||
|
|
|
@ -248,7 +248,7 @@ fn get_state_struct(t: &Trait) -> proc_macro2::TokenStream {
|
||||||
|
|
||||||
let name = get_state_struct_ident(t);
|
let name = get_state_struct_ident(t);
|
||||||
quote! {
|
quote! {
|
||||||
#[derive(Debug, Default, serde::Serialize)]
|
#[derive(Debug, serde::Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct #name {
|
struct #name {
|
||||||
#(#fields,)*
|
#(#fields,)*
|
||||||
|
|
|
@ -2,7 +2,10 @@ use async_trait::async_trait;
|
||||||
use automation_macro::{LuaDevice, LuaDeviceConfig};
|
use automation_macro::{LuaDevice, LuaDeviceConfig};
|
||||||
use google_home::device::Name;
|
use google_home::device::Name;
|
||||||
use google_home::errors::ErrorCode;
|
use google_home::errors::ErrorCode;
|
||||||
use google_home::traits::{AvailableSpeeds, FanSpeed, HumiditySetting, OnOff, Speed, SpeedValue};
|
use google_home::traits::{
|
||||||
|
AvailableSpeeds, FanSpeed, HumiditySetting, OnOff, Speed, SpeedValue, TemperatureSetting,
|
||||||
|
TemperatureUnit,
|
||||||
|
};
|
||||||
use google_home::types::Type;
|
use google_home::types::Type;
|
||||||
use rumqttc::Publish;
|
use rumqttc::Publish;
|
||||||
use tracing::{debug, error, trace, warn};
|
use tracing::{debug, error, trace, warn};
|
||||||
|
@ -69,6 +72,7 @@ impl LuaDeviceCreate for AirFilter {
|
||||||
last_known_state: AirFilterState {
|
last_known_state: AirFilterState {
|
||||||
state: AirFilterFanState::Off,
|
state: AirFilterFanState::Off,
|
||||||
humidity: 0.0,
|
humidity: 0.0,
|
||||||
|
temperature: 0.0,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -229,3 +233,19 @@ impl HumiditySetting for AirFilter {
|
||||||
Ok(self.last_known_state.humidity.round() as isize)
|
Ok(self.last_known_state.humidity.round() as isize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TemperatureSetting for AirFilter {
|
||||||
|
fn query_only_temperature_control(&self) -> Option<bool> {
|
||||||
|
Some(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
fn temperatureUnitForUX(&self) -> TemperatureUnit {
|
||||||
|
TemperatureUnit::Celsius
|
||||||
|
}
|
||||||
|
|
||||||
|
fn temperature_ambient_celsius(&self) -> f32 {
|
||||||
|
// HACK: Round to one decimal place
|
||||||
|
(10.0 * self.last_known_state.temperature).round() / 10.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -261,6 +261,7 @@ pub struct SetAirFilterFanState {
|
||||||
pub struct AirFilterState {
|
pub struct AirFilterState {
|
||||||
pub state: AirFilterFanState,
|
pub state: AirFilterFanState,
|
||||||
pub humidity: f32,
|
pub humidity: f32,
|
||||||
|
pub temperature: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SetAirFilterFanState {
|
impl SetAirFilterFanState {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user