From e14ea75dcfc6b1d5a1ae1a2c72156eff4203deb3 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Sun, 20 Dec 2020 12:35:26 +0000 Subject: [PATCH] WIP re-sending info after reconnecting --- homie-device/src/lib.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/homie-device/src/lib.rs b/homie-device/src/lib.rs index 84e3c7e9..e2eefd58 100644 --- a/homie-device/src/lib.rs +++ b/homie-device/src/lib.rs @@ -398,8 +398,8 @@ impl HomieDevice { } } Ok(Incoming::ConnAck(_)) => { - // TODO: Republish nodes and everything, unless this is the initial connection. - state.lock().await.send_state().await?; + // TODO: Only if this is not the initial connection. + state.lock().await.republish_all().await?; } _ => {} } @@ -507,6 +507,27 @@ impl DeviceState { self.publisher.publish_retained("$state", self.state).await } + async fn republish_all(&self) -> Result<(), ClientError> { + for node in &self.nodes { + self.publisher.publish_node(node).await?; + } + self.publish_nodes().await?; + // TODO: Stats and firmware extensions + self.publisher + .publish_retained("$homie", HOMIE_VERSION) + .await?; + self.publisher + .publish_retained("$extensions", self.extension_ids.as_str()) + .await?; + self.publisher + .publish_retained("$implementation", HOMIE_IMPLEMENTATION) + .await?; + self.publisher + .publish_retained("$name", self.device_name.as_str()) + .await?; + self.send_state().await + } + /// Add a node to the Homie device and publish it. async fn add_node(&mut self, node: Node) -> Result<(), ClientError> { // First check that there isn't already a node with the same ID.