Module: Growatt

Extended by:
WrAPI::Configuration, WrAPI::RespondTo
Defined in:
lib/growatt.rb,
lib/growatt/api.rb,
lib/growatt/const.rb,
lib/growatt/error.rb,
lib/growatt/client.rb,
lib/growatt/version.rb,
lib/growatt/connection.rb,
lib/growatt/pagination.rb,
lib/growatt/authorization.rb

Overview

The ‘Growatt` module provides a Ruby client for interacting with the Growatt API.

It extends ‘WrAPI::Configuration` for managing API settings and `WrAPI::RespondTo` for handling API responses dynamically.

The module allows you to create a client instance, configure API endpoints, and manage pagination settings.

Examples:

Creating a Growatt API client:

client = Growatt.client(api_key: "your_api_key")

Defined Under Namespace

Modules: Authentication, Connection, RequestPagination Classes: API, AuthenticationError, Client, ConfigurationError, Enum, ExportLimit, GrowattError, Inverter, Timespan

Constant Summary collapse

DEFAULT_UA =

Default User-Agent string for API requests.

"Ruby Growatt API client #{Growatt::VERSION}".freeze
DEFAULT_ENDPOINT =

Default API endpoint for Growatt services.

Note: ‘openapi.growatt.com/` is an alternative, but it does not work with some accounts.

'https://server.growatt.com/'
DEFAULT_PAGINATION =

Default pagination class used for handling paginated API responses.

RequestPagination::DataPager
VERSION =
'0.2.1'

Class Method Summary collapse

Class Method Details

.client(options = {}) ⇒ Growatt::Client

Initializes and returns a new ‘Growatt::Client` instance.

Examples:

Creating a client with custom options:

client = Growatt.client(user_agent: "MyCustomClient/1.0")

Parameters:

  • options (Hash) (defaults to: {})

    Configuration options for the client.

Options Hash (options):

  • :user_agent (String)

    Custom user agent string.

  • :endpoint (String)

    Custom API endpoint.

  • :pagination_class (Class)

    Custom pagination class.

Returns:



44
45
46
47
48
49
50
# File 'lib/growatt.rb', line 44

def self.client(options = {})
  Growatt::Client.new({ 
    user_agent: DEFAULT_UA, 
    endpoint: DEFAULT_ENDPOINT, 
    pagination_class: DEFAULT_PAGINATION 
  }.merge(options))
end

.resetObject

Resets the Growatt configuration to default values.

This method restores the API endpoint, user agent, and pagination settings to their default values.



55
56
57
58
59
60
61
# File 'lib/growatt.rb', line 55

def self.reset
  super
  self.endpoint   = nil
  self.user_agent = DEFAULT_UA
  self.endpoint   = DEFAULT_ENDPOINT
  self.pagination_class = DEFAULT_PAGINATION
end