pub struct Envoy { /* private fields */ }Expand description
Main client for the Enphase Envoy local gateway.
This client provides access to local solar production, consumption, and inverter data. It handles session management and authentication with the Envoy device.
Implementations§
Source§impl Envoy
impl Envoy
Sourcepub fn new(host: impl Display) -> Self
pub fn new(host: impl Display) -> Self
Create a new Envoy client with the given host.
The host can be a hostname (e.g., “envoy.local”) or IP address (e.g., “192.168.1.100”). The client will connect via HTTPS by default.
§Arguments
host- The hostname or IP address of the Envoy device
§Returns
Returns a new Envoy client configured for the given host.
§Example
use enphase_api::Envoy;
let client = Envoy::new("envoy.local");Sourcepub fn with_client(host: impl Display, client: Client) -> Self
pub fn with_client(host: impl Display, client: Client) -> Self
Create a new Envoy client with the given host and HTTP client.
This allows you to provide a custom reqwest::Client with specific
configuration.
Since the Envoy client uses self-signed certificates, ensure that the provided client is configured to accept them if necessary (or ignore certificate errors).
Additionally, the Envoy client requires cookie storage to maintain session state, so ensure that the provided client has cookie store enabled.
§Arguments
host- The hostname or IP address of the Envoy deviceclient- A configuredreqwest::Client
§Example
use enphase_api::Envoy;
let client = reqwest::Client::new();
let envoy = Envoy::with_client("envoy.local", client);Sourcepub async fn authenticate(&self, token: impl Display) -> Result<()>
pub async fn authenticate(&self, token: impl Display) -> Result<()>
Authenticate with the Envoy device using a JWT token.
This validates that the provided token is valid by checking it against the Envoy device.
§Arguments
token- The JWT token to authenticate with. This is typically obtained from the Enphase Entrez service.
§Returns
Returns Ok(()) if authentication is successful.
§Errors
Returns an error if the token is invalid or the authentication check fails.
§Example
use enphase_api::{Envoy, Entrez};
let entrez = Entrez::default();
entrez.login_with_env().await?;
let token = entrez.generate_token("your-site-name", "your-envoy-serial-number", true).await?;
let client = Envoy::new("envoy.local");
client.authenticate(&token).await?;Sourcepub async fn set_power_state(
&self,
serial: impl Display,
state: PowerState,
) -> Result<()>
pub async fn set_power_state( &self, serial: impl Display, state: PowerState, ) -> Result<()>
Set the power state of an inverter or device.
This sends a command to the Envoy device to enable or disable power production on the specified device (identified by serial number).
§Arguments
serial- The serial number of the device to controlstate- The desired power state (PowerState::OnorPowerState::Off)
§Returns
Returns Ok(()) if the power state change is successful.
§Errors
Returns an error if the request fails or the device does not respond correctly.
§Example
use enphase_api::{Envoy, models::PowerState};
let client = Envoy::new("envoy.local");
client.set_power_state("603980032", PowerState::Off).await?;Sourcepub async fn get_power_state(&self, serial: impl Display) -> Result<bool>
pub async fn get_power_state(&self, serial: impl Display) -> Result<bool>
Get the power state of an inverter or device.
This retrieves the current power state from the Envoy device for the specified device (identified by serial number).
§Arguments
serial- The serial number of the device to query
§Returns
Returns Ok(true) if power is on, Ok(false) if power is off.
§Errors
Returns an error if the request fails or the response cannot be parsed.
§Example
use enphase_api::Envoy;
let client = Envoy::new("envoy.local");
let is_on = client.get_power_state("603980032").await?;
println!("Power is {}", if is_on { "on" } else { "off" });