Report AirFilter humidity
This commit is contained in:
@@ -17,4 +17,6 @@ pub struct Attributes {
|
||||
pub command_only_fan_speed: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub available_fan_speeds: Option<AvailableSpeeds>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub query_only_humidity_setting: Option<bool>,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use serde::Serialize;
|
||||
use crate::errors::{DeviceError, ErrorCode};
|
||||
use crate::request::execute::CommandType;
|
||||
use crate::response;
|
||||
use crate::traits::{FanSpeed, OnOff, Scene, Trait};
|
||||
use crate::traits::{FanSpeed, HumiditySetting, OnOff, Scene, Trait};
|
||||
use crate::types::Type;
|
||||
|
||||
// TODO: Find a more elegant way to do this
|
||||
@@ -42,7 +42,7 @@ where
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
#[impl_cast::device(As: OnOff + Scene + FanSpeed)]
|
||||
#[impl_cast::device(As: OnOff + Scene + FanSpeed + HumiditySetting)]
|
||||
pub trait GoogleHomeDevice: AsGoogleHomeDevice + Sync + Send + 'static {
|
||||
fn get_device_type(&self) -> Type;
|
||||
fn get_device_name(&self) -> Name;
|
||||
@@ -95,6 +95,12 @@ pub trait GoogleHomeDevice: AsGoogleHomeDevice + Sync + Send + 'static {
|
||||
device.attributes.available_fan_speeds = Some(fan_speed.available_speeds());
|
||||
}
|
||||
|
||||
if let Some(humidity_setting) = As::<dyn HumiditySetting>::cast(self) {
|
||||
traits.push(Trait::HumiditySetting);
|
||||
device.attributes.query_only_humidity_setting =
|
||||
humidity_setting.query_only_humidity_setting();
|
||||
}
|
||||
|
||||
device.traits = traits;
|
||||
|
||||
device
|
||||
@@ -120,6 +126,11 @@ pub trait GoogleHomeDevice: AsGoogleHomeDevice + Sync + Send + 'static {
|
||||
device.state.current_fan_speed_setting = Some(fan_speed.current_speed().await);
|
||||
}
|
||||
|
||||
if let Some(humidity_setting) = As::<dyn HumiditySetting>::cast(self) {
|
||||
device.state.humidity_ambient_percent =
|
||||
Some(humidity_setting.humidity_ambient_percent().await);
|
||||
}
|
||||
|
||||
device
|
||||
}
|
||||
|
||||
|
||||
@@ -36,4 +36,7 @@ pub struct State {
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub current_fan_speed_setting: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub humidity_ambient_percent: Option<isize>,
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ mod tests {
|
||||
let state = State {
|
||||
on: Some(true),
|
||||
current_fan_speed_setting: None,
|
||||
humidity_ambient_percent: None,
|
||||
};
|
||||
let mut command = Command::new(Status::Success);
|
||||
command.states = Some(States {
|
||||
|
||||
@@ -11,6 +11,8 @@ pub enum Trait {
|
||||
Scene,
|
||||
#[serde(rename = "action.devices.traits.FanSpeed")]
|
||||
FanSpeed,
|
||||
#[serde(rename = "action.devices.traits.HumiditySetting")]
|
||||
HumiditySetting,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -72,3 +74,14 @@ pub trait FanSpeed {
|
||||
async fn current_speed(&self) -> String;
|
||||
async fn set_speed(&self, speed: &str) -> Result<(), ErrorCode>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
#[impl_cast::device_trait]
|
||||
pub trait HumiditySetting {
|
||||
// TODO: This implementation is not complete, I have only implemented what I need right now
|
||||
fn query_only_humidity_setting(&self) -> Option<bool> {
|
||||
None
|
||||
}
|
||||
|
||||
async fn humidity_ambient_percent(&self) -> isize;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user