Make router and raspis always on
This commit is contained in:
parent
24551e72bf
commit
fa52f47d9d
8 changed files with 49 additions and 30 deletions
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"plugs": [
|
||||
"Tasmota-Plug-1",
|
||||
"Tasmota-Plug-2",
|
||||
"Tasmota-Plug-3",
|
||||
"Tasmota-Plug-4"
|
||||
["Tasmota-Plug-1", false],
|
||||
["Tasmota-Plug-2", false],
|
||||
["Tasmota-Plug-3", true],
|
||||
["Tasmota-Plug-4", true]
|
||||
]
|
||||
}
|
3
midea.py
3
midea.py
|
@ -1,3 +0,0 @@
|
|||
import midea_ac_lan.midea.core as midea_core
|
||||
|
||||
midea_core
|
|
@ -67,7 +67,7 @@ async function startup() {
|
|||
}
|
||||
}
|
||||
let button_icon = document.createElement('i');
|
||||
button_icon.className = "fa fa-edit";
|
||||
button_icon.className = "fa fa-pencil-square-o";
|
||||
|
||||
device_name_entry.appendChild(device_name);
|
||||
device_name_edit.appendChild(button_icon);
|
||||
|
@ -106,16 +106,21 @@ async function startup() {
|
|||
let device_power_state = document.createElement('label');
|
||||
device_power_state.innerText = device_state["power"];
|
||||
device_power_state.id = "power_" + device_id;
|
||||
let device_power_on = document.createElement('button');
|
||||
device_power_on.innerText = "On"
|
||||
device_power_on.onclick = async () => { await power_on(device_id) };
|
||||
let device_power_off = document.createElement('button');
|
||||
device_power_off.innerText = "Off"
|
||||
device_power_off.onclick = async () => { await power_off(device_id) };
|
||||
|
||||
device_power_state_entry.appendChild(device_power_state);
|
||||
device_power_state_entry.appendChild(device_power_on);
|
||||
device_power_state_entry.appendChild(device_power_off);
|
||||
|
||||
if (devices[i][2] == true) {
|
||||
let device_power_on = document.createElement('button');
|
||||
device_power_on.innerText = "On"
|
||||
device_power_on.onclick = async () => { await power_on(device_id) };
|
||||
let device_power_off = document.createElement('button');
|
||||
device_power_off.innerText = "Off"
|
||||
device_power_off.onclick = async () => { await power_off(device_id) };
|
||||
|
||||
device_power_state_entry.appendChild(device_power_on);
|
||||
device_power_state_entry.appendChild(device_power_off);
|
||||
}
|
||||
|
||||
row_device.appendChild(device_power_state_entry);
|
||||
|
||||
// create device power draw column
|
||||
|
@ -125,7 +130,7 @@ async function startup() {
|
|||
let device_power_draw_graph_button = document.createElement('button');
|
||||
device_power_draw_graph_button.onclick = async () => { await render_graph(device_id, device_descriptor) };
|
||||
let device_power_draw_graph_button_icon = document.createElement('i');
|
||||
device_power_draw_graph_button_icon.className = "fa fa-chart-bar";
|
||||
device_power_draw_graph_button_icon.className = "fa fa-line-chart";
|
||||
|
||||
device_power_draw_graph_button.appendChild(device_power_draw_graph_button_icon);
|
||||
device_power_draw_entry.appendChild(device_power_draw);
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
<head>
|
||||
<title>Smart Homeserver</title>
|
||||
<link href="/css/index.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fork-awesome@1.2.0/css/fork-awesome.min.css"
|
||||
integrity="sha256-XoaMnoYC5TH6/+ihMEnospgm0J1PM/nioxbOUdnM8HY=" crossorigin="anonymous">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
@ -192,7 +192,7 @@ mod test {
|
|||
let db = DataBase::new("home_server.db").await?;
|
||||
let devices = Devices::read("devices.conf").await?;
|
||||
|
||||
for plug in devices.plugs {
|
||||
for (plug, _) in devices.plugs {
|
||||
println!("===== data for plug {plug} =====");
|
||||
|
||||
let days: HashMap<NaiveDate, HashMap<u32, Vec<f32>>> = split_into_days(
|
||||
|
|
30
src/db.rs
30
src/db.rs
|
@ -37,6 +37,7 @@ impl DataBase {
|
|||
id INTEGER PRIMARY KEY,
|
||||
device VARCHAR(60) NOT NULL,
|
||||
type VARCHAR(30) NOT NULL,
|
||||
control INTEGER NOT NULL,
|
||||
name VARCHAR(80)
|
||||
)",
|
||||
[],
|
||||
|
@ -75,7 +76,7 @@ impl DataBase {
|
|||
}
|
||||
|
||||
pub fn register_devices(&self, devices: &Devices) -> Result<()> {
|
||||
for device in devices.plugs.iter() {
|
||||
for (device, control) in devices.plugs.iter() {
|
||||
self.sql.execute(
|
||||
&format!(
|
||||
"INSERT INTO devices (device, type)
|
||||
|
@ -90,6 +91,19 @@ impl DataBase {
|
|||
),
|
||||
[],
|
||||
)?;
|
||||
|
||||
let ctl = if *control { 1 } else { 0 };
|
||||
|
||||
self.sql.execute(
|
||||
&format!(
|
||||
"
|
||||
UPDATE devices
|
||||
SET control=\"{ctl}\"
|
||||
WHERE device=\"{device}\"
|
||||
"
|
||||
),
|
||||
[],
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -116,16 +130,18 @@ impl DataBase {
|
|||
.sql
|
||||
.prepare(&format!(
|
||||
"
|
||||
SELECT device, type, name
|
||||
SELECT device, type, name, control
|
||||
FROM devices
|
||||
"
|
||||
))?
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))?
|
||||
.query_map([], |row| {
|
||||
Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?))
|
||||
})?
|
||||
{
|
||||
let (device, dev_type, name): (String, String, Option<String>) = row?;
|
||||
let (device, dev_type, name, control): (String, String, Option<String>, i32) = row?;
|
||||
|
||||
match dev_type.as_str() {
|
||||
"plug" => devices.plugs.push((device, name)),
|
||||
"plug" => devices.plugs.push((device, name, control != 0)),
|
||||
|
||||
_ => panic!(),
|
||||
}
|
||||
|
@ -195,7 +211,7 @@ mod test {
|
|||
let db = DataBase::new("startup_test.db").await?;
|
||||
|
||||
db.register_devices(&Devices {
|
||||
plugs: vec!["test".to_string()],
|
||||
plugs: vec![("test".to_string(), true)],
|
||||
})?;
|
||||
|
||||
fs::remove_file("startup_test.db")?;
|
||||
|
@ -210,7 +226,7 @@ mod test {
|
|||
let device_name = "test";
|
||||
|
||||
db.register_devices(&Devices {
|
||||
plugs: vec![device_name.to_string()],
|
||||
plugs: vec![(device_name.to_string(), true)],
|
||||
})?;
|
||||
|
||||
db.write(device_name, 0, 5.5)?;
|
||||
|
|
|
@ -6,7 +6,7 @@ use serde_json::{from_str, to_string, to_string_pretty};
|
|||
|
||||
#[derive(Clone, PartialEq, Eq, Deserialize, Serialize, Debug)]
|
||||
pub struct Devices {
|
||||
pub plugs: Vec<String>,
|
||||
pub plugs: Vec<(String, bool)>,
|
||||
}
|
||||
|
||||
impl Devices {
|
||||
|
@ -24,7 +24,7 @@ impl Devices {
|
|||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
|
||||
pub struct DevicesWithName {
|
||||
pub plugs: Vec<(String, Option<String>)>,
|
||||
pub plugs: Vec<(String, Option<String>, bool)>,
|
||||
}
|
||||
|
||||
impl DevicesWithName {
|
||||
|
@ -41,7 +41,7 @@ mod test {
|
|||
#[test]
|
||||
fn create_conf() -> Result<()> {
|
||||
let devices = Devices {
|
||||
plugs: vec!["Dev1".to_string(), "Dev2".to_string()],
|
||||
plugs: vec![("Dev1".to_string(), true), ("Dev2".to_string(), false)],
|
||||
};
|
||||
|
||||
devices.save("test_devices.conf")
|
||||
|
|
|
@ -89,7 +89,7 @@ async fn main() -> Result<()> {
|
|||
let tasmota_plugs: Vec<Tasmota> = devices
|
||||
.plugs
|
||||
.iter()
|
||||
.map(|plug| Tasmota::new(plug))
|
||||
.map(|(plug, _)| Tasmota::new(plug))
|
||||
.collect();
|
||||
|
||||
try_join!(
|
||||
|
|
Loading…
Reference in a new issue