Merge branch 'release/0.4.1'
This commit is contained in:
commit
f2c2351c2d
3 changed files with 22 additions and 4 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -421,7 +421,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ha-now-playing"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-tungstenite",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "ha-now-playing"
|
||||
description = "Retrieves the state of a media_player entity from Home Assistant"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
authors = ["Erwin Boskma <erwin@datarift.nl>"]
|
||||
edition = "2021"
|
||||
|
||||
|
|
|
@ -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