Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[energidataservice] Introduce subscription-based providers #17456

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -86,12 +87,12 @@ public class ApiController {
.create();
private final HttpClient httpClient;
private final TimeZoneProvider timeZoneProvider;
private final String userAgent;
private final Supplier<String> userAgentSupplier;

public ApiController(HttpClient httpClient, TimeZoneProvider timeZoneProvider) {
this.httpClient = httpClient;
this.timeZoneProvider = timeZoneProvider;
userAgent = "openHAB/" + FrameworkUtil.getBundle(this.getClass()).getVersion().toString();
this.userAgentSupplier = this::getUserAgent;
}

/**
Expand All @@ -116,7 +117,7 @@ public ElspotpriceRecord[] getSpotPrices(String priceArea, Currency currency, Da
.param("start", start.toString()) //
.param("filter", "{\"" + FILTER_KEY_PRICE_AREA + "\":\"" + priceArea + "\"}") //
.param("columns", "HourUTC,SpotPrice" + currency) //
.agent(userAgent) //
.agent(userAgentSupplier.get()) //
.method(HttpMethod.GET);

if (!end.isEmpty()) {
Expand All @@ -138,6 +139,10 @@ public ElspotpriceRecord[] getSpotPrices(String priceArea, Currency currency, Da
}
}

private String getUserAgent() {
return "openHAB/" + FrameworkUtil.getBundle(this.getClass()).getVersion().toString();
}

private String sendRequest(Request request, Map<String, String> properties)
throws TimeoutException, ExecutionException, InterruptedException, DataServiceException {
logger.trace("GET request for {}", request.getURI());
Expand Down Expand Up @@ -210,7 +215,7 @@ public Collection<DatahubPricelistRecord> getDatahubPriceLists(GlobalLocationNum
.timeout(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.param("filter", mapToFilter(filterMap)) //
.param("columns", columns) //
.agent(userAgent) //
.agent(userAgentSupplier.get()) //
.method(HttpMethod.GET);

DateQueryParameter start = tariffFilter.getStart();
Expand Down Expand Up @@ -277,7 +282,7 @@ public CO2EmissionRecord[] getCo2Emissions(Dataset dataset, String priceArea, Da
.param("filter", "{\"" + FILTER_KEY_PRICE_AREA + "\":\"" + priceArea + "\"}") //
.param("columns", "Minutes5UTC,CO2Emission") //
.param("sort", "Minutes5UTC DESC") //
.agent(userAgent) //
.agent(userAgentSupplier.get()) //
.method(HttpMethod.GET);

try {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.time.ZoneId;
import java.util.Currency;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ChannelUID;
Expand Down Expand Up @@ -62,6 +64,12 @@ public class EnergiDataServiceBindingConstants {
CHANNEL_SYSTEM_TARIFF, CHANNEL_TRANSMISSION_GRID_TARIFF, CHANNEL_ELECTRICITY_TAX,
CHANNEL_REDUCED_ELECTRICITY_TAX);

public static final Set<String> CO2_EMISSION_CHANNELS = Set.of(CHANNEL_CO2_EMISSION_PROGNOSIS,
CHANNEL_CO2_EMISSION_REALTIME);

public static final Set<String> SUBSCRIPTION_CHANNELS = Stream
.concat(ELECTRICITY_CHANNELS.stream(), CO2_EMISSION_CHANNELS.stream()).collect(Collectors.toSet());

// List of all properties
public static final String PROPERTY_REMAINING_CALLS = "remainingCalls";
public static final String PROPERTY_TOTAL_CALLS = "totalCalls";
Expand Down
Loading