use std::net::IpAddr;
use framesmith::{FileAuthTokenStore, FrameTv, discover};
#[tokio::main]
async fn main() -> Result<(), framesmith::Error> {
let ip = match std::env::args().nth(1) {
Some(addr) => addr.parse::<IpAddr>().expect("invalid IP address"),
None => {
println!("Searching for Samsung Frame TVs on the network...\n");
let tvs = discover().await?;
if tvs.is_empty() {
println!("No TVs found. Make sure your TV is on and on the same network.");
return Ok(());
}
for tv in &tvs {
println!(" Found: {} at {} ({})", tv.name(), tv.ip(), tv.model());
}
println!();
tvs[0].ip()
}
};
println!("Connecting to {ip}...");
let token_path = std::env::temp_dir().join("framesmith_token.txt");
let tv = FrameTv::connection_builder(ip)
.auth_token_store(FileAuthTokenStore::new(&token_path))
.connect()
.await?;
println!("Connected! Auth token cached at {}\n", token_path.display());
let info = tv.get_device_info().await?;
println!("Device Info:");
println!(" Model: {}", info.model());
println!(" OS: {}", info.os());
println!(" Frame TV support: {}", info.frame_tv_support());
println!(" Power state: {:?}", info.power_state());
let brightness = tv.get_display_brightness().await?;
let color_temp = tv.get_display_color_temp().await?;
let rotation = tv.get_display_rotation().await?;
println!("\nDisplay Settings:");
println!(" Brightness: {}", brightness.as_value());
println!(" Color temp: {:+}", color_temp.as_value());
println!(" Rotation: {rotation:?}");
let art_mode = tv.is_artmode_enabled().await?;
println!(
"\nArt Mode: {}",
if art_mode { "enabled" } else { "disabled" }
);
let images = tv.get_uploaded_art_images().await?;
println!("Uploaded images: {}", images.len());
if let Ok(current) = tv.get_selected_art_image().await {
println!(
"Currently showing: {} ({}x{})",
current.id(),
current.width(),
current.height()
);
}
Ok(())
}