Sha256: 77c4395da1dda074e581cdf94c09a0ac07b4fa9f150773188d22780670fdc736

Contents?: true

Size: 698 Bytes

Versions: 2

Compression:

Stored size: 698 Bytes

Contents

module Easee
  class State
    CHARGER_OP_MODES = {
      0 => :offline,
      1 => :disconnected,
      2 => :awaiting_start,
      3 => :charging,
      4 => :completed,
      5 => :error,
      6 => :ready_to_charge,
    }.freeze

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

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

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

    private

    def charger_op_mode = CHARGER_OP_MODES.fetch(@data.fetch(:chargerOpMode))
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stekker_easee-1.0.0 lib/easee/state.rb
stekker_easee-0.1.0 lib/easee/state.rb