SubSetting

Struct SubSetting 

Source
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 menus
  • Value - a setting with a set value
  • Slider - a setting with possible values on a scale
  • List or Xlist - 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

Source

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,
// > },
// > ...
// > ]
Source

pub fn name(&self) -> String

Name of the setting.

Source

pub fn hidden(&self) -> bool

Returns true if the setting should be displayed.

Source

pub fn read_only(&self) -> bool

Returns true if the setting is read only.

Source

pub fn setting_type(&self) -> SettingType

Type of the settings object. See SettingType.

Source

pub fn is_boolean(&self) -> bool

Returns true if the value is a boolean. Returns false otherwise.

Source

pub fn is_string(&self) -> bool

Returns true if the value is a String. Returns false otherwise.

Source

pub fn is_number(&self) -> bool

Returns true if the Value is a 32 bit signed integer.

Source

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);
}
// > Calibrated
Source

pub async fn update<T>(&self, new_value: T) -> Result<()>
where SubSetting: Write<T>, T: Serialize + for<'de> Deserialize<'de> + Debug,

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 List or XList, the value passed in is not present in the setting’s Elements.
  • The setting type is not a Slider, List, Xlist, or Value.
§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?;
        },

        _ => {},
    }
}
Source

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,
// > }
Source

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

Source§

fn clone(&self) -> SubSetting

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SubSetting

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SubSetting

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,