homework: finish

This commit is contained in:
2 changed files with 19 additions and 1 deletions

View File

@@ -4,17 +4,21 @@ use smart_house::{House, PowerSocket, PrintStatus, Room, Thermometer, room};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let house = create_house_demo()?;
house.print_status();
Ok(())
}
fn create_house_demo() -> Result<House, Box<dyn std::error::Error>> {
println!("# Create new smart house");
let mut psoc = PowerSocket::connect("127.0.0.1:10001")?;
psoc.set_on(!psoc.is_on());
let house = House::new(
[(
"Main".to_string(),
room!(
"PSocA" => PowerSocket::connect("127.0.0.1:10001")?,
"PSocA" => psoc,
"ThermA" => Thermometer::connect("127.0.0.1:10002")?,
),
)]