Skip to content

Commit

Permalink
Also treat status "SPARE CAPACITY" as empty
Browse files Browse the repository at this point in the history
Belongs to #143
  • Loading branch information
ledermann committed Sep 3, 2024
1 parent dc596af commit 7aea0d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 5 additions & 2 deletions app/senec_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ def initialize(config:)

attr_reader :config

STAT_STATE_EMPTY = 15
STAT_STATE_EMPTY = [
15, # BATTERY EMPTY
89, # SPARE CAPACITY
].freeze

def bat_fuel_charge
refresh_request
Expand All @@ -20,7 +23,7 @@ def stat_state
end

def bat_empty?
stat_state == STAT_STATE_EMPTY
STAT_STATE_EMPTY.include?(stat_state)
end

def safe_charge_running?
Expand Down
14 changes: 8 additions & 6 deletions test/senec_provider_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ def test_allow_discharge!
end

def test_bat_empty
with_stubbed_request(
bat_fuel_charge: 13,
stat_state: SenecProvider::STAT_STATE_EMPTY,
) do
assert_in_delta 13, senec_provider.bat_fuel_charge
assert_predicate senec_provider, :bat_empty?
SenecProvider::STAT_STATE_EMPTY.each do |stat_state|
with_stubbed_request(
bat_fuel_charge: 13,
stat_state:,
) do
assert_in_delta 13, senec_provider.bat_fuel_charge
assert_predicate senec_provider, :bat_empty?
end
end
end

Expand Down

0 comments on commit 7aea0d4

Please sign in to comment.