Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/zaptec/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def disconnected? = charger_operation_mode == DISCONNECTED

def paused? = charger_operation_mode == CONNECTED_FINISHED && final_stop_active?

def final_stop_active? = @data.fetch(:FinalStopActive).to_i == 1

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

def session_identifier
Expand All @@ -39,8 +41,6 @@ def meter_reading

private

def final_stop_active? = @data.fetch(:FinalStopActive).to_i == 1

def charger_operation_mode
Constants.charger_operation_mode_to_name(@data.fetch(:ChargerOperationMode).to_i)
end
Expand Down
15 changes: 15 additions & 0 deletions spec/zaptec/state_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
RSpec.describe Zaptec::State do
describe "#final_stop_active?" do
it "is true when FinalStopActive is 1" do
state = Zaptec::State.new(FinalStopActive: "1")

expect(state).to be_final_stop_active
end

it "is false when FinalStopActive is 0" do
state = Zaptec::State.new(FinalStopActive: "0")

expect(state).not_to be_final_stop_active
end
end
end