From d7b0650cef6e8f042e39d039dedc5db13fda3293 Mon Sep 17 00:00:00 2001 From: Bob Forma <1178544+bforma@users.noreply.github.com> Date: Tue, 14 Jul 2026 09:17:14 +0200 Subject: [PATCH] Fetch a single Easee charger by id Resolving one charge point at a time only needs that charger's data (notably its productCode), so expose GET /api/chargers/{id} instead of forcing callers to page the whole account listing. --- lib/easee/client.rb | 6 ++++++ spec/easee/client_spec.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/easee/client.rb b/lib/easee/client.rb index ddaad9a..4b9a512 100644 --- a/lib/easee/client.rb +++ b/lib/easee/client.rb @@ -44,6 +44,12 @@ def chargers end end + # https://developer.easee.cloud/reference/get_api-chargers-id + def charger(charger_id) + get("/api/chargers/#{charger_id}") + .then { |response| Charger.new(response.body) } + end + # https://developer.easee.cloud/reference/get_api-chargers-id-state def state(charger_id) get("/api/chargers/#{charger_id}/state") diff --git a/spec/easee/client_spec.rb b/spec/easee/client_spec.rb index fc0f2cb..56fada8 100644 --- a/spec/easee/client_spec.rb +++ b/spec/easee/client_spec.rb @@ -436,6 +436,38 @@ end end + describe "#charger" do + it "fetches a single charger by id" do + token_cache = ActiveSupport::Cache::MemoryStore.new + token_cache.write( + Easee::Client::TOKENS_CACHE_KEY, + { "accessToken" => "T123" }.to_json, + ) + + stub_request(:get, "https://api.easee.cloud/api/chargers/EASEE123") + .with(headers: { "Authorization" => "Bearer T123" }) + .to_return( + status: 200, + body: { + id: "EASEE123", + name: "EaseeChargePro", + color: 11, + productCode: 103, + }.to_json, + headers: { "Content-Type": "application/json" }, + ) + + client = Easee::Client.new(user_name: "easee", password: "money", token_cache:) + + expect(client.charger("EASEE123")).to have_attributes( + id: "EASEE123", + name: "EaseeChargePro", + color: 11, + product_code: 103, + ) + end + end + describe "#configuration" do it "fetches the technical configuration" do token_cache = ActiveSupport::Cache::MemoryStore.new