changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use std::sync::{atomic::AtomicBool, Arc, Mutex};
|
||||
|
||||
use chrono::{DateTime, Datelike, Duration, NaiveDateTime, Timelike};
|
||||
use chrono::{DateTime, Datelike, TimeDelta, Timelike};
|
||||
use chrono_tz::{Europe::Berlin, Tz};
|
||||
|
||||
use esp_idf_hal::delay::Delay;
|
||||
@@ -169,7 +169,7 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
Ok(cur) => cur,
|
||||
Err(err) => {
|
||||
log::error!("time error {}", err);
|
||||
NaiveDateTime::from_timestamp_millis(0).unwrap().and_utc()
|
||||
DateTime::from_timestamp_millis(0).unwrap()
|
||||
}
|
||||
};
|
||||
//check if we know the time current > 2020
|
||||
@@ -862,7 +862,7 @@ fn determine_state_target_moisture_for_plant(
|
||||
state.no_water = true;
|
||||
}
|
||||
}
|
||||
let duration = Duration::minutes((plant_config.pump_cooldown_min).into());
|
||||
let duration = TimeDelta::try_minutes(plant_config.pump_cooldown_min as i64).unwrap();
|
||||
let next_pump = board.last_pump_time(plant) + duration;
|
||||
if next_pump > cur {
|
||||
let europe_time = next_pump.with_timezone(&Berlin);
|
||||
@@ -913,7 +913,7 @@ fn determine_next_plant(
|
||||
);
|
||||
}
|
||||
config::Mode::TimerOnly => {
|
||||
let duration = Duration::minutes((plant_config.pump_cooldown_min).into());
|
||||
let duration = TimeDelta::try_minutes(plant_config.pump_cooldown_min as i64).unwrap();
|
||||
let next_pump = board.last_pump_time(plant) + duration;
|
||||
if next_pump > cur {
|
||||
let europe_time = next_pump.with_timezone(&Berlin);
|
||||
@@ -928,7 +928,7 @@ fn determine_next_plant(
|
||||
}
|
||||
}
|
||||
config::Mode::TimerAndDeadzone => {
|
||||
let duration = Duration::minutes((60 * plant_config.pump_cooldown_min).into());
|
||||
let duration = TimeDelta::try_minutes(plant_config.pump_cooldown_min as i64).unwrap();
|
||||
let next_pump = board.last_pump_time(plant) + duration;
|
||||
if next_pump > cur {
|
||||
let europe_time = next_pump.with_timezone(&Berlin);
|
||||
|
@@ -23,7 +23,7 @@ use std::ffi::CString;
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use chrono::{DateTime, Utc};
|
||||
use ds18b20::Ds18b20;
|
||||
use std::result::Result::Ok as OkStd;
|
||||
use std::str::FromStr;
|
||||
@@ -277,8 +277,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
||||
|
||||
fn last_pump_time(&self, plant: usize) -> chrono::DateTime<Utc> {
|
||||
let ts = unsafe { LAST_WATERING_TIMESTAMP }[plant];
|
||||
let timestamp = NaiveDateTime::from_timestamp_millis(ts).unwrap();
|
||||
DateTime::<Utc>::from_naive_utc_and_offset(timestamp, Utc)
|
||||
return DateTime::from_timestamp_millis(ts).unwrap();
|
||||
}
|
||||
|
||||
fn store_last_pump_time(&mut self, plant: usize, time: chrono::DateTime<Utc>) {
|
||||
@@ -322,9 +321,9 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
||||
fn time(&mut self) -> Result<chrono::DateTime<Utc>> {
|
||||
let time = EspSystemTime {}.now().as_millis();
|
||||
let smaller_time = time as i64;
|
||||
let local_time = NaiveDateTime::from_timestamp_millis(smaller_time)
|
||||
let local_time = DateTime::from_timestamp_millis(smaller_time)
|
||||
.ok_or(anyhow!("could not convert timestamp"))?;
|
||||
Ok(local_time.and_utc())
|
||||
Ok(local_time)
|
||||
}
|
||||
|
||||
fn sntp(&mut self, max_wait_ms: u32) -> Result<chrono::DateTime<Utc>> {
|
||||
@@ -920,9 +919,8 @@ impl CreatePlantHal<'_> for PlantHal {
|
||||
);
|
||||
for i in 0..PLANT_COUNT {
|
||||
let smaller_time = LAST_WATERING_TIMESTAMP[i];
|
||||
let local_time = NaiveDateTime::from_timestamp_millis(smaller_time)
|
||||
let utc_time = DateTime::from_timestamp_millis(smaller_time)
|
||||
.ok_or(anyhow!("could not convert timestamp"))?;
|
||||
let utc_time = local_time.and_utc();
|
||||
let europe_time = utc_time.with_timezone(&Berlin);
|
||||
|
||||
println!(
|
||||
|
Reference in New Issue
Block a user