Use correct db for reading

This commit is contained in:
hodasemi 2023-09-20 15:35:35 +02:00
parent 4ae0c30171
commit 922f8d82a1
3 changed files with 5 additions and 7 deletions

View file

@ -189,7 +189,7 @@ mod test {
price_list.push(("tibber hourly (optimal)", tibber_hourly_prices_optimal)); price_list.push(("tibber hourly (optimal)", tibber_hourly_prices_optimal));
let db = DataBase::new("data.db").await?; let db = DataBase::new("home_server.db").await?;
let devices = Devices::read("devices.conf").await?; let devices = Devices::read("devices.conf").await?;
for plug in devices.plugs { for plug in devices.plugs {

View file

@ -47,14 +47,10 @@ impl DataBase {
pub fn read(&self, device: &str) -> Result<Vec<(u64, f32)>> { pub fn read(&self, device: &str) -> Result<Vec<(u64, f32)>> {
self.sql self.sql
.prepare(&format!( .prepare(&format!(
// "
// SELECT time, watts
// FROM data
// WHERE device={device}
// "
" "
SELECT time, watts SELECT time, watts
FROM data FROM data
WHERE device=\"{device}\"
" "
))? ))?
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))? .query_map([], |row| Ok((row.get(0)?, row.get(1)?)))?

View file

@ -41,6 +41,8 @@ async fn main() -> Result<()> {
.lock() .lock()
.unwrap() .unwrap()
.write(plug.name(), since_epoch()?, usage)?; .write(plug.name(), since_epoch()?, usage)?;
println!("{} uses {usage} W", plug.name());
} }
Ok::<(), anyhow::Error>(()) Ok::<(), anyhow::Error>(())