]> git.basschouten.com Git - openhab-addons.git/commitdiff
Restrict CO2 emission datasets to price area DK1/DK2 (#16649)
authorJacob Laursen <jacob-github@vindvejr.dk>
Sun, 14 Apr 2024 07:37:15 +0000 (09:37 +0200)
committerGitHub <noreply@github.com>
Sun, 14 Apr 2024 07:37:15 +0000 (09:37 +0200)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
bundles/org.openhab.binding.energidataservice/README.md
bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/ApiController.java
bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/handler/EnergiDataServiceHandler.java

index 7c7434c9f86a2ad6a9ab4000c8f157dca1de1b69..73b8f6a700b0ef6ba0102829092508c053e1976b 100644 (file)
@@ -154,6 +154,9 @@ Channel `co2-emission-prognosis` provides estimated prognosis for future emissio
 Depending on the time of the day, an update of the prognosis may include estimates for more than 9 hours, but every update will have at least 9 hours into the future.
 A persistence configuration is required for this channel.
 
+Please note that the CO₂ emission channels only apply to Denmark.
+These channels will not be updated when the configured price area is not DK1 or DK2.
+
 ## Thing Actions
 
 Thing actions can be used to perform calculations as well as import prices directly into rules without relying on persistence.
index ee80274a59e64f3573d56f42ac5f7e7afbc56f0e..25588fa4650d72d3548e79a305b1126d817201f5 100644 (file)
@@ -263,6 +263,9 @@ public class ApiController {
         if (dataset != Dataset.CO2Emission && dataset != Dataset.CO2EmissionPrognosis) {
             throw new IllegalArgumentException("Invalid dataset " + dataset + " for getting CO2 emissions");
         }
+        if (!"DK1".equals(priceArea) && !"DK2".equals(priceArea)) {
+            throw new IllegalArgumentException("Invalid price area " + priceArea + " for getting CO2 emissions");
+        }
         Request request = httpClient.newRequest(ENDPOINT + DATASET_PATH + dataset)
                 .timeout(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS) //
                 .param("start", start.toString()) //
index 2a66f4442072678a553de30fdef972902aea67bf..414bde6993c533b3f8ee489a8dcae12a0736b62c 100644 (file)
@@ -196,6 +196,18 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
         return Set.of(EnergiDataServiceActions.class);
     }
 
+    @Override
+    public void channelLinked(ChannelUID channelUID) {
+        super.channelLinked(channelUID);
+
+        if (!"DK1".equals(config.priceArea) && !"DK2".equals(config.priceArea)
+                && (CHANNEL_CO2_EMISSION_PROGNOSIS.equals(channelUID.getId())
+                        || CHANNEL_CO2_EMISSION_REALTIME.contains(channelUID.getId()))) {
+            logger.warn("Item linked to channel '{}', but price area {} is not supported for this channel",
+                    channelUID.getId(), config.priceArea);
+        }
+    }
+
     @Override
     public void channelUnlinked(ChannelUID channelUID) {
         super.channelUnlinked(channelUID);
@@ -404,6 +416,10 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
 
     private void updateCo2Emissions(Dataset dataset, String channelId, DateQueryParameter dateQueryParameter)
             throws InterruptedException, DataServiceException {
+        if (!"DK1".equals(config.priceArea) && !"DK2".equals(config.priceArea)) {
+            // Dataset is only for Denmark.
+            return;
+        }
         Map<String, String> properties = editProperties();
         CO2EmissionRecord[] emissionRecords = apiController.getCo2Emissions(dataset, config.priceArea,
                 dateQueryParameter, properties);