From 5a87aaecadef726a269d06c9cb92a536e35f6506 Mon Sep 17 00:00:00 2001 From: Alexander Baranov Date: Fri, 15 May 2026 18:38:09 +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 | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/smart-house-web/backend/src/house.rs b/smart-house-web/backend/src/house.rs index 15876a1..96ab237 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::{collections::HashMap, fmt::Display}; +use std::collections::HashMap; #[derive(Debug, Serialize, Deserialize)] pub struct PowerSocket { @@ -24,7 +24,7 @@ impl PowerSocket { if self.is_on() { self.power_rate } else { 0.0 } } - pub fn report(&self) -> impl Display { + pub fn report(&self) -> String { let state = if self.is_on() { "ON" } else { "OFF" }; let power = self.get_power(); format!("PowerSocket[ {} : {:02.1} ]", state, power) @@ -45,7 +45,7 @@ impl Thermometer { self.temperature } - pub fn report(&self) -> impl Display { + pub fn report(&self) -> String { let temperature = self.get_temperature(); format!("Thermometer[ {:02.1} ]", temperature) } @@ -58,7 +58,7 @@ pub enum Device { } impl Device { - pub fn report(&self) -> impl Display { + pub fn report(&self) -> String { match self { Device::PowerSocket(v) => format!("{}", v.report()), Device::Thermometer(v) => format!("{}", v.report()), @@ -88,7 +88,7 @@ impl Room { Self { devices } } - pub fn report(&self) -> Vec { + 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())); @@ -106,4 +106,13 @@ 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 + } }