Class: Easee::State

Inherits:
Object
  • Object
show all
Defined in:
lib/easee/state.rb

Constant Summary collapse

OP_MODE_UNKNOWN =
:unknown
CHARGER_OP_MODES =
{
  0 => :offline,
  1 => :disconnected,
  2 => :awaiting_start,
  3 => :charging,
  4 => :completed,
  5 => :error,
  6 => :ready_to_charge,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ State

Returns a new instance of State.



15
16
17
# File 'lib/easee/state.rb', line 15

def initialize(data)
  @data = data.symbolize_keys
end

Instance Method Details

#charging?Boolean

Returns:

  • (Boolean)


19
# File 'lib/easee/state.rb', line 19

def charging? = charger_op_mode == :charging

#disconnected?Boolean

Returns:

  • (Boolean)


20
# File 'lib/easee/state.rb', line 20

def disconnected? = charger_op_mode == :disconnected

#meter_readingObject



23
24
25
26
27
28
# File 'lib/easee/state.rb', line 23

def meter_reading
  MeterReading.new(
    reading_kwh: @data.fetch(:lifetimeEnergy),
    timestamp: Time.zone.parse(@data.fetch(:latestPulse)),
  )
end

#online?Boolean

Returns:

  • (Boolean)


21
# File 'lib/easee/state.rb', line 21

def online? = @data.fetch(:isOnline)