From 8ca9fda5c5df0791f1242596f530a63404cd671c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 26 Nov 2023 19:04:01 +0100 Subject: [PATCH] Add lib.rs to bundle re-usable parts of the implementation --- src/inverter.rs | 3 +-- src/lib.rs | 7 +++++++ src/logging.rs | 2 +- src/main.rs | 21 ++++++--------------- 4 files changed, 15 insertions(+), 18 deletions(-) create mode 100644 src/lib.rs diff --git a/src/inverter.rs b/src/inverter.rs index d7ecc286..da16d65e 100644 --- a/src/inverter.rs +++ b/src/inverter.rs @@ -1,5 +1,4 @@ -use crate::protos::hoymiles::RealData::HMSStateResponse; -use crate::RealData::RealDataResDTO; +use crate::protos::hoymiles::RealData::{HMSStateResponse, RealDataResDTO}; use crc16::*; use log::{debug, info}; use protobuf::Message; diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000..f3398352 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,7 @@ +pub mod home_assistant; +pub mod home_assistant_config; +pub mod inverter; +pub mod metric_collector; +pub mod mqtt_config; +pub mod protos; +pub mod simple_mqtt; diff --git a/src/logging.rs b/src/logging.rs index ca824ddc..455ecf65 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -4,7 +4,7 @@ use chrono::Local; use env_logger::Builder; use log::LevelFilter; -pub(crate) fn init_logger() { +pub fn init_logger() { Builder::new() .format(|buf, record| { writeln!( diff --git a/src/main.rs b/src/main.rs index ee193f6e..7f950ca4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,21 +1,13 @@ // TODO: support CA33 command to take over metrics consumption // TODO: support publishing to S-Miles cloud, too -mod home_assistant; -mod home_assistant_config; -mod inverter; mod logging; -mod metric_collector; -mod mqtt_config; -mod protos; -mod simple_mqtt; - -use crate::home_assistant::HomeAssistant; -use crate::inverter::Inverter; -use crate::logging::init_logger; -use crate::metric_collector::MetricCollector; -use crate::simple_mqtt::SimpleMqtt; +use hms_mqtt_publish::home_assistant::HomeAssistant; +use hms_mqtt_publish::inverter::Inverter; +use hms_mqtt_publish::metric_collector::MetricCollector; +use hms_mqtt_publish::mqtt_config; +use hms_mqtt_publish::simple_mqtt::SimpleMqtt; use mqtt_config::MqttConfig; use serde_derive::Deserialize; use std::fs; @@ -23,7 +15,6 @@ use std::thread; use std::time::Duration; use log::{error, info}; -use protos::hoymiles::RealData; #[derive(Debug, Deserialize)] struct Config { @@ -35,7 +26,7 @@ struct Config { static REQUEST_DELAY: u64 = 30_500; fn main() { - init_logger(); + logging::init_logger(); if std::env::args().len() > 1 { error!("Arguments passed. Tool is configured by config.toml in its path");