Replaced impl_cast with a new and improved trait

With this trait the impl_cast macros are no longer needed, simplifying
everything.
This commit also improved how the actual casting itself is handled.
This commit is contained in:
Dreaded_X 2024-05-05 00:33:21 +02:00
parent 3689a52afd
commit f50bc4bd0c
Signed by: Dreaded_X
GPG Key ID: FA5F485356B0D2D4

View File

@ -142,17 +142,14 @@ impl DeviceManager {
debug!(id, "Adding device");
{
// If the device listens to mqtt, subscribe to the topics
let device: Option<&dyn OnMqtt> = device.as_ref().cast();
if let Some(device) = device {
for topic in device.topics() {
trace!(id, topic, "Subscribing to topic");
if let Err(err) = self.client.subscribe(topic, QoS::AtLeastOnce).await {
// NOTE: Pretty sure that this can only happen if the mqtt client if no longer
// running
error!(id, topic, "Failed to subscribe to topic: {err}");
}
// If the device listens to mqtt, subscribe to the topics
if let Some(device) = device.as_ref().cast() as Option<&dyn OnMqtt> {
for topic in device.topics() {
trace!(id, topic, "Subscribing to topic");
if let Err(err) = self.client.subscribe(topic, QoS::AtLeastOnce).await {
// NOTE: Pretty sure that this can only happen if the mqtt client if no longer
// running
error!(id, topic, "Failed to subscribe to topic: {err}");
}
}
}