Use format macro instead of directly concating
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -23,11 +23,13 @@ pub struct AudioSetup {
|
||||
impl AudioSetup {
|
||||
pub async fn build(identifier: &str, mqtt: MqttDeviceConfig, mixer: DeviceBox, speakers: DeviceBox, client: AsyncClient) -> Result<Self, DeviceError> {
|
||||
// We expect the children devices to implement the OnOff trait
|
||||
let mixer_id = mixer.get_id().to_owned();
|
||||
let mixer = AsOnOff::consume(mixer)
|
||||
.ok_or_else(|| DeviceError::OnOffExpected(identifier.to_owned() + ".mixer"))?;
|
||||
.ok_or_else(|| DeviceError::OnOffExpected(mixer_id))?;
|
||||
|
||||
let speakers_id = speakers.get_id().to_owned();
|
||||
let speakers = AsOnOff::consume(speakers)
|
||||
.ok_or_else(|| DeviceError::OnOffExpected(identifier.to_owned() + ".speakers"))?;
|
||||
.ok_or_else(|| DeviceError::OnOffExpected(speakers_id))?;
|
||||
|
||||
client.subscribe(mqtt.topic.clone(), rumqttc::QoS::AtLeastOnce).await?;
|
||||
|
||||
|
||||
@@ -37,10 +37,11 @@ impl IkeaOutlet {
|
||||
async fn set_on(client: AsyncClient, topic: &str, on: bool) {
|
||||
let message = OnOffMessage::new(on);
|
||||
|
||||
let topic = format!("{}/set", topic);
|
||||
// @TODO Handle potential errors here
|
||||
client.publish(topic.to_owned() + "/set", rumqttc::QoS::AtLeastOnce, false, serde_json::to_string(&message).unwrap())
|
||||
client.publish(topic.clone(), rumqttc::QoS::AtLeastOnce, false, serde_json::to_string(&message).unwrap())
|
||||
.await
|
||||
.map_err(|err| warn!("Failed to update state on {topic}/set: {err}"))
|
||||
.map_err(|err| warn!("Failed to update state on {topic}: {err}"))
|
||||
.ok();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user