added funtionality to turn off lights when TV is off

Added some functionality when the TV is turned off, the lights turn off.
This commit is contained in:
Wyatt J. Miller
2020-01-24 22:08:10 +00:00
parent fa6b56e675
commit 023434cfcc
4 changed files with 97 additions and 38 deletions

View File

@ -2,36 +2,45 @@ extern crate serde;
extern crate serde_derive;
extern crate serde_json;
use std::fs::File;
use std::io::{BufReader, Read};
use std::fs::{write, File};
use std::io::{BufReader, Read, BufWriter, Write};
use std::path::Path;
use std::future::Future;
use reqwest::Client;
use select::document::Document;
use select::predicate::Name;
use serde::Deserialize;
use serde::{Serialize, Deserialize};
use serde_json::Result;
// config structure
#[derive(Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug)]
pub struct Configuration {
pub ipaddr: String,
pub port: i32,
pub tv: String,
pub active_app: String,
pub power_status: String,
}
impl Configuration {
pub fn is_change_app(&self) -> bool {
true
self.active_app == self.get_app_status()
}
pub fn change_active_app(&mut self) {
// stuff happens here
pub fn is_change_power(&self) -> bool {
self.power_status == self.get_power_status()
}
pub fn get_tv_status(&self) -> String {
pub fn change_active_app(&mut self, app_text: &String) {
self.active_app = app_text.to_string();
}
pub fn change_power(&mut self, power_text: &String) {
self.power_status = power_text.to_string();
}
pub fn get_app_status(&self) -> String {
let request = format!(
"http://{ipaddr}:{port}/query/active-app",
ipaddr = self.ipaddr,