sonos_api/services/rendering_control/
state.rs1use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8use crate::SonosClient;
9
10#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
15pub struct RenderingControlState {
16 pub master_volume: Option<String>,
18
19 pub master_mute: Option<String>,
21
22 pub lf_volume: Option<String>,
24
25 pub rf_volume: Option<String>,
27
28 pub lf_mute: Option<String>,
30
31 pub rf_mute: Option<String>,
33
34 pub bass: Option<String>,
36
37 pub treble: Option<String>,
39
40 pub loudness: Option<String>,
42
43 pub balance: Option<String>,
45
46 pub other_channels: HashMap<String, String>,
48}
49
50pub fn poll(client: &SonosClient, ip: &str) -> crate::Result<RenderingControlState> {
55 let volume = client.execute_enhanced(
56 ip,
57 super::get_volume_operation("Master".to_string())
58 .build()
59 .map_err(|e| crate::ApiError::ParseError(e.to_string()))?,
60 )?;
61
62 let mute = super::get_mute_operation("Master".to_string())
63 .build()
64 .ok()
65 .and_then(|op| client.execute_enhanced(ip, op).ok());
66 let bass = super::get_bass_operation()
67 .build()
68 .ok()
69 .and_then(|op| client.execute_enhanced(ip, op).ok());
70 let treble = super::get_treble_operation()
71 .build()
72 .ok()
73 .and_then(|op| client.execute_enhanced(ip, op).ok());
74 let loudness = super::get_loudness_operation("Master".to_string())
75 .build()
76 .ok()
77 .and_then(|op| client.execute_enhanced(ip, op).ok());
78
79 Ok(RenderingControlState {
80 master_volume: Some(volume.current_volume.to_string()),
81 master_mute: mute.map(|m| if m.current_mute { "1" } else { "0" }.to_string()),
82 bass: bass.map(|b| b.current_bass.to_string()),
83 treble: treble.map(|t| t.current_treble.to_string()),
84 loudness: loudness.map(|l| if l.current_loudness { "1" } else { "0" }.to_string()),
85 lf_volume: None,
86 rf_volume: None,
87 lf_mute: None,
88 rf_mute: None,
89 balance: None,
90 other_channels: HashMap::new(),
91 })
92}