Skip to content

Commit

Permalink
WIP re-sending info after reconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
qwandor committed Dec 31, 2020
1 parent 8b68439 commit e14ea75
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions homie-device/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
}
_ => {}
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e14ea75

Please sign in to comment.