From 00d15574db601ec36d5bb4b9e0fb1fb19fbb9416 Mon Sep 17 00:00:00 2001 From: Alexander Friese Date: Fri, 24 Jan 2025 21:13:54 +0100 Subject: [PATCH] [easee] Adjust configuration to new API limits (#18168) * dedicated polling interval for session data Signed-off-by: Alexander Friese --- bundles/org.openhab.binding.easee/README.md | 17 +++++++------ .../internal/config/EaseeConfiguration.java | 14 +++++++++-- .../internal/handler/EaseeChargerHandler.java | 25 +++++++++++++++++++ .../internal/handler/EaseeSiteHandler.java | 10 ++++++++ .../main/resources/OH-INF/config/config.xml | 6 +++++ .../resources/OH-INF/i18n/easee.properties | 4 ++- 6 files changed, 65 insertions(+), 11 deletions(-) diff --git a/bundles/org.openhab.binding.easee/README.md b/bundles/org.openhab.binding.easee/README.md index bcee314fe60..2141e33c956 100644 --- a/bundles/org.openhab.binding.easee/README.md +++ b/bundles/org.openhab.binding.easee/README.md @@ -23,14 +23,15 @@ Auto-discovery is supported and will discover all circuits and chargers assigned The following configuration parameters are available for the binding/bridge: -| Configuration Parameter | Required | Description | -|-------------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| username | yes | The username to login at Easee Cloud service. This should be an e-mail address or phone number. | -| passord | yes | Your password to login at Easee Cloud service. | -| siteId | yes | The ID of the site containing the wallbox(es) and circuit(s) that should be integrated into openHAB. The ID of your site can be found via the sites overview (). You just need to click one of the sites listed there, the id will be part of the URL which is then opened. It will be a number with typically 6 digits. | -| dataPollingInterval | no | Interval (seconds) in which live data values are retrieved from the Easee Cloud API. (default = 60) | -| webRequestInitialDelay | no | Initial time (seconds) to wait before first request is sent to the Easee Cloud API. (default = 10) | -| webRequestInterval | no | Interval (seconds) between two subsequent requests to be sent to the Easee Cloud API. (default = 2) | +| Configuration Parameter | Required | Description | +|------------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| username | yes | The username to login at Easee Cloud service. This should be an e-mail address or phone number. | +| passord | yes | Your password to login at Easee Cloud service. | +| siteId | yes | The ID of the site containing the wallbox(es) and circuit(s) that should be integrated into openHAB. The ID of your site can be found via the sites overview (). You just need to click one of the sites listed there, the id will be part of the URL which is then opened. It will be a number with typically 6 digits. | +| dataPollingInterval | no | Interval (seconds) in which live data values are retrieved from the Easee Cloud API. (default = 60) | +| sessionDataPollingInterval | no | Interval (seconds) in which session data values are retrieved from the Easee Cloud API. (default = 360) | +| webRequestInitialDelay | no | Initial time (seconds) to wait before first request is sent to the Easee Cloud API. (default = 10) | +| webRequestInterval | no | Interval (seconds) between two subsequent requests to be sent to the Easee Cloud API. (default = 2) | ## Thing configuration diff --git a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/config/EaseeConfiguration.java b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/config/EaseeConfiguration.java index 5f960212db2..5367fd2255a 100644 --- a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/config/EaseeConfiguration.java +++ b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/config/EaseeConfiguration.java @@ -29,6 +29,7 @@ public class EaseeConfiguration { private Integer asyncTimeout = 120; private Integer syncTimeout = 120; private Integer dataPollingInterval = 60; + private Integer sessionDataPollingInterval = 360; private Integer webRequestInitialDelay = 10; private Integer webRequestInterval = 2; @@ -80,6 +81,14 @@ public class EaseeConfiguration { this.dataPollingInterval = dataPollingInterval; } + public Integer getSessionDataPollingInterval() { + return sessionDataPollingInterval; + } + + public void setSessionDataPollingInterval(Integer sessionDataPollingInterval) { + this.sessionDataPollingInterval = sessionDataPollingInterval; + } + public Integer getWebRequestInitialDelay() { return webRequestInitialDelay; } @@ -102,8 +111,9 @@ public class EaseeConfiguration { builder.append("EaseeConfiguration [username=").append(username).append(", password=").append(password) .append(", siteId=").append(siteId).append(", asyncTimeout=").append(asyncTimeout) .append(", syncTimeout=").append(syncTimeout).append(", dataPollingInterval=") - .append(dataPollingInterval).append(", webRequestInitialDelay=").append(webRequestInitialDelay) - .append(", webRequestInterval=").append(webRequestInterval).append("]"); + .append(dataPollingInterval).append(", sessionDataPollingInterval=").append(sessionDataPollingInterval) + .append(", webRequestInitialDelay=").append(webRequestInitialDelay).append(", webRequestInterval=") + .append(webRequestInterval).append("]"); return builder.toString(); } } diff --git a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeChargerHandler.java b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeChargerHandler.java index 156a078a6f4..dce4da3e4bd 100644 --- a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeChargerHandler.java +++ b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeChargerHandler.java @@ -62,10 +62,19 @@ public class EaseeChargerHandler extends BaseThingHandler implements EaseeThingH * Schedule for polling live data */ private final AtomicReference<@Nullable Future> dataPollingJobReference; + private final AtomicReference<@Nullable Future> sessionDataPollingJobReference; public EaseeChargerHandler(Thing thing) { super(thing); this.dataPollingJobReference = new AtomicReference<>(null); + this.sessionDataPollingJobReference = new AtomicReference<>(null); + } + + void reInit() { + if (isInitialized()) { + dispose(); + initialize(); + } } @Override @@ -117,6 +126,9 @@ public class EaseeChargerHandler extends BaseThingHandler implements EaseeThingH private void startPolling() { updateJobReference(dataPollingJobReference, scheduler.scheduleWithFixedDelay(this::pollingRun, POLLING_INITIAL_DELAY, getBridgeConfiguration().getDataPollingInterval(), TimeUnit.SECONDS)); + + updateJobReference(sessionDataPollingJobReference, scheduler.scheduleWithFixedDelay(this::sessionDataPollingRun, + POLLING_INITIAL_DELAY, getBridgeConfiguration().getSessionDataPollingInterval(), TimeUnit.SECONDS)); } /** @@ -129,6 +141,18 @@ public class EaseeChargerHandler extends BaseThingHandler implements EaseeThingH // proceed if charger is online if (getThing().getStatus() == ThingStatus.ONLINE) { enqueueCommand(new GetConfiguration(this, chargerId, this::updateOnlineStatus)); + } + } + + /** + * Poll the Easee Cloud API session data endpoint one time. + */ + void sessionDataPollingRun() { + String chargerId = getConfig().get(EaseeBindingConstants.THING_CONFIG_ID).toString(); + logger.debug("polling session data for {}", chargerId); + + // proceed if charger is online + if (getThing().getStatus() == ThingStatus.ONLINE) { enqueueCommand(new LatestChargingSession(this, chargerId, this::updateOnlineStatus)); } } @@ -175,6 +199,7 @@ public class EaseeChargerHandler extends BaseThingHandler implements EaseeThingH public void dispose() { logger.debug("Handler disposed."); cancelJobReference(dataPollingJobReference); + cancelJobReference(sessionDataPollingJobReference); } /** diff --git a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeSiteHandler.java b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeSiteHandler.java index c23522f09be..630c5be5f88 100644 --- a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeSiteHandler.java +++ b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeSiteHandler.java @@ -35,6 +35,7 @@ import org.openhab.binding.easee.internal.config.EaseeConfiguration; import org.openhab.binding.easee.internal.connector.CommunicationStatus; import org.openhab.binding.easee.internal.connector.WebInterface; import org.openhab.binding.easee.internal.discovery.EaseeSiteDiscoveryService; +import org.openhab.core.config.core.Configuration; import org.openhab.core.config.discovery.DiscoveryService; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.ThingStatus; @@ -174,6 +175,15 @@ public class EaseeSiteHandler extends BaseBridgeHandler implements EaseeBridgeHa webInterface.dispose(); } + @Override + protected void updateConfiguration(Configuration configuration) { + super.updateConfiguration(configuration); + getChildChargerHandlers().forEach((name, handler) -> { + logger.debug("notify {}: config update", name); + handler.reInit(); + }); + } + @Override public EaseeConfiguration getBridgeConfiguration() { return this.getConfigAs(EaseeConfiguration.class); diff --git a/bundles/org.openhab.binding.easee/src/main/resources/OH-INF/config/config.xml b/bundles/org.openhab.binding.easee/src/main/resources/OH-INF/config/config.xml index 1b6ebd0f6ad..26791a3dcd5 100644 --- a/bundles/org.openhab.binding.easee/src/main/resources/OH-INF/config/config.xml +++ b/bundles/org.openhab.binding.easee/src/main/resources/OH-INF/config/config.xml @@ -36,6 +36,12 @@ Interval in which data is polled from EaseeCloud (in seconds). 60 + + + Interval in which session data is polled from EaseeCloud (in seconds). + 360 + diff --git a/bundles/org.openhab.binding.easee/src/main/resources/OH-INF/i18n/easee.properties b/bundles/org.openhab.binding.easee/src/main/resources/OH-INF/i18n/easee.properties index 8bd86e3a8ba..d381f554530 100644 --- a/bundles/org.openhab.binding.easee/src/main/resources/OH-INF/i18n/easee.properties +++ b/bundles/org.openhab.binding.easee/src/main/resources/OH-INF/i18n/easee.properties @@ -30,6 +30,8 @@ thing-type.config.easee.site.group.general.label = General thing-type.config.easee.site.group.general.description = General settings. thing-type.config.easee.site.password.label = Password thing-type.config.easee.site.password.description = Your password to login at Easee Cloud service. +thing-type.config.easee.site.sessionDataPollingInterval.label = Session Data Polling Interval +thing-type.config.easee.site.sessionDataPollingInterval.description = Interval in which session data is polled from EaseeCloud (in seconds). thing-type.config.easee.site.siteId.label = Site ID thing-type.config.easee.site.siteId.description = The ID of the site containing the charger(s) and circuit(s) that should be integrated into openHAB. thing-type.config.easee.site.username.label = Username @@ -37,7 +39,7 @@ thing-type.config.easee.site.username.description = The username to login at Eas thing-type.config.easee.site.webRequestInitialDelay.label = Initial Web Request Delay thing-type.config.easee.site.webRequestInitialDelay.description = Initial time to wait before first request is sent to EaseeCloud (in seconds). thing-type.config.easee.site.webRequestInterval.label = Web Request Interval -thing-type.config.easee.site.webRequestInterval.description = Interval between two subsequent requests are sent to EaseeCloud (in seconds). +thing-type.config.easee.site.webRequestInterval.description = Interval between two subsequent requests to be sent to EaseeCloud (in seconds). # channel group types