diff --git a/hms2mqtt/src/home_assistant.rs b/hms2mqtt/src/home_assistant.rs index de11b07a..74e5d16b 100644 --- a/hms2mqtt/src/home_assistant.rs +++ b/hms2mqtt/src/home_assistant.rs @@ -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 { diff --git a/hms2mqtt/src/mqtt_config.rs b/hms2mqtt/src/mqtt_config.rs index 5eccc097..93ca9e8c 100644 --- a/hms2mqtt/src/mqtt_config.rs +++ b/hms2mqtt/src/mqtt_config.rs @@ -6,5 +6,6 @@ pub struct MqttConfig { pub port: Option, pub username: Option, pub password: Option, + pub client_id: Option, pub tls: Option, } diff --git a/src/bin/hms-mqtt-publish/rumqttc_wrapper.rs b/src/bin/hms-mqtt-publish/rumqttc_wrapper.rs index b9e55d64..7289ae68 100644 --- a/src/bin/hms-mqtt-publish/rumqttc_wrapper.rs +++ b/src/bin/hms-mqtt-publish/rumqttc_wrapper.rs @@ -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 { diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 49983938..448ac83f 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -51,6 +51,7 @@ fn publish_one_message() { username: None, password: None, tls: None, + client_id: Some("myclient".to_string()), }, "-test", );