Merge branch 'release/0.4.3'
This commit is contained in:
commit
4faf850a48
5 changed files with 67 additions and 76 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -421,7 +421,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ha-now-playing"
|
||||
version = "0.4.2"
|
||||
version = "0.4.3"
|
||||
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.2"
|
||||
version = "0.4.3"
|
||||
authors = ["Erwin Boskma <erwin@datarift.nl>"]
|
||||
edition = "2021"
|
||||
|
||||
|
|
26
flake.lock
26
flake.lock
|
@ -7,11 +7,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1649096192,
|
||||
"narHash": "sha256-7O8e+eZEYeU+ET98u/zW5epuoN/xYx9G+CIh4DjZVzY=",
|
||||
"lastModified": 1651574473,
|
||||
"narHash": "sha256-wQhFORvRjo8LB2hTmETmv6cbyKGDPbfWqvZ/0chnDE4=",
|
||||
"owner": "nmattia",
|
||||
"repo": "naersk",
|
||||
"rev": "d626f73332a8f587b613b0afe7293dd0777be07d",
|
||||
"rev": "f21309b38e1da0d61b881b6b6d41b81c1aed4e1d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -23,16 +23,16 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1648219316,
|
||||
"narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=",
|
||||
"lastModified": 1652172129,
|
||||
"narHash": "sha256-8e2JMrswaKe02P8rYfvIMoc59pNuw6h/GYu8DBE1c+0=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634",
|
||||
"rev": "f419dc5763c2b3c5580e396dea065b6d8b58ee27",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
|
@ -55,11 +55,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1649298784,
|
||||
"narHash": "sha256-rUwQKjBOZiRpzgkG3h9OM5pUyxRYIV45ohgqZJtSZtE=",
|
||||
"lastModified": 1652236937,
|
||||
"narHash": "sha256-anMSkIvaxB3jV74nTvPcE8fH7bZ5LPuc2wXGvt50Oe0=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "c6fe2a14f10cb85659b8848bac87e4ff29a00f9a",
|
||||
"rev": "18c816d2d10317f4a8816925a12cb4bbdd0821de",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -70,11 +70,11 @@
|
|||
},
|
||||
"utils": {
|
||||
"locked": {
|
||||
"lastModified": 1648297722,
|
||||
"narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=",
|
||||
"lastModified": 1649676176,
|
||||
"narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade",
|
||||
"rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
utils.url = "github:numtide/flake-utils";
|
||||
naersk = {
|
||||
url = "github:nmattia/naersk/master";
|
||||
|
|
|
@ -195,63 +195,50 @@ impl Display for MessageType {
|
|||
|
||||
impl Message {
|
||||
fn auth() -> Self {
|
||||
let mut msg = Self::default();
|
||||
msg.message_type = MessageType::Auth;
|
||||
msg
|
||||
Self {
|
||||
message_type: MessageType::Auth,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn subscribe_events() -> Self {
|
||||
let mut msg = Self::default();
|
||||
msg.message_type = MessageType::SubscribeEvents;
|
||||
msg
|
||||
Self {
|
||||
message_type: MessageType::SubscribeEvents,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn get_states() -> Self {
|
||||
let mut msg = Self::default();
|
||||
msg.message_type = MessageType::GetStates;
|
||||
msg
|
||||
Self {
|
||||
message_type: MessageType::GetStates,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn ping() -> Self {
|
||||
let mut msg = Self::default();
|
||||
msg.message_type = MessageType::Ping;
|
||||
msg
|
||||
Self {
|
||||
message_type: MessageType::Ping,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn pong() -> Self {
|
||||
let mut msg = Self::default();
|
||||
msg.message_type = MessageType::Pong;
|
||||
msg
|
||||
Self {
|
||||
message_type: MessageType::Pong,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn to_json(self) -> String {
|
||||
fn to_json(&self) -> String {
|
||||
serde_json::to_string(&self).unwrap()
|
||||
}
|
||||
|
||||
fn to_message(self) -> tungstenite::Message {
|
||||
fn to_message(&self) -> tungstenite::Message {
|
||||
tungstenite::Message::from(self.to_json())
|
||||
}
|
||||
}
|
||||
|
||||
impl HomeAssistant {
|
||||
// pub(crate) fn new(
|
||||
// host: String,
|
||||
// entity: String,
|
||||
// insecure: bool,
|
||||
// token: String,
|
||||
// format: OutputFormat,
|
||||
// ) -> Self {
|
||||
// Self {
|
||||
// token,
|
||||
// entity,
|
||||
// insecure,
|
||||
// host,
|
||||
// format,
|
||||
// id: 1,
|
||||
// auth_complete: false,
|
||||
// }
|
||||
// }
|
||||
|
||||
pub(crate) fn builder() -> HomeAssistantBuilder {
|
||||
HomeAssistantBuilder::new()
|
||||
}
|
||||
|
@ -278,32 +265,36 @@ impl HomeAssistant {
|
|||
loop {
|
||||
tokio::select! {
|
||||
msg = ws_stream.next() => match msg {
|
||||
Some(msg) => {
|
||||
let msg = msg?;
|
||||
|
||||
match self.handle_message(msg).await {
|
||||
Ok(response_messages) => {
|
||||
for response in response_messages {
|
||||
ws_stream.send(response).await?
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
if let Some(err) = e.downcast_ref::<HomeAssistantError>() {
|
||||
match err {
|
||||
HomeAssistantError::EmptyMessage => {
|
||||
debug!("Received empty message, ignoring...")
|
||||
}
|
||||
HomeAssistantError::UnhandledMessage(message_type) => {
|
||||
debug!(
|
||||
"Received '{message_type}', we're currently not handling that."
|
||||
)
|
||||
}
|
||||
HomeAssistantError::JsonError(e) => error!("{e}"),
|
||||
Some(msg) => match msg {
|
||||
Ok(msg) => {
|
||||
match self.handle_message(msg).await {
|
||||
Ok(response_messages) => {
|
||||
for response in response_messages {
|
||||
ws_stream.send(response).await?
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
if let Some(err) = e.downcast_ref::<HomeAssistantError>() {
|
||||
match err {
|
||||
HomeAssistantError::EmptyMessage => {
|
||||
debug!("Received empty message, ignoring...")
|
||||
}
|
||||
HomeAssistantError::UnhandledMessage(message_type) => {
|
||||
debug!(
|
||||
"Received '{message_type}', we're currently not handling that."
|
||||
)
|
||||
}
|
||||
HomeAssistantError::JsonError(e) => error!("{e}"),
|
||||
}
|
||||
} else {
|
||||
error!("{e}");
|
||||
}
|
||||
} else {
|
||||
error!("{e}");
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
error!("Error in receiving message: {e}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
None => break,
|
||||
|
@ -327,7 +318,7 @@ impl HomeAssistant {
|
|||
&mut self,
|
||||
msg: tungstenite::Message,
|
||||
) -> Result<Vec<tungstenite::Message>> {
|
||||
if msg.len() == 0 {
|
||||
if msg.is_empty() {
|
||||
bail!(HomeAssistantError::EmptyMessage);
|
||||
}
|
||||
|
||||
|
@ -417,7 +408,7 @@ impl HomeAssistant {
|
|||
let is_muted = attributes["is_volume_muted"].as_bool().unwrap_or(false);
|
||||
|
||||
let volume = if is_muted {
|
||||
String::from("[ \u{fc5d} ]")
|
||||
String::from("[ \u{f466} ] ")
|
||||
} else if volume_raw >= 0. {
|
||||
format!("[{:3.0}%] ", volume_raw * 100.)
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue