Merge branch 'release/0.5.0'
This commit is contained in:
commit
44cff9187a
7 changed files with 602 additions and 383 deletions
729
Cargo.lock
generated
729
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
28
Cargo.toml
28
Cargo.toml
|
@ -1,26 +1,26 @@
|
|||
[package]
|
||||
name = "ha-now-playing"
|
||||
description = "Retrieves the state of a media_player entity from Home Assistant"
|
||||
version = "0.4.7"
|
||||
version = "0.5.0"
|
||||
authors = ["Erwin Boskma <erwin@datarift.nl>"]
|
||||
edition = "2021"
|
||||
include = ["src/**/*"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.56"
|
||||
async-tungstenite = { version = "0.18.0", features = ["tokio-rustls-native-certs"] }
|
||||
clap = { version = "4.0.27", features = ["cargo", "unicode", "derive", "env", "wrap_help"] }
|
||||
color-eyre = "0.6.1"
|
||||
futures = "0.3.21"
|
||||
reqwest = { version = "0.11.10", features = ["blocking", "json"] }
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
serde_json = "1.0.79"
|
||||
thiserror = "1.0.30"
|
||||
tokio = { version = "1.17.0", features = ["full"] }
|
||||
tracing = "0.1.32"
|
||||
anyhow = "1.0.71"
|
||||
async-tungstenite = { version = "0.22.2", features = ["tokio-rustls-native-certs"] }
|
||||
clap = { version = "4.3.10", features = ["cargo", "unicode", "derive", "env", "wrap_help"] }
|
||||
color-eyre = "0.6.2"
|
||||
futures = "0.3.28"
|
||||
reqwest = { version = "0.11.18", features = ["blocking", "json"] }
|
||||
serde = { version = "1.0.165", features = ["derive"] }
|
||||
serde_json = "1.0.99"
|
||||
thiserror = "1.0.40"
|
||||
tokio = { version = "1.29.1", features = ["full"] }
|
||||
tracing = "0.1.37"
|
||||
tracing-error = "0.2.0"
|
||||
tracing-subscriber = { version = "0.3.9", features = ["env-filter", "registry"] }
|
||||
tracing-tree = "0.2.0"
|
||||
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "registry"] }
|
||||
tracing-tree = "0.2.3"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "z"
|
||||
|
|
130
flake.lock
130
flake.lock
|
@ -1,13 +1,56 @@
|
|||
{
|
||||
"nodes": {
|
||||
"crane": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-utils": [
|
||||
"flake-utils"
|
||||
],
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"rust-overlay": [
|
||||
"rust-overlay"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1681680516,
|
||||
"narHash": "sha256-EB8Adaeg4zgcYDJn9sR6UMjN/OHdIiMMK19+3LmmXQY=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "54b63c8eae4c50172cb50b612946ff1d2bc1c75c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1668681692,
|
||||
"narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=",
|
||||
"lastModified": 1673956053,
|
||||
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "009399224d5e398d03b22badca40a37ac85412a1",
|
||||
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat_2": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1673956053,
|
||||
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -17,12 +60,15 @@
|
|||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1667395993,
|
||||
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
||||
"lastModified": 1681202837,
|
||||
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
|
||||
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -52,34 +98,13 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"naersk": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1662220400,
|
||||
"narHash": "sha256-9o2OGQqu4xyLZP9K6kNe1pTHnyPz0Wr3raGYnr9AIgY=",
|
||||
"owner": "nmattia",
|
||||
"repo": "naersk",
|
||||
"rev": "6944160c19cb591eb85bbf9b2f2768a935623ed3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nmattia",
|
||||
"ref": "master",
|
||||
"repo": "naersk",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1669542132,
|
||||
"narHash": "sha256-DRlg++NJAwPh8io3ExBJdNW7Djs3plVI5jgYQ+iXAZQ=",
|
||||
"lastModified": 1681737997,
|
||||
"narHash": "sha256-pHhjgsIkRMu80LmVe8QoKIZB6VZGRRxFmIvsC5S89k4=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "a115bb9bd56831941be3776c8a94005867f316a7",
|
||||
"rev": "f00994e78cd39e6fc966f0c4103f908e63284780",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -91,27 +116,27 @@
|
|||
},
|
||||
"nixpkgs-stable": {
|
||||
"locked": {
|
||||
"lastModified": 1668984258,
|
||||
"narHash": "sha256-0gDMJ2T3qf58xgcSbYoXiRGUkPWmKyr5C3vcathWhKs=",
|
||||
"lastModified": 1678872516,
|
||||
"narHash": "sha256-/E1YwtMtFAu2KUQKV/1+KFuReYPANM2Rzehk84VxVoc=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "cf63ade6f74bbc9d2a017290f1b2e33e8fbfa70a",
|
||||
"rev": "9b8e5abb18324c7fe9f07cb100c3cd4a29cda8b8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-22.05",
|
||||
"ref": "nixos-22.11",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1668994630,
|
||||
"narHash": "sha256-1lqx6HLyw6fMNX/hXrrETG1vMvZRGm2XVC9O/Jt0T6c=",
|
||||
"lastModified": 1681303793,
|
||||
"narHash": "sha256-JEdQHsYuCfRL2PICHlOiH/2ue3DwoxUX7DJ6zZxZXFk=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "af50806f7c6ab40df3e6b239099e8f8385f6c78b",
|
||||
"rev": "fe2ecaf706a5907b5e54d979fbde4924d84b65fc",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -123,7 +148,7 @@
|
|||
},
|
||||
"pre-commit-hooks": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-compat": "flake-compat_2",
|
||||
"flake-utils": [
|
||||
"flake-utils"
|
||||
],
|
||||
|
@ -132,11 +157,11 @@
|
|||
"nixpkgs-stable": "nixpkgs-stable"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1669152228,
|
||||
"narHash": "sha256-FEDReoTLWJHXcNso7aaAlAUU7uOqIR6Hc/C/nqlfooE=",
|
||||
"lastModified": 1681831107,
|
||||
"narHash": "sha256-pXl3DPhhul9NztSetUJw2fcN+RI3sGOYgKu29xpgnqw=",
|
||||
"owner": "cachix",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"rev": "078b0dee35e2da01334af682ec347463b70a9986",
|
||||
"rev": "b7ca8f6fff42f6af75c17f9438fed1686b7d855d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -147,8 +172,8 @@
|
|||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"crane": "crane",
|
||||
"flake-utils": "flake-utils",
|
||||
"naersk": "naersk",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"pre-commit-hooks": "pre-commit-hooks",
|
||||
"rust-overlay": "rust-overlay"
|
||||
|
@ -164,11 +189,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1669602829,
|
||||
"narHash": "sha256-I3LBvBiVui4Rf0iQvTqUIgBovaLDzpOzsoNEzCsDowg=",
|
||||
"lastModified": 1681870826,
|
||||
"narHash": "sha256-1YEXIdr5wwG8PWntvcjjoVpsAKOKuKEaFIy3vR0FGpo=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "b9da8e68a08707115be750c0cf7ade33f49d8ec4",
|
||||
"rev": "e2f975856a48ebecba4f95846b8f368f3808d4e7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -176,6 +201,21 @@
|
|||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
|
|
81
flake.nix
81
flake.nix
|
@ -3,10 +3,7 @@
|
|||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
naersk = {
|
||||
url = "github:nmattia/naersk/master";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
|
@ -16,48 +13,46 @@
|
|||
url = "github:cachix/pre-commit-hooks.nix";
|
||||
inputs.flake-utils.follows = "flake-utils";
|
||||
};
|
||||
|
||||
crane = {
|
||||
url = "github:ipetkov/crane";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.flake-utils.follows = "flake-utils";
|
||||
inputs.rust-overlay.follows = "rust-overlay";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, naersk, rust-overlay, pre-commit-hooks }:
|
||||
outputs = { self, nixpkgs, flake-utils, rust-overlay, pre-commit-hooks, crane }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
overlays = [ (import rust-overlay) ];
|
||||
pkgs = import nixpkgs { inherit system overlays; };
|
||||
naersk-lib = pkgs.callPackage naersk { };
|
||||
rustToolchain =
|
||||
pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||
|
||||
crane-lib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
|
||||
src = crane-lib.cleanCargoSource ./.;
|
||||
buildInputs = with pkgs; [
|
||||
openssl
|
||||
] ++ lib.optionals pkgs.stdenv.isDarwin [ pkgs.libiconv ];
|
||||
nativeBuildInputs = with pkgs; [
|
||||
pkgconf
|
||||
];
|
||||
|
||||
cargoArtifacts = crane-lib.buildDepsOnly {
|
||||
inherit src buildInputs nativeBuildInputs;
|
||||
};
|
||||
|
||||
ha-now-playing = crane-lib.buildPackage {
|
||||
inherit cargoArtifacts src buildInputs nativeBuildInputs;
|
||||
};
|
||||
|
||||
in
|
||||
{
|
||||
formatter = pkgs.nixpkgs-fmt;
|
||||
|
||||
packages = {
|
||||
ha-now-playing = (naersk-lib.override {
|
||||
cargo = rustToolchain;
|
||||
rustc = rustToolchain;
|
||||
}).buildPackage
|
||||
{
|
||||
pname = "ha-now-playing";
|
||||
root = ./.;
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
rustToolchain
|
||||
openssl
|
||||
];
|
||||
nativeBuildInputs = with pkgs; [
|
||||
pkgconf
|
||||
cargo-edit
|
||||
cargo-expand
|
||||
cargo-diet
|
||||
cargo-feature
|
||||
cargo-outdated
|
||||
rust-analyzer
|
||||
pre-commit
|
||||
jq
|
||||
gitflow
|
||||
yaml-language-server
|
||||
];
|
||||
};
|
||||
inherit ha-now-playing;
|
||||
};
|
||||
packages.default = self.packages.${system}.ha-now-playing;
|
||||
|
||||
|
@ -71,6 +66,17 @@
|
|||
};
|
||||
|
||||
checks = {
|
||||
inherit ha-now-playing;
|
||||
|
||||
ha-now-playing-clippy = crane-lib.cargoClippy {
|
||||
inherit cargoArtifacts src buildInputs nativeBuildInputs;
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
};
|
||||
|
||||
ha-now-playing-fmt = crane-lib.cargoFmt {
|
||||
inherit src;
|
||||
};
|
||||
|
||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
|
@ -97,6 +103,17 @@
|
|||
|
||||
name = "ha-now-playing";
|
||||
inputsFrom = [ self.packages.${system}.ha-now-playing ];
|
||||
packages = [
|
||||
rustToolchain
|
||||
cargo-edit
|
||||
cargo-diet
|
||||
cargo-feature
|
||||
cargo-outdated
|
||||
pre-commit
|
||||
rust-analyzer
|
||||
taplo
|
||||
gitflow
|
||||
];
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
@ -427,6 +427,7 @@ impl HomeAssistant {
|
|||
OutputFormat::Waybar => Waybar::builder()
|
||||
.text(text)
|
||||
.percentage((volume_raw * 100.) as u8)
|
||||
.muted(is_muted)
|
||||
.build()
|
||||
.to_string(),
|
||||
OutputFormat::I3Blocks => I3Blocks::builder().text(text).build().to_string(),
|
||||
|
|
|
@ -103,11 +103,15 @@ async fn main() -> Result<()> {
|
|||
let token = if let Some(token) = token {
|
||||
Some(token)
|
||||
} else if let Some(token_file) = token_file {
|
||||
if let Ok(mut file) = std::fs::File::open(token_file) {
|
||||
if let Ok(mut file) = std::fs::File::open(token_file.clone()) {
|
||||
let mut buf = String::new();
|
||||
file.read_to_string(&mut buf).ok();
|
||||
Some(buf)
|
||||
} else {
|
||||
println!(
|
||||
"Error reading API token file '{}'",
|
||||
token_file.as_path().display()
|
||||
);
|
||||
None
|
||||
}
|
||||
} else {
|
||||
|
@ -130,7 +134,7 @@ async fn main() -> Result<()> {
|
|||
.insecure(insecure)
|
||||
.format(format)
|
||||
.build();
|
||||
ha.open_connection().await.unwrap();
|
||||
ha.open_connection().await.unwrap_or(());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -11,6 +11,7 @@ pub(crate) struct WaybarBuilder {
|
|||
tooltip: String,
|
||||
class: String,
|
||||
percentage: u8,
|
||||
muted: bool,
|
||||
}
|
||||
|
||||
impl WaybarBuilder {
|
||||
|
@ -43,6 +44,11 @@ impl WaybarBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub(crate) fn muted(mut self, muted: bool) -> Self {
|
||||
self.muted = muted;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn build(self) -> Waybar {
|
||||
Waybar {
|
||||
text: self.text,
|
||||
|
@ -50,6 +56,7 @@ impl WaybarBuilder {
|
|||
tooltip: self.tooltip,
|
||||
class: self.class,
|
||||
percentage: self.percentage,
|
||||
muted: self.muted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +68,7 @@ pub(crate) struct Waybar {
|
|||
tooltip: String,
|
||||
class: String,
|
||||
percentage: u8,
|
||||
muted: bool,
|
||||
}
|
||||
|
||||
impl Waybar {
|
||||
|
|
Loading…
Reference in a new issue