From 831a7af2c66d6af4181cced222fe32761bd359da Mon Sep 17 00:00:00 2001 From: lolodomo Date: Fri, 5 May 2023 22:35:09 +0200 Subject: [PATCH] [ecowatt] Remove the access token when the thing is removed (#14934) 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 13cf7735b..c6fd16e6b 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 class EcowattHandler extends BaseThingHandler { } } + @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 7da333721..c7f8d01fe 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 @@ public class EcowattRestApi { public void dispose() { oAuthFactory.ungetOAuthService(authServiceHandle); } + + public void deleteServiceAndAccessToken() { + oAuthFactory.deleteServiceAndAccessToken(authServiceHandle); + } }