Crates.io | n3rgy_consumer_api_client |
lib.rs | n3rgy_consumer_api_client |
version | 0.1.1 |
source | src |
created_at | 2024-09-17 17:45:56.322985 |
updated_at | 2024-09-17 19:44:23.64691 |
description | A client for retrieving energy data from n3rgy's consumer API |
homepage | |
repository | https://github.com/rars/n3rgy_consumer_api_client |
max_upload_size | |
id | 1377781 |
size | 22,150 |
A Rust client for accessing electricity and gas smart meter data in the United Kingdom via the n3rgy consumer data REST API.
Note: This library is not affiliated with or endorsed by n3rgy.
To access your data, you must enroll in the n3rgy consumer access service. Follow these steps:
Set the environment variable N3RGY__APIKEY
to your In Home Device (IHD) MAC address, formatted without hyphens.
use chrono::{Days, Local};
use n3rgy_consumer_api_client::{ConsumerApiClient, EnvironmentAuthorizationProvider};
#[tokio::main]
async fn main() {
let ap = EnvironmentAuthorizationProvider {};
let client = ConsumerApiClient::new(ap, None);
let today = Local::now().date_naive();
let yesterday = today.checked_sub_days(Days::new(1)).unwrap();
if let Ok(consumption) = client.get_electricity_consumption(yesterday, today).await {
println!(
"Retrieved {} electricity consumption records",
consumption.len()
);
}
if let Ok(consumption) = client.get_electricity_tariff(yesterday, today).await {
println!("Retrieved {} electricity tariff records", consumption.len());
}
if let Ok(consumption) = client.get_gas_consumption(yesterday, today).await {
println!("Retrieved {} gas consumption records", consumption.len());
}
if let Ok(consumption) = client.get_gas_tariff(yesterday, today).await {
println!("Retrieved {} gas tariff records", consumption.len());
}
}
For interactive user input, consider using StaticAuthorizationProvider::new(api_key)
rather than EnvironmentAuthorizationProvider
.
API keys are sensitive information. Ensure they are not stored in source control. Use environment variables or secure vaults to manage them safely.
This project is licensed under the MIT License - see the LICENSE file for details.