Midea/src/devices/e1.rs

212 lines
6.7 KiB
Rust
Raw Normal View History

2023-09-26 06:30:16 +00:00
use std::collections::HashMap;
use anyhow::Result;
use crate::command::Command;
2023-09-26 06:30:16 +00:00
use super::DeviceBackend;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
enum DeviceAttributes {
Power,
Status,
Mode,
Additional,
Door,
RinseAid,
Salt,
ChildLock,
UV,
Dry,
DryStatus,
Storage,
StorageStatus,
TimeRemaining,
Progress,
StorageRemaining,
Temperature,
Humidity,
Waterswitch,
WaterLack,
ErrorCode,
Softwater,
WrongOperation,
Bright,
}
impl DeviceAttributes {
fn as_str(&self) -> &str {
match self {
DeviceAttributes::Power => "power",
DeviceAttributes::Status => "status",
DeviceAttributes::Mode => "mode",
DeviceAttributes::Additional => "additional",
DeviceAttributes::Door => "door",
DeviceAttributes::RinseAid => "rinse_aid",
DeviceAttributes::Salt => "salt",
DeviceAttributes::ChildLock => "child_lock",
DeviceAttributes::UV => "uv",
DeviceAttributes::Dry => "dry",
DeviceAttributes::DryStatus => "dry_status",
DeviceAttributes::Storage => "storage",
DeviceAttributes::StorageStatus => "storage_status",
DeviceAttributes::TimeRemaining => "time_remaining",
DeviceAttributes::Progress => "progress",
DeviceAttributes::StorageRemaining => "storage_remaining",
DeviceAttributes::Temperature => "temperature",
DeviceAttributes::Humidity => "humidity",
DeviceAttributes::Waterswitch => "waterswitch",
DeviceAttributes::WaterLack => "water_lack",
DeviceAttributes::ErrorCode => "error_code",
DeviceAttributes::Softwater => "softwater",
DeviceAttributes::WrongOperation => "wrong_operation",
DeviceAttributes::Bright => "bright",
}
}
fn from_str(s: &str) -> Self {
match s {
"power" => Self::Power,
"status" => Self::Status,
"mode" => Self::Mode,
"additional" => Self::Additional,
"door" => Self::Door,
"rinse_aid" => Self::RinseAid,
"salt" => Self::Salt,
"child_lock" => Self::ChildLock,
"uv" => Self::UV,
"dry" => Self::Dry,
"dry_status" => Self::DryStatus,
"storage" => Self::Storage,
"storage_status" => Self::StorageStatus,
"time_remaining" => Self::TimeRemaining,
"progress" => Self::Progress,
"storage_remaining" => Self::StorageRemaining,
"temperature" => Self::Temperature,
"humidity" => Self::Humidity,
"waterswitch" => Self::Waterswitch,
"water_lack" => Self::WaterLack,
"error_code" => Self::ErrorCode,
"softwater" => Self::Softwater,
"wrong_operation" => Self::WrongOperation,
"bright" => Self::Bright,
_ => panic!(),
}
}
}
enum AttributeValue {
String(Option<String>),
Bool(bool),
Int(i32),
}
pub struct E1 {
modes: HashMap<u32, String>,
attributes: HashMap<DeviceAttributes, AttributeValue>,
status: [&'static str; 5],
progress: [&'static str; 6],
}
impl E1 {
pub fn new() -> Result<Self> {
let modes = [
(0x0, "Neutral Gear"),
(0x1, "Auto"),
(0x2, "Heavy"),
(0x3, "Normal"),
(0x4, "Energy Saving"),
(0x5, "Delicate"),
(0x6, "Hour"),
(0x7, "Quick"),
(0x8, "Rinse"),
(0x9, "90min"),
(0xA, "Self Clean"),
(0xB, "Fruit Wash"),
(0xC, "Self Define"),
(0xD, "Germ"),
(0xE, "Bowl Wash"),
(0xF, "Kill Germ"),
(0x10, "Sea Food Wash"),
(0x12, "Hot Pot Wash"),
(0x13, "Quiet"),
(0x14, "Less Wash"),
(0x16, "Oil Net Wash"),
(0x19, "Cloud Wash"),
]
.into_iter()
.map(|(i, s)| (i, s.to_string()))
.collect();
let attributes = [
(DeviceAttributes::Power, AttributeValue::Bool(false)),
(DeviceAttributes::Status, AttributeValue::String(None)),
(DeviceAttributes::Mode, AttributeValue::Int(0)),
(DeviceAttributes::Additional, AttributeValue::Int(0)),
(DeviceAttributes::UV, AttributeValue::Bool(false)),
(DeviceAttributes::Dry, AttributeValue::Bool(false)),
(DeviceAttributes::DryStatus, AttributeValue::Bool(false)),
(DeviceAttributes::Door, AttributeValue::Bool(false)),
(DeviceAttributes::RinseAid, AttributeValue::Bool(false)),
(DeviceAttributes::Salt, AttributeValue::Bool(false)),
(DeviceAttributes::ChildLock, AttributeValue::Bool(false)),
(DeviceAttributes::Storage, AttributeValue::Bool(false)),
(DeviceAttributes::StorageStatus, AttributeValue::Bool(false)),
(
DeviceAttributes::TimeRemaining,
AttributeValue::String(None),
),
(DeviceAttributes::Progress, AttributeValue::String(None)),
(
DeviceAttributes::StorageRemaining,
AttributeValue::String(None),
),
(DeviceAttributes::Temperature, AttributeValue::String(None)),
(DeviceAttributes::Humidity, AttributeValue::String(None)),
(DeviceAttributes::Waterswitch, AttributeValue::Bool(false)),
(DeviceAttributes::WaterLack, AttributeValue::Bool(false)),
(DeviceAttributes::ErrorCode, AttributeValue::String(None)),
(DeviceAttributes::Softwater, AttributeValue::Int(0)),
(
DeviceAttributes::WrongOperation,
AttributeValue::String(None),
),
(DeviceAttributes::Bright, AttributeValue::Int(0)),
]
.into_iter()
.collect();
let status = ["Off", "Idle", "Delay", "Running", "Error"];
let progress = ["Idle", "Pre-wash", "Wash", "Rinse", "Dry", "Complete"];
Ok(Self {
modes,
attributes,
status,
progress,
})
}
}
impl DeviceBackend for E1 {
fn build_query(&self) -> Result<Vec<Command>> {
2023-09-26 06:30:16 +00:00
todo!()
}
fn process_message(&self, msg: &[u8]) -> Result<Vec<u8>> {
2023-09-26 06:30:16 +00:00
todo!()
}
fn set_attribute(&self, attribute: &str, value: &str) -> () {
match DeviceAttributes::from_str(attribute) {
DeviceAttributes::Power => (),
DeviceAttributes::ChildLock => (),
DeviceAttributes::Storage => (),
_ => (),
}
}
}