mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
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:
parent
ee12a84d4c
commit
f36412adf9
@ -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.
|
||||
|
@ -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()) //
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user