-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jacob Laursen <[email protected]>
- Loading branch information
Showing
10 changed files
with
498 additions
and
195 deletions.
There are no files selected for viewing
186 changes: 0 additions & 186 deletions
186
...n/java/org/openhab/binding/energidataservice/internal/api/DatahubTariffFilterFactory.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...org/openhab/binding/energidataservice/internal/api/filter/DatahubTariffFilterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** | ||
* Copyright (c) 2010-2024 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.energidataservice.internal.api.filter; | ||
|
||
import static org.openhab.binding.energidataservice.internal.EnergiDataServiceBindingConstants.*; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.time.LocalDate; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.energidataservice.internal.api.DatahubTariffFilter; | ||
import org.openhab.binding.energidataservice.internal.api.DateQueryParameter; | ||
import org.openhab.binding.energidataservice.internal.api.DateQueryParameterType; | ||
import org.openhab.binding.energidataservice.internal.api.filter.dto.DatahubFilter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
|
||
/** | ||
* Factory for creating a {@link DatahubTariffFilter} for a specific Grid Company GLN. | ||
* | ||
* @author Jacob Laursen - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class DatahubTariffFilterFactory { | ||
|
||
private static final String RESOURCE_NAME = "/filters/grid_tariffs.yaml"; | ||
|
||
private static final String NOTE_NET_TARIFF_C = "Nettarif C"; | ||
private static final String NOTE_SYSTEM_TARIFF = "Systemtarif"; | ||
private static final String NOTE_ELECTRICITY_TAX = "Elafgift"; | ||
private static final String NOTE_REDUCED_ELECTRICITY_TAX = "Reduceret elafgift"; | ||
private static final String NOTE_TRANSMISSION_NET_TARIFF = "Transmissions nettarif"; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(DatahubTariffFilterFactory.class); | ||
|
||
private final Map<String, DatahubFilter> filterMap = getMap(); | ||
|
||
private Map<String, DatahubFilter> getMap() { | ||
HashMap<String, DatahubFilter> filterMap = new HashMap<>(); | ||
Collection<DatahubFilter> filters = parseResource(); | ||
for (DatahubFilter filter : filters) { | ||
filterMap.put(filter.gln(), filter); | ||
} | ||
return filterMap; | ||
} | ||
|
||
private Collection<DatahubFilter> parseResource() { | ||
try (InputStream inputStream = DatahubTariffFilterFactory.class.getResourceAsStream(RESOURCE_NAME)) { | ||
if (inputStream == null) { | ||
throw new IllegalStateException("Grid tariffs resource not found"); | ||
} | ||
|
||
ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); | ||
mapper.registerModule(new JavaTimeModule()); | ||
|
||
return mapper.readValue(inputStream, | ||
mapper.getTypeFactory().constructCollectionType(List.class, DatahubFilter.class)); | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Grid tariffs resource could not be read and parsed", e); | ||
} | ||
} | ||
|
||
public DatahubTariffFilter getGridTariffByGLN(String globalLocationNumber) { | ||
DatahubFilter datahubFilter = filterMap.get(globalLocationNumber); | ||
if (datahubFilter != null) { | ||
logger.trace("Found filter in YAML resource: {}", datahubFilter); | ||
return new DatahubTariffFilter(datahubFilter.chargeTypeCodes(), datahubFilter.notes(), | ||
datahubFilter.start()); | ||
} | ||
return new DatahubTariffFilter(Set.of(), Set.of(NOTE_NET_TARIFF_C), | ||
DateQueryParameter.of(DateQueryParameterType.START_OF_YEAR)); | ||
} | ||
|
||
public static DatahubTariffFilter getSystemTariff() { | ||
return new DatahubTariffFilter(Set.of(), Set.of(NOTE_SYSTEM_TARIFF), | ||
DateQueryParameter.of(ENERGINET_CUTOFF_DATE)); | ||
} | ||
|
||
public static DatahubTariffFilter getTransmissionGridTariff() { | ||
return new DatahubTariffFilter(Set.of(), Set.of(NOTE_TRANSMISSION_NET_TARIFF), | ||
DateQueryParameter.of(ENERGINET_CUTOFF_DATE)); | ||
} | ||
|
||
public static DatahubTariffFilter getElectricityTax() { | ||
return new DatahubTariffFilter(Set.of(), Set.of(NOTE_ELECTRICITY_TAX), | ||
DateQueryParameter.of(ENERGINET_CUTOFF_DATE)); | ||
} | ||
|
||
public static DatahubTariffFilter getReducedElectricityTax() { | ||
return new DatahubTariffFilter(Set.of(), Set.of(NOTE_REDUCED_ELECTRICITY_TAX), | ||
DateQueryParameter.of(LocalDate.of(2021, 2, 1))); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ain/java/org/openhab/binding/energidataservice/internal/api/filter/dto/DatahubFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) 2010-2024 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.energidataservice.internal.api.filter.dto; | ||
|
||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.energidataservice.internal.api.ChargeTypeCode; | ||
import org.openhab.binding.energidataservice.internal.api.DateQueryParameter; | ||
import org.openhab.binding.energidataservice.internal.api.filter.serialization.ChargeTypeCodeDeserializer; | ||
import org.openhab.binding.energidataservice.internal.api.filter.serialization.DateQueryParameterDeserializer; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
|
||
/** | ||
* Record for deserializing YAML grid tariff definitions. | ||
* | ||
* @author Jacob Laursen - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public record DatahubFilter(String gln, | ||
@JsonDeserialize(contentUsing = ChargeTypeCodeDeserializer.class) Set<ChargeTypeCode> chargeTypeCodes, | ||
Set<String> notes, @JsonDeserialize(using = DateQueryParameterDeserializer.class) DateQueryParameter start) { | ||
@Override | ||
public DateQueryParameter start() { | ||
return Objects.isNull(start) ? DateQueryParameter.EMPTY : start; | ||
} | ||
|
||
@Override | ||
public Set<String> notes() { | ||
return Objects.isNull(notes) ? Set.of() : notes; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DatahubFilter{gln='" + gln + "', chargeTypeCodes=" + chargeTypeCodes + "', notes=" + notes + "', start=" | ||
+ start + '}'; | ||
} | ||
} |
Oops, something went wrong.