Class: Egauge::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/egauge/client.rb

Constant Summary collapse

EGAUGE_PATH =
'/cgi-bin/egauge-show?'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(base_url) ⇒ Client

The base_url should look something like this: ‘egauge12345.egaug.es



10
11
12
# File 'lib/egauge/client.rb', line 10

def initialize(base_url)
  @client = HTTPClient.new(base_url: base_url)
end

Instance Method Details

#fetch(options) ⇒ Object

The options hash should have 3 keys defined:

  1. :timestamp [Timestamp] - This is the point in time from which to fetch past readings. The “latest” reading will be the beginning of the current period breakdown. For instance if the timestamp is 2018-10-20 13:06 and the breakdown is hourly, the latest reading will be from 2018-10-20 13:00

  2. :breakdown [Symbol] - This defines the time period between the readings. This can be :hour, :day or :month

  3. :count [Integer] - Number of past readings to fetch

This method returns an array of hashes with these values

- "Date & Time" (An integer representing time since epoch)
- "Usage [kWh]"
- "Generation [kWh]"
- "Solar [kWh]"
- "Solar+ [kWh]"


31
32
33
34
35
# File 'lib/egauge/client.rb', line 31

def fetch(options)
  timestamps = build_timestamps(options)
  params = { T: timestamps.join(","), c: nil }
  query(params)
end