use super::common::set_output_device;
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 AudioControlOutputDeviceSetDriver;
#[async_trait::async_trait]
impl Driver for AudioControlOutputDeviceSetDriver {
fn name(&self) -> &str {
"audio_control_output_device_set"
}
fn description(&self) -> &str {
"Set the active audio output device"
}
fn usage_hint(&self) -> &str {
"Use this skill to switch between speakers, headphones, or other output devices."
}
fn parameters(&self) -> Vec<DriverParameter> {
return vec![DriverParameter {
name: "device_id".to_string(),
param_type: "string".to_string(),
description: "Device ID from output device list".to_string(),
required: true,
default: None,
example: Some(Value::String("headphones".to_string())),
enum_values: None,
}];
}
fn example_call(&self) -> DriverResult<Value> {
Ok(json!({
"action": "audio_control_output_device_set",
"parameters": {
"device_id": "headphones"
}
}))
}
fn example_output(&self) -> String {
"Output device set to headphones".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_output_device_set driver");
let device_id = parameters.get("device_id").and_then(|v| v.as_str()).ok_or_else(|| {
debug!("Missing 'device_id' parameter");
DriverError::missing_parameter("device_id")
})?;
debug!("Setting output device to: {}", device_id);
set_output_device(device_id).map_err(|e| DriverError::execution(format!("Failed to set output device: {}", e)))?;
info!("Output device set to: {}", device_id);
Ok(format!("Output device set to {}", device_id))
}
}