diff --git a/smart-house/README.md b/smart-house/README.md index 0e0a2fc..03badf8 100644 --- a/smart-house/README.md +++ b/smart-house/README.md @@ -45,9 +45,9 @@ Для примера использования: -- [ ] Реализована в виде bin крейта. -- [ ] Создайте экземпляр умного дома и выведете отчёт о его содержимом. -- [ ] Для уже созданного экземпляра дома выключите умную розетку в одной из комнат. Снова выведите отчёт. +- [x] Реализована в виде bin крейта. +- [x] Создайте экземпляр умного дома и выведете отчёт о его содержимом. +- [x] Для уже созданного экземпляра дома выключите умную розетку в одной из комнат. Снова выведите отчёт. **Критерии оценки**: diff --git a/smart-house/src/main.rs b/smart-house/src/main.rs index f328e4d..08b7e87 100644 --- a/smart-house/src/main.rs +++ b/smart-house/src/main.rs @@ -1 +1,38 @@ -fn main() {} +use smart_house::{Device, House, PowerSocket, Room, Thermometer}; + +fn main() { + let mut house = House::new( + "A house of dream", + Box::new([ + Room::new( + "Hall", + Box::new([Device::PowerSocket(PowerSocket::new(9.5, true)), Device::Thermometer(Thermometer::new(20.1))]), + ), + Room::new( + "Main", + Box::new([ + Device::PowerSocket(PowerSocket::new(11.2, true)), + Device::Thermometer(Thermometer::new(24.5)), + Device::PowerSocket(PowerSocket::new(10.4, true)), + ]), + ), + Room::new( + "Bedroom", + Box::new([Device::Thermometer(Thermometer::new(19.3)), Device::PowerSocket(PowerSocket::new(12.1, true))]), + ), + ]), + ); + + house.print_status(); + + print!("# Switching off a power socket in Hall... "); + let Device::PowerSocket(power_socket) = house.get_room_mut(0).get_device_mut(0) else { + println!("FAILED!"); + return; + }; + power_socket.set_on(false); + println!("SUCCESS"); + println!(); + + house.print_status(); +} diff --git a/smart-house/src/power_socket.rs b/smart-house/src/power_socket.rs index 7e0fdc4..78d9808 100644 --- a/smart-house/src/power_socket.rs +++ b/smart-house/src/power_socket.rs @@ -1,5 +1,3 @@ -#![allow(unused)] - use std::fmt::Display; pub struct PowerSocket { diff --git a/smart-house/src/room.rs b/smart-house/src/room.rs index be5fa4e..3718b37 100644 --- a/smart-house/src/room.rs +++ b/smart-house/src/room.rs @@ -1,5 +1,3 @@ -#![allow(unused)] - use crate::Device; pub struct Room { diff --git a/smart-house/src/thermometer.rs b/smart-house/src/thermometer.rs index 8a195e3..d41fcd4 100644 --- a/smart-house/src/thermometer.rs +++ b/smart-house/src/thermometer.rs @@ -1,5 +1,3 @@ -#![allow(unused)] - use std::fmt::Display; pub struct Thermometer {