v0.12.0-preety_code
This commit is contained in:
+67
-15
@@ -13,10 +13,16 @@ mod tests {
|
||||
let base = DateTime::<Utc>::from_timestamp(seconds, 0).unwrap();
|
||||
for offset in [10_i64, 20_i64] {
|
||||
db.add_reading(&Reading {
|
||||
id: 0, device_id: device.id.clone(), timestamp: base + Duration::seconds(offset),
|
||||
indoor_temperature: Some(22.0), outdoor_temperature: None, target_temperature: 23.0,
|
||||
power: true, source: "gree".into(),
|
||||
}).unwrap();
|
||||
id: 0,
|
||||
device_id: device.id.clone(),
|
||||
timestamp: base + Duration::seconds(offset),
|
||||
indoor_temperature: Some(22.0),
|
||||
outdoor_temperature: None,
|
||||
target_temperature: 23.0,
|
||||
power: true,
|
||||
source: "gree".into(),
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
assert_eq!(db.history_counts().unwrap().0, 2);
|
||||
assert_eq!(db.compact_history(30).unwrap(), 1);
|
||||
@@ -32,11 +38,22 @@ mod tests {
|
||||
let loaded = db.get_device(&device.id).unwrap().unwrap();
|
||||
assert_eq!(loaded.mac, device.mac);
|
||||
assert_eq!(db.list_devices().unwrap().len(), 1);
|
||||
db.log_event("info", "test", "ok", &serde_json::json!({"a":1})).unwrap();
|
||||
db.log_event("info", "test", "ok", &serde_json::json!({"a":1}))
|
||||
.unwrap();
|
||||
assert_eq!(db.list_events(10).unwrap().len(), 1);
|
||||
{
|
||||
let conn = db.lock().unwrap();
|
||||
conn.execute(queries::INSERT_EVENT, rusqlite::params![(Utc::now() - Duration::days(40)).to_rfc3339(), "info", "old", "old", "{}"] ).unwrap();
|
||||
conn.execute(
|
||||
queries::INSERT_EVENT,
|
||||
rusqlite::params![
|
||||
(Utc::now() - Duration::days(40)).to_rfc3339(),
|
||||
"info",
|
||||
"old",
|
||||
"old",
|
||||
"{}"
|
||||
],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
assert_eq!(db.prune_events(30).unwrap(), 1);
|
||||
assert_eq!(db.list_events(10).unwrap().len(), 1);
|
||||
@@ -55,16 +72,51 @@ mod tests {
|
||||
|
||||
let now = Utc::now();
|
||||
db.add_reading(&Reading {
|
||||
id: 0, device_id: device.id.clone(), timestamp: now.clone(), indoor_temperature: Some(22.5),
|
||||
outdoor_temperature: Some(31.0), target_temperature: 23.0, power: true, source: "gree".into(),
|
||||
}).unwrap();
|
||||
assert_eq!(db.list_device_history(Some(&device.id), now.clone() - Duration::minutes(1), 30, 100).unwrap().len(), 1);
|
||||
id: 0,
|
||||
device_id: device.id.clone(),
|
||||
timestamp: now.clone(),
|
||||
indoor_temperature: Some(22.5),
|
||||
outdoor_temperature: Some(31.0),
|
||||
target_temperature: 23.0,
|
||||
power: true,
|
||||
source: "gree".into(),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
db.list_device_history(
|
||||
Some(&device.id),
|
||||
now.clone() - Duration::minutes(1),
|
||||
30,
|
||||
100
|
||||
)
|
||||
.unwrap()
|
||||
.len(),
|
||||
1
|
||||
);
|
||||
|
||||
db.add_ha_reading_if_due(&HaReading {
|
||||
id: 0, entity_id: "sensor.room".into(), zone_id: Some("zone-room".into()), kind: "room".into(),
|
||||
timestamp: now.clone(), temperature: 22.1,
|
||||
}, 15).unwrap();
|
||||
assert_eq!(db.list_ha_history(Some("sensor.room"), now.clone() - Duration::minutes(1), 30, 100).unwrap().len(), 1);
|
||||
db.add_ha_reading_if_due(
|
||||
&HaReading {
|
||||
id: 0,
|
||||
entity_id: "sensor.room".into(),
|
||||
zone_id: Some("zone-room".into()),
|
||||
kind: "room".into(),
|
||||
timestamp: now.clone(),
|
||||
temperature: 22.1,
|
||||
},
|
||||
15,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
db.list_ha_history(
|
||||
Some("sensor.room"),
|
||||
now.clone() - Duration::minutes(1),
|
||||
30,
|
||||
100
|
||||
)
|
||||
.unwrap()
|
||||
.len(),
|
||||
1
|
||||
);
|
||||
assert_eq!(db.history_counts().unwrap(), (1, 0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user