temp: config v2

This commit is contained in:
Alex Janka 2025-01-11 18:35:40 +11:00
parent da53750216
commit 1c9d36c6ad
2 changed files with 65 additions and 7 deletions

View file

@ -124,7 +124,9 @@ pub enum ConfigStorage {
#[serde(rename = "1")] #[serde(rename = "1")]
V1(outdated::ConfigV1), V1(outdated::ConfigV1),
#[serde(rename = "2")] #[serde(rename = "2")]
V2(Config), V2(outdated::ConfigV2),
#[serde(rename = "3")]
V3(Config),
} }
mod outdated; mod outdated;
@ -137,13 +139,14 @@ impl Default for ConfigStorage {
impl ConfigStorage { impl ConfigStorage {
pub const fn from_latest(config: Config) -> Self { pub const fn from_latest(config: Config) -> Self {
Self::V2(config) Self::V3(config)
} }
pub fn into_latest(self) -> Config { pub fn into_latest(self) -> Config {
match self { match self {
ConfigStorage::V1(v1) => v1.into(), ConfigStorage::V1(v1) => v1.into(),
ConfigStorage::V2(config) => config, ConfigStorage::V2(v2) => v2.into(),
ConfigStorage::V3(config) => config,
} }
} }
@ -184,6 +187,13 @@ impl Config {
} }
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct ConnectionConfig {
transport: Transport,
variant: ChargeControllerVariant,
charge_controllers: Vec<ChargeControllerConfig>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct ChargeControllerConfig { pub struct ChargeControllerConfig {
pub name: String, pub name: String,

View file

@ -1,4 +1,46 @@
pub use v1::ConfigV1; pub use v1::ConfigV1;
pub use v2::ConfigV2;
mod v2 {
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
#[serde(default)]
pub struct ConfigV2 {
pub primary_charge_controller: String,
pub enable_secondary_control: bool,
pub charge_controllers: Vec<ChargeControllerConfigV2>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct ChargeControllerConfigV2 {
pub name: String,
pub watch_interval_seconds: u64,
pub variant: ChargeControllerVariantV2,
#[serde(default)]
pub follow_primary: bool,
pub transport: TransportV2,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub enum ChargeControllerVariantV2 {
Tristar,
Pl { timeout_milliseconds: u64 },
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum TransportV2 {
Serial { port: String, baud_rate: u32 },
Tcp { ip: std::net::IpAddr, port: u16 },
}
impl From<ConfigV2> for crate::config::Config {
fn from(value: ConfigV2) -> Self {
todo!()
}
}
}
mod v1 { mod v1 {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -28,11 +70,11 @@ mod v1 {
Pl { timeout_milliseconds: u64 }, Pl { timeout_milliseconds: u64 },
} }
impl From<ChargeControllerConfigV1> for crate::config::ChargeControllerConfig { impl From<ChargeControllerConfigV1> for super::v2::ChargeControllerConfigV2 {
fn from(value: ChargeControllerConfigV1) -> Self { fn from(value: ChargeControllerConfigV1) -> Self {
Self { Self {
name: value.name, name: value.name,
transport: crate::config::Transport::Serial { transport: super::v2::TransportV2::Serial {
port: value.serial_port, port: value.serial_port,
baud_rate: value.baud_rate, baud_rate: value.baud_rate,
}, },
@ -43,7 +85,7 @@ mod v1 {
} }
} }
impl From<ChargeControllerVariantV1> for crate::config::ChargeControllerVariant { impl From<ChargeControllerVariantV1> for super::v2::ChargeControllerVariantV2 {
fn from(value: ChargeControllerVariantV1) -> Self { fn from(value: ChargeControllerVariantV1) -> Self {
match value { match value {
ChargeControllerVariantV1::Tristar => Self::Tristar, ChargeControllerVariantV1::Tristar => Self::Tristar,
@ -56,7 +98,7 @@ mod v1 {
} }
} }
impl From<ConfigV1> for crate::config::Config { impl From<ConfigV1> for super::v2::ConfigV2 {
fn from(value: ConfigV1) -> Self { fn from(value: ConfigV1) -> Self {
Self { Self {
primary_charge_controller: value.primary_charge_controller, primary_charge_controller: value.primary_charge_controller,
@ -69,4 +111,10 @@ mod v1 {
} }
} }
} }
impl From<ConfigV1> for crate::config::Config {
fn from(value: ConfigV1) -> Self {
super::v2::ConfigV2::from(value).into()
}
}
} }