Sha256: 518bc7bda67050a2ba08f9d4cda557f24905d500988123ea0d9e20367c024010

Contents?: true

Size: 868 Bytes

Versions: 4

Compression:

Stored size: 868 Bytes

Contents

module Zaptec
  class State
    CHARGING_MODES = %w[Connected_Requesting Connected_Charging].freeze
    DISCONNECTED = "Disconnected".freeze

    def initialize(data)
      @data = data
    end

    def total_charge_power = @data.fetch(:TotalChargePower).to_f

    def max_phases = @data.fetch(:MaxPhases).to_i

    def total_charge_power_session = @data.fetch(:TotalChargePowerSession).to_f

    def charging? = charger_operation_mode.in?(CHARGING_MODES)

    def disconnected? = charger_operation_mode == DISCONNECTED

    def online? = @data.fetch(:IsOnline).to_i.positive?

    def meter_reading
      @meter_reading ||= MeterReading.new(reading_kwh: total_charge_power_session, timestamp: Time.zone.now)
    end

    private

    def charger_operation_mode
      Constants.charger_operation_mode_to_name(@data.fetch(:ChargerOperationMode).to_i)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
stekker_zaptec-1.1.1 lib/zaptec/state.rb
stekker_zaptec-1.1.0 lib/zaptec/state.rb
stekker_zaptec-1.0.1 lib/zaptec/state.rb
stekker_zaptec-1.0.0 lib/zaptec/state.rb