Struct govee_api::GoveeClient
source · pub struct GoveeClient { /* private fields */ }Expand description
A client for interacting with Govee devices through their API.
This struct provides methods to control Govee devices using the Govee API. It requires a valid Govee API key and root URL to initialize.
Implementations§
source§impl GoveeClient
impl GoveeClient
Control a Govee device using the provided payload.
This method sends a PUT request to the Govee API’s control endpoint in order to control a Govee device.
Arguments
payload- The payload containing control instructions for the device.
Returns
Returns Ok(()) if the request is successful. Otherwise, returns a ReqwestError indicating the failure
pub async fn control_device( &self, payload: PayloadBody ) -> Result<(), ReqwestError>
source§impl GoveeClient
impl GoveeClient
Asynchronously controls multiple devices by sending payloads to the Govee API.
This method takes a vector of PayloadBody objects and sends control requests to the Govee API
for each payload asynchronously. It uses the provided self.govee_api_key and self.govee_root_url
to construct the API endpoint for each request.
Arguments
payloads: A vector ofPayloadBodyobjects representing the control payloads for the devices.
Returns
Returns a Result indicating success or an error that occurred during the requests.
Examples
let govee_client = GoveeClient::new("your_api_key", "https://api.govee.com");
let payloads = vec![payload1, payload2];
let result = govee_client.bulk_control_devices(payloads).await;
match result {
Ok(_) => println!("Devices controlled successfully"),
Err(err) => eprintln!("Error controlling devices: {:?}", err),
}
`pub async fn bulk_control_devices( &self, payloads: Vec<PayloadBody> ) -> Result<(), ReqwestError>
source§impl GoveeClient
impl GoveeClient
Controls a Govee appliance using the provided payload.
This method sends a PUT request to the Govee API to control an appliance with the specified payload. The payload should be in the form of a PayloadBody struct.
Arguments
payload- The payload containing the control instructions for the appliance.
Returns
Returns Ok(()) if the request is successful. Otherwise, returns a ReqwestError indicating the failure
pub async fn control_appliance( &self, payload: PayloadBody ) -> Result<(), ReqwestError>
source§impl GoveeClient
impl GoveeClient
Retrieves a list of Govee devices.
This method sends a GET request to the Govee API to retrieve a list of devices associated with the Govee account.
Returns
An ApiResponseGoveeDevices containing information about the devices.
Returns
Returns Ok(()) if the request is successful. Otherwise, returns a ReqwestError indicating the failure
pub async fn get_devices(&self) -> Result<ApiResponseGoveeDevices, ReqwestError>
source§impl GoveeClient
impl GoveeClient
Retrieves a list of Govee appliances.
This method sends a GET request to the Govee API to retrieve a list of appliances associated with the Govee account.
Returns
An ApiResponseGoveeAppliances containing information about the appliances.
Returns
Returns Ok(()) if the request is successful. Otherwise, returns a ReqwestError indicating the failure
pub async fn get_appliances( &self ) -> Result<ApiResponseGoveeAppliances, ReqwestError>
source§impl GoveeClient
impl GoveeClient
Retrieves the state of a Govee device.
This method sends a GET request to the Govee API to retrieve the state of a specific device.
Arguments
device- The device ID or name.model- The model of the device.
Returns
An ApiResponseGoveeDeviceState containing the current state of the device.
Returns
Returns Ok(()) if the request is successful. Otherwise, returns a ReqwestError indicating the failure