use super::common::volume_down;
use crate::{
DriverCallback, DriverCategory, DriverContext, DriverError, DriverResult,
types::{Driver, DriverParameter},
};
use serde_json::{Value, json};
use std::collections::HashMap;
use tracing::{debug, info};
#[derive(Debug)]
pub struct AudioControlVolumeDownDriver;
#[async_trait::async_trait]
impl Driver for AudioControlVolumeDownDriver {
fn name(&self) -> &str {
"audio_control_volume_down"
}
fn description(&self) -> &str {
"Decrease system volume by a specified amount"
}
fn usage_hint(&self) -> &str {
"Use this skill to decrease the volume. Default delta is 10 if not specified."
}
fn parameters(&self) -> Vec<DriverParameter> {
return vec![DriverParameter {
name: "delta".to_string(),
param_type: "integer".to_string(),
description: "Amount to decrease by (0-100)".to_string(),
required: false,
default: Some(Value::Number(10.into())),
example: Some(Value::Number(20.into())),
enum_values: None,
}];
}
fn example_call(&self) -> DriverResult<Value> {
Ok(json!({
"action": "audio_control_volume_down",
"parameters": {
"delta": 10
}
}))
}
fn example_output(&self) -> String {
"Volume decreased by 10%".to_string()
}
fn category(&self) -> DriverCategory {
DriverCategory::Audio
}
async fn execute(
&self,
parameters: &HashMap<String, Value>,
_callback: Option<&dyn DriverCallback>,
_context: Option<&DriverContext>,
) -> DriverResult<String> {
debug!("Executing audio_control_volume_down driver");
let delta = parameters.get("delta").and_then(|v| v.as_u64()).unwrap_or(10) as u32;
debug!("Decreasing volume by {}%", delta);
volume_down(delta).map_err(|e| DriverError::execution(format!("Failed to decrease volume: {}", e)))?;
info!("Volume decreased by {}%", delta);
Ok(format!("Volume decreased by {}%", delta))
}
}