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

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

source

pub async fn control_device( &self, payload: PayloadBody ) -> Result<(), ReqwestError>

source§

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 of PayloadBody objects 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),
}
`
source

pub async fn bulk_control_devices( &self, payloads: Vec<PayloadBody> ) -> Result<(), ReqwestError>

source§

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

source

pub async fn control_appliance( &self, payload: PayloadBody ) -> Result<(), ReqwestError>

source§

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

source§

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

source§

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

source

pub async fn get_device_state( &self, device: &str, model: &str ) -> Result<ApiResponseGoveeDeviceState, ReqwestError>

source§

impl GoveeClient

source

pub fn new(api_key: &str) -> GoveeClient

Creates a new instance of the GoveeClient with the specified API key and root URL.

Arguments
  • govee_api_key - A valid Govee API key for authentication.
  • govee_root_url - The root URL of the Govee API.
Returns

A new GoveeClient instance.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more