socit/
monitoring.rs

1/* Copyright 2023, 2025 Bruce Merry
2 *
3 * This program is free software: you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation, either version 3 of the License, or (at your option)
6 * any later version.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <https://www.gnu.org/licenses/>.
15 */
16
17use async_trait::async_trait;
18use chrono::{DateTime, Utc};
19use std::error::Error;
20
21#[derive(Clone, PartialEq, Debug)]
22pub struct SocUpdate {
23    pub time: DateTime<Utc>,
24    pub target_soc_low: f64,
25    pub target_soc_high: f64,
26    pub alarm_soc: f64,
27    pub target_soc_export_low: f64,
28    pub target_soc_export_high: f64,
29    pub current_soc: f64,
30    pub predicted_pv: f64, // In watts
31    pub is_loadshedding: bool,
32    pub next_change: Option<DateTime<Utc>>,
33}
34
35#[derive(Clone, PartialEq, Debug)]
36pub struct CoilUpdate {
37    pub time: DateTime<Utc>,
38    pub active: bool,
39    pub target: Option<f64>,  // In watts
40    pub setting: Option<f64>, // In watts
41}
42
43#[async_trait]
44pub trait Monitor: Send {
45    async fn soc_update(&mut self, update: SocUpdate) -> Result<(), Box<dyn Error>>;
46    async fn coil_update(&mut self, update: CoilUpdate) -> Result<(), Box<dyn Error>>;
47}
48
49pub struct NullMonitor;
50
51#[async_trait]
52impl Monitor for NullMonitor {
53    async fn soc_update(&mut self, _: SocUpdate) -> Result<(), Box<dyn Error>> {
54        Ok(())
55    }
56
57    async fn coil_update(&mut self, _: CoilUpdate) -> Result<(), Box<dyn Error>> {
58        Ok(())
59    }
60}