Skip to content

Commit

Permalink
Rename mqtt*.rs to home_assistant*.rs (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisOSRM authored Nov 26, 2023
1 parent a6ce131 commit ff19953
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/mqtt.rs → src/home_assistant.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use std::{thread, time::Duration};

use crate::mqtt_schemas::DeviceConfig;
use crate::home_assistant_config::DeviceConfig;
use crate::{mqtt_config::MqttConfig, protos::hoymiles::RealData::HMSStateResponse};

use crate::home_assistant_config::SensorConfig;
use crate::metric_collector::MetricCollector;
use crate::mqtt_schemas::SensorConfig;
use log::{debug, error};
use rumqttc::{Client, MqttOptions, QoS};
use serde_json::json;

pub struct Mqtt {
pub struct HomeAssistant {
client: Client,
}

impl Mqtt {
impl HomeAssistant {
pub fn new(config: &MqttConfig) -> Self {
let this_host = hostname::get().unwrap().into_string().unwrap();
let mut mqttoptions = MqttOptions::new(
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Mqtt {
}
}

impl MetricCollector for Mqtt {
impl MetricCollector for HomeAssistant {
fn publish(&mut self, hms_state: &HMSStateResponse) {
let config_topic = format!("homeassistant/sensor/hms_{}", hms_state.short_dtu_sn());
let state_topic = format!("solar/hms_{}/state", hms_state.short_dtu_sn());
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// 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;
mod mqtt_config;
mod mqtt_schemas;
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::mqtt::Mqtt;
use crate::simple_mqtt::SimpleMqtt;

use mqtt_config::MqttConfig;
Expand Down Expand Up @@ -52,7 +52,7 @@ fn main() {
let mut output_channels: Vec<Box<dyn MetricCollector>> = Vec::new();
if let Some(config) = config.home_assistant {
info!("Publishing to Home Assistent");
output_channels.push(Box::new(Mqtt::new(&config)));
output_channels.push(Box::new(HomeAssistant::new(&config)));
}

if let Some(config) = config.simple_mqtt {
Expand Down

0 comments on commit ff19953

Please sign in to comment.