feat(config)!: Config now returns the mqtt config instead of the client
Instead the client is now created on the rust side based on the config. Devices that require the mqtt client will now instead need to be constructor using a function. This function receives the mqtt client.
This commit is contained in:
@@ -1,34 +1,6 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use lua_typed::Typed;
|
||||
use rumqttc::{MqttOptions, Transport};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Typed)]
|
||||
pub struct MqttConfig {
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
pub client_name: String,
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
#[serde(default)]
|
||||
pub tls: bool,
|
||||
}
|
||||
|
||||
impl From<MqttConfig> for MqttOptions {
|
||||
fn from(value: MqttConfig) -> Self {
|
||||
let mut mqtt_options = MqttOptions::new(value.client_name, value.host, value.port);
|
||||
mqtt_options.set_credentials(value.username, value.password);
|
||||
mqtt_options.set_keep_alive(Duration::from_secs(5));
|
||||
|
||||
if value.tls {
|
||||
mqtt_options.set_transport(Transport::tls_with_default_config());
|
||||
}
|
||||
|
||||
mqtt_options
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Typed)]
|
||||
pub struct InfoConfig {
|
||||
pub name: String,
|
||||
|
||||
Reference in New Issue
Block a user