pub struct SubSetting { /* private fields */ }Expand description
Settings for a Device
Because every device has a different settings layout, we need to propagate through them at runtime.
You can get the root of a Devices settings using the settings() method.
Propagate through the settings using expand().
A SubSetting SettingType can correspond any one of the following:
Menu- an object which contains settings or more menusValue- a setting with a set valueSlider- a setting with possible values on a scaleListorXlist- a setting with a list of possible values
§Example
use smartcast::{Device, SubSetting};
let mut dev = Device::from_ip("192.168.0.14").await?;
dev.set_auth_token("Z2zscc1udl");
let settings: Vec<SubSetting> = dev.settings().await?;
println!("{:#?}", settings);
// > [
// > SubSetting {
// > name: "Picture Mode",
// > value: Some(
// > String(
// > "Calibrated",
// > ),
// > ),
// > hidden: false,
// > read_only: false,
// > object_type: XList,
// > },
// > ...
// > ]
let pic_settings: Vec<SubSetting> = settings[0].expand().await?;
println!("{:#?}", pic_settings);
// > [
// > SubSetting {
// > name: "Picture Mode",
// > value: Some(
// > String(
// > "Calibrated",
// > ),
// > ),
// > hidden: false,
// > read_only: false,
// > object_type: XList,
// > },
// > SubSetting {
// > name: "Ambient Light Sensor",
// > value: Some(
// > String(
// > "Off",
// > ),
// > ),
// > hidden: false,
// > read_only: false,
// > object_type: List,
// > },
// > ...
// > ]Implementations§
Source§impl SubSetting
impl SubSetting
Sourcepub async fn expand(&self) -> Result<Vec<SubSetting>>
pub async fn expand(&self) -> Result<Vec<SubSetting>>
If the settings object is a Menu, get its SubSettings.
§Example
use smartcast::{Device, SubSetting};
let mut dev = Device::from_ip("192.168.0.14").await?;
dev.set_auth_token("Z2zscc1udl");
let settings: Vec<SubSetting> = dev.settings().await?;
println!("{:#?}", settings);
// > [
// > SubSetting {
// > name: "Picture",
// > value: None,
// > hidden: false,
// > read_only: false,
// > object_type: Menu,
// > },
// > ...
// > ]
let pic_settings: Vec<SubSetting> = settings[0].expand().await?;
println!("{:#?}", pic_settings);
// > [
// > SubSetting {
// > name: "Picture Mode",
// > value: Some(
// > String(
// > "Calibrated",
// > ),
// > ),
// > hidden: false,
// > read_only: false,
// > object_type: XList,
// > },
// > SubSetting {
// > name: "Ambient Light Sensor",
// > value: Some(
// > String(
// > "Off",
// > ),
// > ),
// > hidden: false,
// > read_only: false,
// > object_type: List,
// > },
// > ...
// > ]Returns true if the setting should be displayed.
Sourcepub fn setting_type(&self) -> SettingType
pub fn setting_type(&self) -> SettingType
Type of the settings object. See SettingType.
Sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Returns true if the value is a boolean. Returns false otherwise.
Sourcepub fn is_string(&self) -> bool
pub fn is_string(&self) -> bool
Returns true if the value is a String. Returns false otherwise.
Sourcepub fn value<T>(&self) -> Option<T>where
T: for<'de> Deserialize<'de>,
pub fn value<T>(&self) -> Option<T>where
T: for<'de> Deserialize<'de>,
Get the current value of the setting.
§Example
use smartcast::{Device, SubSetting};
let mut dev = Device::from_ip("192.168.0.14").await?;
let settings: Vec<SubSetting> = dev.settings().await?;
let pic_settings: Vec<SubSetting> = settings[0].expand().await?;
println!("{:#?}", pic_settings);
// > [
// > SubSetting {
// > name: "Picture Mode",
// > value: Some(
// > String(
// > "Calibrated",
// > ),
// > ),
// > hidden: false,
// > read_only: false,
// > object_type: XList,
// > },
// > ...
// > ]
if let Some(value) = pic_settings[0].value::<String>() {
println!("{}", value);
}
// > CalibratedSourcepub async fn update<T>(&self, new_value: T) -> Result<()>
pub async fn update<T>(&self, new_value: T) -> Result<()>
Change the value of the setting.
Returns an error if:
- The setting is
read-only. - The value passed in is not the same type as the value currently in the setting.
- In the case of a
Slider, the value passed in is higher than the max or lower than the min. - In the case of a
ListorXList, the value passed in is not present in the setting’sElements. - The
setting typeis not aSlider,List,Xlist, orValue.
§Example
use smartcast::{Device, SettingType, SubSetting};
let dev = Device::from_ip("192.168.0.14").await?;
let settings: Vec<SubSetting> = dev.settings().await?;
for setting in settings {
match setting.setting_type() {
// If the setting is a slider type, set it to the max
SettingType::Slider => {
let new_value = setting.slider_info().await?.unwrap().max;
setting.update(new_value).await?;
},
// If the setting is a list type, choose the first option
SettingType::List
| SettingType::XList => {
let new_value = setting.elements().await?[0].clone();
setting.update(new_value).await?;
},
_ => {},
}
}Sourcepub async fn slider_info(&self) -> Result<Option<SliderInfo>>
pub async fn slider_info(&self) -> Result<Option<SliderInfo>>
If the setting object is a Slider, get the slider info. See SliderInfo.
§Example
use smartcast::{Device, SubSetting};
let dev = Device::from_ip("192.168.0.14").await?;
let settings: Vec<SubSetting> = dev.settings().await?;
let pic_settings: Vec<SubSetting> = settings[0].expand().await?;
println!("{:#?}", pic_settings);
// > [
// > ...
// > SubSetting {
// > name: "Tint",
// > value: Some(
// > Number(
// > 0,
// > ),
// > ),
// > hidden: false,
// > read_only: false,
// > object_type: Slider,
// > },
// > ...
// > ]
if let Some(slider_info) = pic_settings[8].slider_info().await? {
println!("{:#?}", slider_info);
}
// > SliderInfo {
// > dec_marker: "Red",
// > inc_marker: "Green",
// > increment: 1,
// > max: 50,
// > min: -50,
// > center: 0,
// > }Sourcepub async fn elements(&self) -> Result<Vec<String>>
pub async fn elements(&self) -> Result<Vec<String>>
If the setting object is a List or XList, get its elements. See SettingType.
§Example
use smartcast::{Device, SubSetting};
let dev = Device::from_ip("192.168.0.14").await?;
let settings: Vec<SubSetting> = dev.settings().await?;
let pic_settings: Vec<SubSetting> = settings[0].expand().await?;
println!("{:#?}", pic_settings);
// > [
// > SubSetting {
// > name: "Picture Mode",
// > value: Some(
// > String(
// > "Calibrated",
// > ),
// > ),
// > hidden: false,
// > read_only: false,
// > object_type: XList,
// > },
// > ...
// > ]
println!("{:#?}", pic_settings[0].elements().await?);
// > [
// > "Vivid",
// > "Bright",
// > "Calibrated",
// > "Calibrated Dark*",
// > "Game",
// > "Sports",
// > ],Trait Implementations§
Source§impl Clone for SubSetting
impl Clone for SubSetting
Source§fn clone(&self) -> SubSetting
fn clone(&self) -> SubSetting
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more