Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Wannes committed Sep 23, 2023
1 parent 6dfc576 commit acba64d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 14 additions & 2 deletions ebusd-thermostat/src/homeassistant.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::bail;
use futures_util::{SinkExt, StreamExt};
use log::{error, trace};
use log::{debug, error, trace};
use reqwest::{Client, Url};
use serde::{Deserialize, Serialize};
use serde_json::Value;
Expand Down Expand Up @@ -169,7 +169,19 @@ impl Api {

tokio::spawn(async move {
read.for_each(|msg| async {
let msg = msg.unwrap().into_text().unwrap();
let msg = match msg {
Ok(v) => match v.into_text() {
Ok(v) => v,
Err(e) => {
debug!("Failed to convert WS message into text: {}", e);
return;
}
},
Err(e) => {
debug!("Failed to read WS message: {}", e);
return;
}
};
let ha_msg: HaMessage = match serde_json::from_str(&msg) {
Ok(v) => v,
Err(e) => {
Expand Down
3 changes: 2 additions & 1 deletion ebusd-thermostat/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ impl Thermostat {
None => {}
Some(e) => {
debug!("Original error: {}", e.to_string());
if e.to_string().to_lowercase().contains("broken pipe") {
let msg = e.to_string().to_lowercase();
if msg.contains("broken pipe") || msg.contains("connection") {
debug!("Reconnecting...");
self.ebusd.reconnect().await?;
self.ebusd.define_message( "wi,BAI,SetModeOverride,Betriebsart,,08,B510,00,hcmode,,UCH,,,,flowtempdesired,,D1C,,,,hwctempdesired,,D1C,,,,hwcflowtempdesired,,UCH,,,,setmode1,,UCH,,,,disablehc,,BI0,,,,disablehwctapping,,BI1,,,,disablehwcload,,BI2,,,,setmode2,,UCH,,,,remoteControlHcPump,,BI0,,,,releaseBackup,,BI1,,,,releaseCooling,,BI2".to_string()).await?;
Expand Down

0 comments on commit acba64d

Please sign in to comment.