smart-house-web: в работе
This commit is contained in:
@@ -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<impl Display> {
|
||||
pub fn report(&self) -> Vec<String> {
|
||||
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<String, Room>) -> Self {
|
||||
Self { rooms }
|
||||
}
|
||||
|
||||
pub fn report(&self) -> Vec<(String, Vec<String>)> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user