From 368eb13089f8d5f43aeae8314f9bae5ab2c19f6b Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 16 Sep 2024 22:41:20 +0200 Subject: [PATCH] Add relay state history proto --- central_backend/src/energy/mod.rs | 1 + .../src/energy/relay_state_history.rs | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 central_backend/src/energy/relay_state_history.rs diff --git a/central_backend/src/energy/mod.rs b/central_backend/src/energy/mod.rs index c080861..2922113 100644 --- a/central_backend/src/energy/mod.rs +++ b/central_backend/src/energy/mod.rs @@ -1,3 +1,4 @@ pub mod consumption; pub mod energy_actor; pub mod engine; +pub mod relay_state_history; diff --git a/central_backend/src/energy/relay_state_history.rs b/central_backend/src/energy/relay_state_history.rs new file mode 100644 index 0000000..117e094 --- /dev/null +++ b/central_backend/src/energy/relay_state_history.rs @@ -0,0 +1,44 @@ +use crate::devices::device::DeviceRelayID; + +/// # RelayStateHistory +/// +/// This structures handles the manipulation of relay state history files +/// +/// These file are binary file optimizing used space. +pub struct RelayStateHistory { + id: DeviceRelayID, + day: usize, + buff: Vec, +} + +impl RelayStateHistory { + /// Open relay state history file, if it exist, or create an empty one + pub fn open(id: DeviceRelayID, day: usize) -> anyhow::Result { + todo!() + } + + /// Create a new in memory dev relay state history + fn new_memory(id: DeviceRelayID, day: usize) -> Self { + todo!() + } + + /// Resolve time offset of a given time in buffer + fn resolve_offset(&self, time: i64) -> anyhow::Result<(usize, u8)> { + todo!() + } + + /// Set new state of relay + fn set_state(&mut self, time: i64, on: bool) -> anyhow::Result<()> { + todo!() + } + + /// Get the state of relay at a given time + fn get_state(&self, time: i64) -> anyhow::Result { + todo!() + } + + /// Persist device relay state history + pub fn save(&self) -> anyhow::Result<()> { + todo!() + } +}