temp: config v2
This commit is contained in:
parent
da53750216
commit
1c9d36c6ad
2 changed files with 65 additions and 7 deletions
|
@ -124,7 +124,9 @@ pub enum ConfigStorage {
|
|||
#[serde(rename = "1")]
|
||||
V1(outdated::ConfigV1),
|
||||
#[serde(rename = "2")]
|
||||
V2(Config),
|
||||
V2(outdated::ConfigV2),
|
||||
#[serde(rename = "3")]
|
||||
V3(Config),
|
||||
}
|
||||
|
||||
mod outdated;
|
||||
|
@ -137,13 +139,14 @@ impl Default for ConfigStorage {
|
|||
|
||||
impl ConfigStorage {
|
||||
pub const fn from_latest(config: Config) -> Self {
|
||||
Self::V2(config)
|
||||
Self::V3(config)
|
||||
}
|
||||
|
||||
pub fn into_latest(self) -> Config {
|
||||
match self {
|
||||
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)]
|
||||
pub struct ChargeControllerConfig {
|
||||
pub name: String,
|
||||
|
|
|
@ -1,4 +1,46 @@
|
|||
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 {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -28,11 +70,11 @@ mod v1 {
|
|||
Pl { timeout_milliseconds: u64 },
|
||||
}
|
||||
|
||||
impl From<ChargeControllerConfigV1> for crate::config::ChargeControllerConfig {
|
||||
impl From<ChargeControllerConfigV1> for super::v2::ChargeControllerConfigV2 {
|
||||
fn from(value: ChargeControllerConfigV1) -> Self {
|
||||
Self {
|
||||
name: value.name,
|
||||
transport: crate::config::Transport::Serial {
|
||||
transport: super::v2::TransportV2::Serial {
|
||||
port: value.serial_port,
|
||||
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 {
|
||||
match value {
|
||||
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 {
|
||||
Self {
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue