Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lib.rs to bundle re-usable parts of the implementation #41

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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