Add mute/unmute commands
This commit is contained in:
parent
44b2984fad
commit
8f93064e8b
1 changed files with 10 additions and 0 deletions
10
src/main.rs
10
src/main.rs
|
@ -58,6 +58,10 @@ enum Command {
|
|||
VolumeDown,
|
||||
/// Set volume to value
|
||||
Volume { volume: u8 },
|
||||
/// Mute volume
|
||||
Mute,
|
||||
/// Unmute volume
|
||||
Unmute,
|
||||
}
|
||||
|
||||
impl Display for Command {
|
||||
|
@ -67,6 +71,8 @@ impl Display for Command {
|
|||
Command::VolumeUp => write!(f, "Volume Up"),
|
||||
Command::VolumeDown => write!(f, "Volume Down"),
|
||||
Command::Volume { volume } => write!(f, "Volume {volume}"),
|
||||
Command::Mute => write!(f, "Mute volume"),
|
||||
Command::Unmute => write!(f, "Unmute volume"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +161,8 @@ async fn call_service(
|
|||
Command::VolumeUp => "volume_up",
|
||||
Command::VolumeDown => "volume_down",
|
||||
Command::Volume { .. } => "volume_set",
|
||||
Command::Mute => "volume_mute",
|
||||
Command::Unmute => "volume_mute",
|
||||
};
|
||||
|
||||
let url = format!(
|
||||
|
@ -169,6 +177,8 @@ async fn call_service(
|
|||
json!({ "entity_id": entity, "volume_level": volume.clamp(0, 100) as f32 / 100. })
|
||||
.to_string()
|
||||
}
|
||||
Command::Mute => json!({ "entity_id": entity, "is_volume_muted": true }).to_string(),
|
||||
Command::Unmute => json!({ "entity_id": entity, "is_volume_muted": false }).to_string(),
|
||||
_ => json!({ "entity_id": entity }).to_string(),
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue