Merge branch 'release/0.4.1'

This commit is contained in:
Erwin Boskma 2022-04-12 23:12:31 +02:00
commit f2c2351c2d
Signed by: erwin
GPG key ID: 270B20D17394F7E5
3 changed files with 22 additions and 4 deletions

2
Cargo.lock generated
View file

@ -421,7 +421,7 @@ dependencies = [
[[package]] [[package]]
name = "ha-now-playing" name = "ha-now-playing"
version = "0.4.0" version = "0.4.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-tungstenite", "async-tungstenite",

View file

@ -1,7 +1,7 @@
[package] [package]
name = "ha-now-playing" name = "ha-now-playing"
description = "Retrieves the state of a media_player entity from Home Assistant" 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>"] authors = ["Erwin Boskma <erwin@datarift.nl>"]
edition = "2021" edition = "2021"

View file

@ -1,4 +1,4 @@
use std::fmt::Display; use std::{fmt::Display, io::Write};
use async_tungstenite::{tokio::connect_async, tungstenite}; use async_tungstenite::{tokio::connect_async, tungstenite};
use color_eyre::{eyre::bail, Result}; use color_eyre::{eyre::bail, Result};
@ -324,12 +324,30 @@ impl HomeAssistant {
let output = self let output = self
.format_state(event.data.new_state.state, event.data.new_state.attributes); .format_state(event.data.new_state.state, event.data.new_state.attributes);
println!("{output}"); println!("{output}");
std::io::stdout().flush()?;
} }
vec![] vec![]
} }
MessageType::Result => { 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![] vec![]
} }