Skip to content

Commit

Permalink
Add lib.rs to bundle re-usable parts of the implementation (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisOSRM authored Nov 26, 2023
1 parent ff19953 commit ba29f2f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/inverter.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
21 changes: 6 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
// 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;
use std::thread;
use std::time::Duration;

use log::{error, info};
use protos::hoymiles::RealData;

#[derive(Debug, Deserialize)]
struct Config {
Expand All @@ -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");
Expand Down

0 comments on commit ba29f2f

Please sign in to comment.