From 35e9dca0a492ea7659d2de039d0588b1990d49d5 Mon Sep 17 00:00:00 2001 From: Martijn Versluis Date: Wed, 3 Jun 2026 09:50:01 +0200 Subject: [PATCH] Treat missing FinalStopActive observation as inactive --- lib/zaptec/state.rb | 2 +- spec/zaptec/state_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/zaptec/state.rb b/lib/zaptec/state.rb index 9d4f646..763cfa4 100644 --- a/lib/zaptec/state.rb +++ b/lib/zaptec/state.rb @@ -24,7 +24,7 @@ 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 final_stop_active? = @data[:FinalStopActive].to_i == 1 def online? = @data.fetch(:IsOnline).to_i.positive? diff --git a/spec/zaptec/state_spec.rb b/spec/zaptec/state_spec.rb index 00c5f17..61ea99c 100644 --- a/spec/zaptec/state_spec.rb +++ b/spec/zaptec/state_spec.rb @@ -11,5 +11,11 @@ expect(state).not_to be_final_stop_active end + + it "is false when the FinalStopActive observation is missing from the API response" do + state = Zaptec::State.new({}) + + expect(state).not_to be_final_stop_active + end end end