Add mute/unmute commands

This commit is contained in:
Erwin Boskma 2022-04-12 21:56:16 +02:00
parent 44b2984fad
commit 8f93064e8b
Signed by: erwin
GPG key ID: 270B20D17394F7E5

View file

@ -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(),
};