Added charger as outlet type
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-03-19 22:34:26 +01:00
parent 18bca5abf4
commit 07563a6d30
6 changed files with 74 additions and 39 deletions

View File

@@ -116,6 +116,13 @@ pub struct MqttDeviceConfig {
pub topic: String,
}
#[derive(Debug, Clone, Deserialize)]
pub enum OutletType {
Outlet,
Kettle,
Charger,
}
#[derive(Debug, Clone, Deserialize)]
pub struct KettleConfig {
pub timeout: Option<u64>, // Timeout in seconds
@@ -157,7 +164,9 @@ pub enum Device {
info: InfoConfig,
#[serde(flatten)]
mqtt: MqttDeviceConfig,
kettle: Option<KettleConfig>,
#[serde(default = "default_outlet_type")]
outlet_type: OutletType,
timeout: Option<u64>, // Timeout in seconds
},
WakeOnLAN {
#[serde(flatten)]
@@ -184,6 +193,10 @@ pub enum Device {
}
}
fn default_outlet_type() -> OutletType {
OutletType::Outlet
}
fn default_broadcast_ip() -> Ipv4Addr {
Ipv4Addr::new(255, 255, 255, 255)
}
@@ -228,9 +241,9 @@ impl Device {
#[async_recursion]
pub async fn create(self, identifier: &str, config: &Config, client: AsyncClient) -> Result<DeviceBox, DeviceCreationError> {
let device = match self {
Device::IkeaOutlet { info, mqtt, kettle } => {
Device::IkeaOutlet { info, mqtt, outlet_type, timeout } => {
trace!(id = identifier, "IkeaOutlet [{} in {:?}]", info.name, info.room);
IkeaOutlet::build(&identifier, info, mqtt, kettle, client).await
IkeaOutlet::build(&identifier, info, mqtt, outlet_type, timeout, client).await
.map(device_box)?
},
Device::WakeOnLAN { info, mqtt, mac_address, broadcast_ip } => {