smart-house-web: в работе
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct PowerSocket {
|
pub struct PowerSocket {
|
||||||
power_rate: f32,
|
power_rate: f32,
|
||||||
on: bool,
|
on: bool,
|
||||||
@@ -31,7 +31,7 @@ impl PowerSocket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct Thermometer {
|
pub struct Thermometer {
|
||||||
temperature: f32,
|
temperature: f32,
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ impl Thermometer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub enum Device {
|
pub enum Device {
|
||||||
PowerSocket(PowerSocket),
|
PowerSocket(PowerSocket),
|
||||||
@@ -79,7 +79,7 @@ impl From<Thermometer> for Device {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct Room {
|
pub struct Room {
|
||||||
devices: HashMap<String, Device>,
|
devices: HashMap<String, Device>,
|
||||||
}
|
}
|
||||||
@@ -88,17 +88,9 @@ impl Room {
|
|||||||
pub fn new(devices: HashMap<String, Device>) -> Self {
|
pub fn new(devices: HashMap<String, Device>) -> Self {
|
||||||
Self { devices }
|
Self { devices }
|
||||||
}
|
}
|
||||||
|
|
||||||
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()));
|
|
||||||
}
|
|
||||||
output
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||||
pub struct House {
|
pub struct House {
|
||||||
rooms: HashMap<String, Room>,
|
rooms: HashMap<String, Room>,
|
||||||
}
|
}
|
||||||
@@ -107,17 +99,4 @@ impl House {
|
|||||||
pub fn new(rooms: HashMap<String, Room>) -> Self {
|
pub fn new(rooms: HashMap<String, Room>) -> Self {
|
||||||
Self { rooms }
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_rooms(&self) -> &HashMap<String, Room> {
|
|
||||||
&self.rooms
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user