Add basic exchange of relay states
This commit is contained in:
		
							parent
							
								
									0460e838bc
								
							
						
					
					
						commit
						8a83602d6a
					
				
					 10 changed files with 153 additions and 41 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,5 @@
 | 
			
		|||
use std::ops::DerefMut;
 | 
			
		||||
 | 
			
		||||
use futures::executor::block_on;
 | 
			
		||||
use serde_derive::{Deserialize, Serialize};
 | 
			
		||||
use sqlx::pool::PoolConnection;
 | 
			
		||||
use sqlx::Sqlite;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
use chrono::{Local, NaiveTime};
 | 
			
		||||
use chrono::NaiveTime;
 | 
			
		||||
use futures::executor::block_on;
 | 
			
		||||
use serde_derive::{Deserialize, Serialize};
 | 
			
		||||
use sqlx::pool::PoolConnection;
 | 
			
		||||
| 
						 | 
				
			
			@ -17,7 +17,7 @@ pub struct Relay {
 | 
			
		|||
	pub controller_id: ControllerUid,
 | 
			
		||||
	pub schedules: Vec<DbSchedule>,
 | 
			
		||||
	pub active_schedule: DbSchedule,
 | 
			
		||||
	pub is_on: bool,
 | 
			
		||||
	pub is_on: Option<bool>,
 | 
			
		||||
	pub tags: Vec<String>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -45,8 +45,7 @@ impl FromDbModel for Relay {
 | 
			
		|||
		let schedules = block_on(DbJunctionRelaySchedule::get_schedules(conn, &db_model))?;
 | 
			
		||||
		let active_schedule = block_on(db_model.get_active_schedule(conn))?;
 | 
			
		||||
 | 
			
		||||
		let now = Local::now().time();
 | 
			
		||||
		let is_on = active_schedule.is_on(&now);
 | 
			
		||||
		let is_on = None;
 | 
			
		||||
 | 
			
		||||
		Ok(Relay {
 | 
			
		||||
			r: db_model,
 | 
			
		||||
| 
						 | 
				
			
			@ -74,10 +73,6 @@ impl Relay {
 | 
			
		|||
		conn: &mut PoolConnection<Sqlite>,
 | 
			
		||||
	) -> Result<(), DatabaseError> {
 | 
			
		||||
		self.active_schedule = block_on(self.r.get_active_schedule(conn))?;
 | 
			
		||||
 | 
			
		||||
		let now = Local::now().time();
 | 
			
		||||
		self.is_on = self.active_schedule.is_on(&now);
 | 
			
		||||
 | 
			
		||||
		Ok(())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue