Attempting to reduce .clone() usage
This commit is contained in:
1 file changed
+14
-13
+14
-13
@@ -67,7 +67,7 @@ pub(crate) use cmdline::Opt;
|
|||||||
use event_cam::EventCam;
|
use event_cam::EventCam;
|
||||||
pub(crate) use event_cam::{Direction, Messages};
|
pub(crate) use event_cam::{Direction, Messages};
|
||||||
use heck::ToTitleCase;
|
use heck::ToTitleCase;
|
||||||
use json::{array, object};
|
use json::{array, object, JsonValue};
|
||||||
use log::*;
|
use log::*;
|
||||||
use mqttc::{Mqtt, MqttReplyRef};
|
use mqttc::{Mqtt, MqttReplyRef};
|
||||||
|
|
||||||
@@ -234,15 +234,15 @@ async fn enable_discovery(
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
debug!("Enabling MQTT discovery for {}", cam_config.name);
|
debug!("Enabling MQTT discovery for {}", cam_config.name);
|
||||||
|
|
||||||
let mut connections = array![];
|
let mut connections: JsonValue = array![];
|
||||||
if let Some(addr) = &cam_config.camera_addr {
|
if let Some(addr) = &cam_config.camera_addr {
|
||||||
connections
|
connections
|
||||||
.push(array!["camera_addr", addr.clone()])
|
.push(array!["camera_addr", addr.as_str()])
|
||||||
.expect("Failed to add camera_addr to connections");
|
.expect("Failed to add camera_addr to connections");
|
||||||
}
|
}
|
||||||
if let Some(uid) = &cam_config.camera_uid {
|
if let Some(uid) = &cam_config.camera_uid {
|
||||||
connections
|
connections
|
||||||
.push(array!["camera_uid", uid.clone()])
|
.push(array!["camera_uid", uid.as_str()])
|
||||||
.expect("Failed to add camera_uid to connections");
|
.expect("Failed to add camera_uid to connections");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,19 +255,19 @@ async fn enable_discovery(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let friendly_name = cam_config.name.replace("_", " ").to_title_case();
|
let friendly_name = cam_config.name.replace("_", " ").to_title_case();
|
||||||
let device = object! {
|
let device = Arc::new(object! {
|
||||||
connections: connections,
|
connections: connections,
|
||||||
name: friendly_name.clone(),
|
name: friendly_name.as_str(),
|
||||||
identifiers: array![format!("neolink_{}", cam_config.name)],
|
identifiers: array![format!("neolink_{}", cam_config.name)],
|
||||||
manufacturer: "Reolink",
|
manufacturer: "Reolink",
|
||||||
model: "Neolink",
|
model: "Neolink",
|
||||||
sw_version: env!("CARGO_PKG_VERSION"),
|
sw_version: env!("CARGO_PKG_VERSION"),
|
||||||
};
|
});
|
||||||
|
|
||||||
let availability = object! {
|
let availability = Arc::new(object! {
|
||||||
topic: format!("neolink/{}/status", cam_config.name),
|
topic: format!("neolink/{}/status", cam_config.name),
|
||||||
payload_available: "connected",
|
payload_available: "connected",
|
||||||
};
|
});
|
||||||
|
|
||||||
for feature in &discovery_config.features {
|
for feature in &discovery_config.features {
|
||||||
match feature.as_str() {
|
match feature.as_str() {
|
||||||
@@ -276,11 +276,11 @@ async fn enable_discovery(
|
|||||||
|
|
||||||
let config_data = object! {
|
let config_data = object! {
|
||||||
// Common across all potential features
|
// Common across all potential features
|
||||||
device: device.clone(),
|
device: Arc::try_unwrap(device.clone()).unwrap(),
|
||||||
availability: availability.clone(),
|
availability: Arc::try_unwrap(availability.clone()).unwrap(),
|
||||||
|
|
||||||
// Identifiers
|
// Identifiers
|
||||||
name: format!("{} Floodlight", friendly_name.clone()),
|
name: format!("{} Floodlight", friendly_name.as_str()),
|
||||||
unique_id: format!("neolink_{}_floodlight", cam_config.name),
|
unique_id: format!("neolink_{}_floodlight", cam_config.name),
|
||||||
// Match native home assistant integration: https://github.com/home-assistant/core/blob/dev/homeassistant/components/reolink/light.py#L49
|
// Match native home assistant integration: https://github.com/home-assistant/core/blob/dev/homeassistant/components/reolink/light.py#L49
|
||||||
icon: "mdi:spotlight-beam",
|
icon: "mdi:spotlight-beam",
|
||||||
@@ -323,7 +323,8 @@ async fn enable_discovery(
|
|||||||
|
|
||||||
info!(
|
info!(
|
||||||
"Enabled MQTT discovery for {} with friendly name {}",
|
"Enabled MQTT discovery for {} with friendly name {}",
|
||||||
cam_config.name, friendly_name
|
cam_config.name,
|
||||||
|
friendly_name.as_str()
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in new issue
Block a user