homework: fine tune
This commit is contained in:
@@ -1,9 +1,14 @@
|
|||||||
//! Пример работы умного дома с имитаторами
|
//! Пример работы умного дома с имитаторами
|
||||||
|
|
||||||
use smart_house::{House, PowerSocket, PrintStatus, Room, Thermometer, room};
|
use smart_house::{Device, House, PowerSocket, PrintStatus, Room, Thermometer, room};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let house = create_house_demo()?;
|
let mut house = create_house_demo()?;
|
||||||
|
|
||||||
|
let dev = house.get_room_mut("Main").unwrap().get_device_mut("PSocA").unwrap();
|
||||||
|
if let Device::PowerSocket(psoc) = dev {
|
||||||
|
psoc.set_on(!psoc.is_on());
|
||||||
|
}
|
||||||
|
|
||||||
house.print_status();
|
house.print_status();
|
||||||
|
|
||||||
@@ -12,13 +17,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
fn create_house_demo() -> Result<House, Box<dyn std::error::Error>> {
|
fn create_house_demo() -> Result<House, Box<dyn std::error::Error>> {
|
||||||
println!("# Create new smart house");
|
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(
|
let house = House::new(
|
||||||
[(
|
[(
|
||||||
"Main".to_string(),
|
"Main".to_string(),
|
||||||
room!(
|
room!(
|
||||||
"PSocA" => psoc,
|
"PSocA" => PowerSocket::connect("127.0.0.1:10001")?,
|
||||||
"ThermA" => Thermometer::connect("127.0.0.1:10002")?,
|
"ThermA" => Thermometer::connect("127.0.0.1:10002")?,
|
||||||
),
|
),
|
||||||
)]
|
)]
|
||||||
|
|||||||
Reference in New Issue
Block a user