Flush stdout after print, get initial state
This commit is contained in:
parent
4f8155c1a6
commit
c4515f9b6a
1 changed files with 20 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::fmt::Display;
|
||||
use std::{fmt::Display, io::Write};
|
||||
|
||||
use async_tungstenite::{tokio::connect_async, tungstenite};
|
||||
use color_eyre::{eyre::bail, Result};
|
||||
|
@ -324,12 +324,30 @@ impl HomeAssistant {
|
|||
let output = self
|
||||
.format_state(event.data.new_state.state, event.data.new_state.attributes);
|
||||
println!("{output}");
|
||||
std::io::stdout().flush()?;
|
||||
}
|
||||
|
||||
vec![]
|
||||
}
|
||||
MessageType::Result => {
|
||||
trace!("{}", message.to_json());
|
||||
trace!("Result: {:?}", message);
|
||||
|
||||
if let Some(result) = message.result {
|
||||
if let Some(items) = result.as_array() {
|
||||
if let Some(entity) = items.iter().find(|&item| {
|
||||
item.as_object()
|
||||
.unwrap()
|
||||
.get::<String>(&String::from("entity_id"))
|
||||
.unwrap()
|
||||
.eq(&self.entity)
|
||||
}) {
|
||||
let state: EntityState =
|
||||
serde_json::from_value(entity.clone()).unwrap();
|
||||
println!("{}", self.format_state(state.state, state.attributes));
|
||||
std::io::stdout().flush()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vec![]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue