pub struct Entrez { /* private fields */ }Expand description
Main client for the Enphase Entrez service.
This client provides authentication and token generation for accessing Envoy devices via JWT tokens.
Implementations§
Source§impl Entrez
impl Entrez
Sourcepub fn with_client(url: impl Into<String>, client: Client) -> Self
pub fn with_client(url: impl Into<String>, client: Client) -> Self
Create a new Entrez client with the given URL and HTTP client.
This allows you to provide a custom reqwest::Client with specific
configuration.
§Arguments
url- The base URL of the Entrez serviceclient- A configuredreqwest::Client. The client should have cookie storage enabled to maintain session state.
§Example
use enphase_api::Entrez;
let client = reqwest::Client::new();
let entrez = Entrez::with_client("https://entrez.enphaseenergy.com", client);Sourcepub async fn login(
&self,
username: impl AsRef<str>,
password: impl AsRef<str>,
) -> Result<()>
pub async fn login( &self, username: impl AsRef<str>, password: impl AsRef<str>, ) -> Result<()>
Log in to the Enphase Entrez service.
This authenticates your account and maintains the session for subsequent API calls. The session is maintained automatically by the HTTP agent.
§Arguments
username- Your Enphase account usernamepassword- Your Enphase account password
§Returns
Returns Ok(()) if login is successful.
§Errors
Returns an error if the login fails due to invalid credentials or network issues.
§Example
use enphase_api::Entrez;
let client = Entrez::default();
client.login("user@example.com", "password").await?;Sourcepub async fn login_with_env(&self) -> Result<()>
pub async fn login_with_env(&self) -> Result<()>
Log in to the Enphase Entrez service using environment variables.
This authenticates your account using credentials from ENTREZ_USERNAME
and ENTREZ_PASSWORD environment variables. The session is maintained
automatically by the HTTP agent for subsequent API calls.
§Returns
Returns Ok(()) if login is successful.
§Errors
Returns an error if:
- The
ENTREZ_USERNAMEorENTREZ_PASSWORDenvironment variables are not set - The login fails due to invalid credentials or network issues
§Example
use enphase_api::Entrez;
// Set ENTREZ_USERNAME and ENTREZ_PASSWORD environment variables
let client = Entrez::default();
client.login_with_env().await?;Sourcepub async fn generate_token(
&self,
site_name: impl AsRef<str>,
serial_number: impl AsRef<str>,
commissioned: bool,
) -> Result<String>
pub async fn generate_token( &self, site_name: impl AsRef<str>, serial_number: impl AsRef<str>, commissioned: bool, ) -> Result<String>
Generate a JWT token for accessing an Envoy device.
This generates a token that can be used to authenticate with a specific Envoy device. The token is typically valid for a limited time period.
§Arguments
site_name- The name of the siteserial_number- The serial number of the Envoy devicecommissioned- Whether the device is commissioned (true) or not (false)
§Returns
Returns the JWT token string on success.
§Errors
Returns an error if:
- The request fails
- The site or serial number is not found
- You are not logged in
§Example
use enphase_api::Entrez;
let client = Entrez::default();
client.login("user@example.com", "password").await?;
let token = client.generate_token("My Site", "121212121212", true).await?;
println!("Token: {}", token);