From 984fb4ce9f8f8a5969a2f4a813cac5cabacbf6e5 Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Fri, 5 May 2023 11:07:30 +0200 Subject: [PATCH] [ecowatt] Remove the access token when the thing is removed Related to #14818 Signed-off-by: Laurent Garnier --- .../binding/ecowatt/internal/handler/EcowattHandler.java | 9 +++++++++ .../binding/ecowatt/internal/restapi/EcowattRestApi.java | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/handler/EcowattHandler.java b/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/handler/EcowattHandler.java index 13cf7735b361d..c6fd16e6b06cd 100644 --- a/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/handler/EcowattHandler.java +++ b/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/handler/EcowattHandler.java @@ -116,6 +116,15 @@ public void dispose() { } } + @Override + public void handleRemoval() { + EcowattRestApi localApi = api; + if (localApi != null) { + localApi.deleteServiceAndAccessToken(); + } + super.handleRemoval(); + } + /** * Schedule the next update of channels. * diff --git a/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/restapi/EcowattRestApi.java b/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/restapi/EcowattRestApi.java index 7da333721b3cf..c7f8d01fe4f2d 100644 --- a/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/restapi/EcowattRestApi.java +++ b/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/restapi/EcowattRestApi.java @@ -140,4 +140,8 @@ private AccessTokenResponse authenticate() throws CommunicationException { public void dispose() { oAuthFactory.ungetOAuthService(authServiceHandle); } + + public void deleteServiceAndAccessToken() { + oAuthFactory.deleteServiceAndAccessToken(authServiceHandle); + } }