Restrict CO2 emission datasets to price area DK1/DK2 (#16649)

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Jacob Laursen 2024-04-14 09:37:15 +02:00 committed by Ciprian Pascu
parent ee12a84d4c
commit f36412adf9
3 changed files with 22 additions and 0 deletions

View 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. 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. 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
Thing actions can be used to perform calculations as well as import prices directly into rules without relying on persistence. Thing actions can be used to perform calculations as well as import prices directly into rules without relying on persistence.

View File

@ -263,6 +263,9 @@ public class ApiController {
if (dataset != Dataset.CO2Emission && dataset != Dataset.CO2EmissionPrognosis) { if (dataset != Dataset.CO2Emission && dataset != Dataset.CO2EmissionPrognosis) {
throw new IllegalArgumentException("Invalid dataset " + dataset + " for getting CO2 emissions"); 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) Request request = httpClient.newRequest(ENDPOINT + DATASET_PATH + dataset)
.timeout(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS) // .timeout(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.param("start", start.toString()) // .param("start", start.toString()) //

View File

@ -196,6 +196,18 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
return Set.of(EnergiDataServiceActions.class); 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 @Override
public void channelUnlinked(ChannelUID channelUID) { public void channelUnlinked(ChannelUID channelUID) {
super.channelUnlinked(channelUID); super.channelUnlinked(channelUID);
@ -404,6 +416,10 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
private void updateCo2Emissions(Dataset dataset, String channelId, DateQueryParameter dateQueryParameter) private void updateCo2Emissions(Dataset dataset, String channelId, DateQueryParameter dateQueryParameter)
throws InterruptedException, DataServiceException { throws InterruptedException, DataServiceException {
if (!"DK1".equals(config.priceArea) && !"DK2".equals(config.priceArea)) {
// Dataset is only for Denmark.
return;
}
Map<String, String> properties = editProperties(); Map<String, String> properties = editProperties();
CO2EmissionRecord[] emissionRecords = apiController.getCo2Emissions(dataset, config.priceArea, CO2EmissionRecord[] emissionRecords = apiController.getCo2Emissions(dataset, config.priceArea,
dateQueryParameter, properties); dateQueryParameter, properties);