From 50c8e1e9d6927339da4d2828f907ac21ebdda269 Mon Sep 17 00:00:00 2001 From: Alexander Baranov Date: Sun, 17 May 2026 15:39:05 +0300 Subject: [PATCH] =?UTF-8?q?smart-house-web:=20=D0=B2=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smart-house-web/backend/src/house.rs | 31 +++++----------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/smart-house-web/backend/src/house.rs b/smart-house-web/backend/src/house.rs index be6b972..1d9a4d3 100644 --- a/smart-house-web/backend/src/house.rs +++ b/smart-house-web/backend/src/house.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct PowerSocket { power_rate: f32, on: bool, @@ -31,7 +31,7 @@ impl PowerSocket { } } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Thermometer { temperature: f32, } @@ -51,7 +51,7 @@ impl Thermometer { } } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize)] #[serde(tag = "type")] pub enum Device { PowerSocket(PowerSocket), @@ -79,7 +79,7 @@ impl From for Device { } } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Room { devices: HashMap, } @@ -88,17 +88,9 @@ 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)] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct House { rooms: HashMap, } @@ -107,17 +99,4 @@ impl House { pub fn new(rooms: HashMap) -> Self { Self { rooms } } - - pub fn report(&self) -> Vec<(String, Vec)> { - let mut output = Vec::with_capacity(self.rooms.len()); - for (name, room) in self.rooms.iter() { - let room_report = room.report(); - output.push((format!("{}", name), room_report)); - } - output - } - - pub fn get_rooms(&self) -> &HashMap { - &self.rooms - } }