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

fix(coordinator): don't attempt to read adjustment value on or after … #52

Merged
merged 1 commit into from
Mar 11, 2024
Merged
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
29 changes: 19 additions & 10 deletions custom_components/omie/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
_SCHEDULE_MAX_DELAY = timedelta(seconds=3)
"""The maximum delay after the scheduled time that we will fetch from OMIE to avoid thundering herd."""

ADJUSTMENT_END_DATE = date(2024, 1, 1)
"""The date on which the adjustment mechanism is no longer applicable."""

# language=Markdown
#
# OMIE market sessions and the values that they influence. Time shown below is publication time in the CET timezone plus 10 minutes.
Expand Down Expand Up @@ -208,16 +211,22 @@ async def fetch() -> OMIEModel:

def adjustment_price(client_session: ClientSession, get_market_date: DateFactory) -> UpdateMethod:
async def fetch():
dc = DateComponents.decompose(get_market_date())
source = f'https://www.omie.es/sites/default/files/dados/AGNO_{dc.yy}/MES_{dc.MM}/TXT/INT_MAJ_EV_H_{dc.dd_MM_yy}_{dc.dd_MM_yy}.TXT'

return await fetch_to_dict(client_session, source, get_market_date(), {
"Precio de ajuste en el sistema español (EUR/MWh)": 'adjustment_price_es',
"Precio de ajuste en el sistema portugués (EUR/MWh)": 'adjustment_price_pt',
"Energía horaria sujeta al MAJ a los consumidores MIBEL (MWh)": 'adjustment_energy',
"Energía horaria sujeta al mecanismo de ajuste a los consumidores MIBEL (MWh)": 'adjustment_energy',
"Cuantía unitaria del ajuste (EUR/MWh)": 'adjustment_unit_price',
})
market_date = get_market_date()
if market_date < ADJUSTMENT_END_DATE:
dc = DateComponents.decompose(market_date)
source = f'https://www.omie.es/sites/default/files/dados/AGNO_{dc.yy}/MES_{dc.MM}/TXT/INT_MAJ_EV_H_{dc.dd_MM_yy}_{dc.dd_MM_yy}.TXT'

return await fetch_to_dict(client_session, source, market_date, {
"Precio de ajuste en el sistema español (EUR/MWh)": 'adjustment_price_es',
"Precio de ajuste en el sistema portugués (EUR/MWh)": 'adjustment_price_pt',
"Energía horaria sujeta al MAJ a los consumidores MIBEL (MWh)": 'adjustment_energy',
"Energía horaria sujeta al mecanismo de ajuste a los consumidores MIBEL (MWh)": 'adjustment_energy',
"Cuantía unitaria del ajuste (EUR/MWh)": 'adjustment_unit_price',
})

else:
# adjustment mechanism ended in 2023
return {}

return fetch

Expand Down
Loading