diff --git a/smart-house-web/backend/src/house.rs b/smart-house-web/backend/src/house.rs index b1007ac..15876a1 100644 --- a/smart-house-web/backend/src/house.rs +++ b/smart-house-web/backend/src/house.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use std::fmt::Display; +use std::{collections::HashMap, fmt::Display}; #[derive(Debug, Serialize, Deserialize)] pub struct PowerSocket { @@ -77,3 +77,33 @@ impl From for Device { Device::Thermometer(value) } } + +#[derive(Debug, Serialize, Deserialize)] +pub struct Room { + devices: HashMap, +} + +impl Room { + pub fn new(devices: HashMap) -> Self { + Self { devices } + } + + pub fn report(&self) -> Vec { + let mut output = Vec::with_capacity(self.devices.len()); + for (name, device) in self.devices.iter() { + output.push(format!("{} : {}", name, device.report())); + } + output + } +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct House { + rooms: HashMap, +} + +impl House { + pub fn new(rooms: HashMap) -> Self { + Self { rooms } + } +} diff --git a/smart-house-web/backend/src/lib.rs b/smart-house-web/backend/src/lib.rs index 5686d22..aaa7e18 100644 --- a/smart-house-web/backend/src/lib.rs +++ b/smart-house-web/backend/src/lib.rs @@ -34,4 +34,4 @@ mod server; pub use server::run_server; mod house; -pub use house::{Device, PowerSocket, Thermometer}; +pub use house::{Device, House, PowerSocket, Room, Thermometer};