Fix up documentation
This commit is contained in:
parent
2421dd0f41
commit
8a9e8cf512
18
src/main.rs
18
src/main.rs
|
@ -14,14 +14,14 @@ use self::update::update_loop;
|
|||
|
||||
mod update;
|
||||
|
||||
/// The interval between data polls
|
||||
/// The base URL of My Autarco site.
|
||||
const BASE_URL: &str = "https://my.autarco.com";
|
||||
|
||||
/// The interval between data polls.
|
||||
///
|
||||
/// This depends on with which interval Autaurco processes new information from the invertor.
|
||||
const POLL_INTERVAL: u64 = 300;
|
||||
|
||||
/// The base URL of My Autarco site
|
||||
const BASE_URL: &'static str = "https://my.autarco.com";
|
||||
|
||||
/// The configuration for the My Autarco site
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Config {
|
||||
|
@ -33,7 +33,7 @@ struct Config {
|
|||
site_id: String,
|
||||
}
|
||||
|
||||
/// Loads the configuration
|
||||
/// Loads the configuration.
|
||||
///
|
||||
/// The configuration file `autarco.toml` should be located in the project path.
|
||||
///
|
||||
|
@ -64,18 +64,18 @@ struct Status {
|
|||
}
|
||||
|
||||
lazy_static! {
|
||||
/// The concurrently accessible current status
|
||||
/// The concurrently accessible current status.
|
||||
static ref STATUS: Mutex<Option<Status>> = Mutex::new(None);
|
||||
}
|
||||
|
||||
/// Returns the current (last known) status
|
||||
/// Returns the current (last known) status.
|
||||
#[get("/", format = "application/json")]
|
||||
async fn status() -> Option<Json<Status>> {
|
||||
let status_guard = STATUS.lock().expect("Status mutex was poisoined");
|
||||
status_guard.map(|status| Json(status))
|
||||
status_guard.map(Json)
|
||||
}
|
||||
|
||||
/// Starts the main update loop and sets up and launches Rocket
|
||||
/// Starts the main update loop and sets up and launches Rocket.
|
||||
#[rocket::main]
|
||||
async fn main() -> Result<()> {
|
||||
color_eyre::install()?;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! Module that handles the updating/retrieval of the status via the My Autarco site/API.
|
||||
//! Module for handling the status updating/retrieval via the My Autarco site/API.
|
||||
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
|
@ -22,7 +22,7 @@ fn api_url(site_id: &str, endpoint: &str) -> Result<Url, ParseError> {
|
|||
))
|
||||
}
|
||||
|
||||
/// The energy data returned by the energy API endpoint
|
||||
/// The energy data returned by the energy API endpoint.
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ApiEnergy {
|
||||
/// Total energy produced today (kWh)
|
||||
|
@ -33,14 +33,14 @@ struct ApiEnergy {
|
|||
pv_to_date: u32,
|
||||
}
|
||||
|
||||
/// The power data returned by the power API endpoint
|
||||
/// The power data returned by the power API endpoint.
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ApiPower {
|
||||
/// Current power production (W)
|
||||
pv_now: u32,
|
||||
}
|
||||
|
||||
/// Performs a login on the My Autarco site
|
||||
/// Performs a login on the My Autarco site.
|
||||
///
|
||||
/// It mainly stores the acquired cookie in the client's cookie jar. The login credentials come
|
||||
/// from the loaded configuration (see [`Config`]).
|
||||
|
@ -66,14 +66,14 @@ async fn update(config: &Config, client: &Client, last_updated: u64) -> Result<S
|
|||
let api_response = client.get(api_energy_url).send().await?;
|
||||
let api_energy: ApiEnergy = match api_response.error_for_status() {
|
||||
Ok(res) => res.json().await?,
|
||||
Err(err) => return Err(err.into()),
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
|
||||
let api_power_url = api_url(&config.site_id, "power").expect("valid API power URL");
|
||||
let api_response = client.get(api_power_url).send().await?;
|
||||
let api_power: ApiPower = match api_response.error_for_status() {
|
||||
Ok(res) => res.json().await?,
|
||||
Err(err) => return Err(err.into()),
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
|
||||
// Update the status.
|
||||
|
@ -92,14 +92,14 @@ pub(super) async fn update_loop() -> color_eyre::Result<()> {
|
|||
let config = load_config().await?;
|
||||
let client = ClientBuilder::new().cookie_store(true).build()?;
|
||||
|
||||
// Go to the My Autarco site and login
|
||||
// Go to the My Autarco site and login.
|
||||
println!("⚡ Logging in...");
|
||||
login(&config, &client).await?;
|
||||
println!("⚡ Logged in successfully!");
|
||||
|
||||
let mut last_updated = 0;
|
||||
loop {
|
||||
// Wake up every 10 seconds and check if there is something to do (quit or update).
|
||||
// Wake up every 10 seconds and check if an update is due.
|
||||
sleep(Duration::from_secs(10)).await;
|
||||
|
||||
let timestamp = SystemTime::now()
|
||||
|
|
Reference in New Issue