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

Use suffix instead of prefix of serial number for topic / Multiple Inverter Support #94

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
7 changes: 6 additions & 1 deletion hms2mqtt/src/home_assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ impl HMSStateResponse {
}

fn short_dtu_sn(&self) -> String {
self.dtu_sn[..8].to_string()
let suffix = {
let split_pos = self.dtu_sn.char_indices().nth_back(8).unwrap().0;
&self.dtu_sn[split_pos..]
};

suffix.to_string()
}

fn get_total_efficiency(&self) -> f32 {
Expand Down
1 change: 1 addition & 0 deletions hms2mqtt/src/mqtt_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ pub struct MqttConfig {
pub port: Option<u16>,
pub username: Option<String>,
pub password: Option<String>,
pub client_id: Option<String>,
pub tls: Option<bool>,
}
6 changes: 5 additions & 1 deletion src/bin/hms-mqtt-publish/rumqttc_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ impl mqtt_wrapper::MqttWrapper for RumqttcWrapper {
}

fn new(config: &MqttConfig, suffix: &str) -> Self {

let use_tls = config.tls.is_some_and(|tls| tls);

let mut client_id = config.client_id.as_deref().unwrap_or("hms-mqtt-publish").to_string();
client_id.push_str(suffix);

let mut mqttoptions = MqttOptions::new(
"hms800wt2-mqtt-publisher".to_string() + suffix,
&client_id,
&config.host,
config.port.unwrap_or_else(|| {
if use_tls {
Expand Down
Loading