Skip to content

Commit

Permalink
Implement poll_lifetime_energy method
Browse files Browse the repository at this point in the history
Sending this command triggers the charger to invalidate the meter reading cache.

Co-authored-by: Bob <[email protected]>
  • Loading branch information
martijnversluis and Bob committed Mar 19, 2024
1 parent f8e6053 commit c00b5ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ GEM

PLATFORMS
arm64-darwin-22
arm64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down
5 changes: 5 additions & 0 deletions lib/easee/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def resume_charging(charger_id)
post("/api/chargers/#{charger_id}/commands/resume_charging")
end

# https://developer.easee.com/reference/post_api-chargers-chargerid-commands-poll-lifetimeenergy
def poll_lifetime_energy(charger_id)
post("/api/chargers/#{charger_id}/commands/poll_lifetimeenergy")
end

# https://developer.easee.cloud/reference/get_api-chargers-id-config
def configuration(charger_id)
get("/api/chargers/#{charger_id}/config")
Expand Down
20 changes: 20 additions & 0 deletions spec/easee/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,26 @@
end
end

describe "#poll_lifetime_energy" do
it "sends a poll_lifetimeenergy command" do
token_cache = ActiveSupport::Cache::MemoryStore.new
token_cache.write(
Easee::Client::TOKENS_CACHE_KEY,
{ "accessToken" => "T123" }.to_json,
)

stub = stub_request(:post, "https://api.easee.cloud/api/chargers/C123/commands/poll_lifetimeenergy")
.with(headers: { "Authorization" => "Bearer T123" })
.to_return(status: 200, body: "")

client = Easee::Client.new(user_name: "easee", password: "money", token_cache:)

client.poll_lifetime_energy("C123")

expect(stub).to have_been_requested
end
end

describe "#inspect" do
it "does not include the user name and password" do
token_cache = ActiveSupport::Cache::MemoryStore.new
Expand Down

0 comments on commit c00b5ae

Please sign in to comment.