added power feature
This commit is contained in:
parent
2e6c297a06
commit
b4ca32cf0c
13
src/app.rs
13
src/app.rs
@ -13,6 +13,7 @@ pub enum ActiveApp {
|
||||
}
|
||||
|
||||
// enum used to select what kind of TV you are using
|
||||
// not used atm
|
||||
pub enum TV {
|
||||
Roku,
|
||||
Android,
|
||||
@ -20,6 +21,11 @@ pub enum TV {
|
||||
Amazon,
|
||||
}
|
||||
|
||||
pub enum TVPower {
|
||||
On,
|
||||
Off,
|
||||
}
|
||||
|
||||
pub fn match_to_app(text: String) -> ActiveApp {
|
||||
let mut result = text.split_whitespace();
|
||||
|
||||
@ -34,3 +40,10 @@ pub fn match_to_app(text: String) -> ActiveApp {
|
||||
_ => ActiveApp::Roku,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn match_to_power_status(text: String) -> TVPower {
|
||||
match text.trim() {
|
||||
"PowerOn" => TVPower::On,
|
||||
_ => TVPower::Off,
|
||||
}
|
||||
}
|
@ -29,6 +29,35 @@ impl Configuration {
|
||||
pub fn change_active_app(&mut self) {
|
||||
// stuff happens here
|
||||
}
|
||||
|
||||
pub fn get_tv_status(&self) -> String {
|
||||
let request = format!(
|
||||
"http://{ipaddr}:{port}/query/active-app",
|
||||
ipaddr = self.ipaddr,
|
||||
port = self.port
|
||||
);
|
||||
|
||||
let response = reqwest::get(&request).unwrap();
|
||||
let document = Document::from_read(response).unwrap();
|
||||
let next = document.find(Name("app")).next().unwrap();
|
||||
|
||||
next.text().to_string()
|
||||
}
|
||||
|
||||
pub fn get_power_status(&self) -> String {
|
||||
let request = format!(
|
||||
"http://{ipaddr}:{port}/query/device-info",
|
||||
ipaddr = self.ipaddr,
|
||||
port = self.port
|
||||
);
|
||||
|
||||
let response = reqwest::get(&request).unwrap();
|
||||
let document = Document::from_read(response).unwrap();
|
||||
let next = document.find(Name("power-mode")).next().unwrap();
|
||||
|
||||
next.text().to_string()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// grab the config
|
||||
@ -41,17 +70,3 @@ pub fn init_config() -> Configuration {
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
pub fn get_tv_status(configuration: &Configuration) -> String {
|
||||
let request = format!(
|
||||
"http://{ipaddr}:{port}/query/active-app",
|
||||
ipaddr = configuration.ipaddr,
|
||||
port = configuration.port
|
||||
);
|
||||
let response = reqwest::get(&request).unwrap();
|
||||
//println!("{}", response.status());
|
||||
let document = Document::from_read(response).unwrap();
|
||||
let next = document.find(Name("app")).next().unwrap();
|
||||
|
||||
next.text().to_string()
|
||||
}
|
||||
|
15
src/main.rs
15
src/main.rs
@ -22,9 +22,11 @@ fn main() {
|
||||
println!("{:?}", configuration);
|
||||
|
||||
loop {
|
||||
let text = config::get_tv_status(&configuration);
|
||||
let app_text = configuration.get_tv_status();
|
||||
let power_text = configuration.get_power_status();
|
||||
|
||||
let activeapp = app::match_to_app(text);
|
||||
let activeapp = app::match_to_app(app_text);
|
||||
let tvpower = app::match_to_power_status(power_text);
|
||||
|
||||
match activeapp {
|
||||
app::ActiveApp::Roku => println!("The lights are light purple!"),
|
||||
@ -35,8 +37,13 @@ fn main() {
|
||||
_ => println!("Oops!"),
|
||||
}
|
||||
|
||||
let sec = time::Duration::from_secs(1);
|
||||
match tvpower {
|
||||
app::TVPower::On => println!("TV is on!"),
|
||||
app::TVPower::Off => println!("TV is off!"),
|
||||
_ => println!("We don't know what the power status of the TV is..."),
|
||||
}
|
||||
|
||||
let sec = time::Duration::from_secs(3);
|
||||
thread::sleep(sec);
|
||||
//println!("{:?}", text as str);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user