Class: Zaptec::State

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

Constant Summary collapse

CONNECTED_REQUESTING =
"Connected_Requesting".freeze
CONNECTED_CHARGING =
"Connected_Charging".freeze
DISCONNECTED =
"Disconnected".freeze
CHARGING_MODES =
[CONNECTED_CHARGING, CONNECTED_REQUESTING].freeze

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ State

Returns a new instance of State.



8
9
10
# File 'lib/zaptec/state.rb', line 8

def initialize(data)
  @data = data
end

Instance Method Details

#charging?Boolean

Returns:

  • (Boolean)


18
# File 'lib/zaptec/state.rb', line 18

def charging? = charger_operation_mode.in?(CHARGING_MODES)

#disconnected?Boolean

Returns:

  • (Boolean)


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

def disconnected? = charger_operation_mode == DISCONNECTED

#max_phasesObject



14
# File 'lib/zaptec/state.rb', line 14

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

#meter_readingObject



24
25
26
# File 'lib/zaptec/state.rb', line 24

def meter_reading
  @meter_reading ||= MeterReading.parse(@data.fetch(:SignedMeterValue))
end

#online?Boolean

Returns:

  • (Boolean)


22
# File 'lib/zaptec/state.rb', line 22

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

#total_charge_powerObject



12
# File 'lib/zaptec/state.rb', line 12

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

#total_charge_power_sessionObject



16
# File 'lib/zaptec/state.rb', line 16

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