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

Indicador de ajuste de mercado y cálculo de Indexada #69

Merged
merged 6 commits into from
Mar 10, 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
10 changes: 9 additions & 1 deletion aiopvpc/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,33 @@
ESIOS_INJECTION = "1739"
ESIOS_MAG = "1900" # regargo GAS
ESIOS_OMIE = "10211" # precio mayorista
ESIOS_MARKET_ADJUSTMENT = "2108" # ajuste mercado Indexada VS PVPC
ESIOS_INDEXED = "0" # precio indexado restando PVPC y el ajuste

# unique ids for each series
KEY_PVPC = "PVPC"
KEY_INJECTION = "INJECTION"
KEY_MAG = "MAG" # regargo GAS
KEY_OMIE = "OMIE" # precio mayorista
KEY_ADJUSTMENT = "ADJUSTMENT" # ajuste mercado
KEY_INDEXED = "INDEXED" # precio indexada

ALL_SENSORS = (KEY_PVPC, KEY_INJECTION, KEY_MAG, KEY_OMIE)
ALL_SENSORS = (KEY_PVPC, KEY_INJECTION, KEY_MAG, KEY_OMIE, KEY_ADJUSTMENT)
SENSOR_KEY_TO_DATAID = {
KEY_PVPC: ESIOS_PVPC,
KEY_INJECTION: ESIOS_INJECTION,
KEY_MAG: ESIOS_MAG,
KEY_OMIE: ESIOS_OMIE,
KEY_ADJUSTMENT: ESIOS_MARKET_ADJUSTMENT,
KEY_INDEXED: ESIOS_MARKET_ADJUSTMENT,
azogue marked this conversation as resolved.
Show resolved Hide resolved
}
SENSOR_KEY_TO_NAME = {
KEY_PVPC: "PVPC T. 2.0TD",
KEY_INJECTION: "Precio de la energía excedentaria",
KEY_MAG: "2.0TD Excedente o déficit ajuste liquidación",
KEY_OMIE: "Precio medio horario final suma",
KEY_ADJUSTMENT: "Ajuste de mercado a plazo",
KEY_INDEXED: "Precio tarifa Indexada",
}


Expand Down
8 changes: 7 additions & 1 deletion aiopvpc/ha_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from aiopvpc.const import (
ALL_SENSORS,
KEY_ADJUSTMENT,
KEY_INDEXED,
KEY_INJECTION,
KEY_MAG,
KEY_OMIE,
Expand All @@ -20,6 +22,10 @@
f"{TARIFFS[1]}_{KEY_MAG}": KEY_MAG,
f"{TARIFFS[0]}_{KEY_OMIE}": KEY_OMIE,
f"{TARIFFS[1]}_{KEY_OMIE}": KEY_OMIE,
f"{TARIFFS[0]}_{KEY_ADJUSTMENT}": KEY_ADJUSTMENT,
f"{TARIFFS[1]}_{KEY_ADJUSTMENT}": KEY_ADJUSTMENT,
f"{TARIFFS[0]}_{KEY_INDEXED}": KEY_INDEXED,
f"{TARIFFS[1]}_{KEY_INDEXED}": KEY_INDEXED,
}


Expand All @@ -38,7 +44,7 @@ def get_enabled_sensor_keys(

def make_sensor_unique_id(config_entry_id: str, sensor_key: str) -> str:
"""(HA) Generate unique_id for each sensor kind and config entry."""
assert sensor_key in ALL_SENSORS
assert sensor_key in ALL_SENSORS or sensor_key == KEY_INDEXED
if sensor_key == KEY_PVPC:
# for old compatibility
return config_entry_id
Expand Down
16 changes: 16 additions & 0 deletions aiopvpc/pvpc_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
DEFAULT_TIMEOUT,
EsiosApiData,
EsiosResponse,
KEY_ADJUSTMENT,
KEY_INDEXED,
KEY_PVPC,
REFERENCE_TZ,
SENSOR_KEY_TO_DATAID,
Expand Down Expand Up @@ -274,10 +276,24 @@ async def async_update_all(
current_data.data_source = self._data_source
current_data.last_update = utc_now

if (
KEY_PVPC in current_data.availability
and KEY_ADJUSTMENT in current_data.availability
):
self._calculate_indexed(current_data)

for sensor_key in current_data.sensors:
self.process_state_and_attributes(current_data, sensor_key, now)
return current_data

def _calculate_indexed(self, current_data: EsiosApiData):
pvpc = current_data.sensors[KEY_PVPC]
adjustment = current_data.sensors[KEY_ADJUSTMENT]
current_data.sensors[KEY_INDEXED] = {
date: pvpc[date] - adjustment[date] for date in pvpc
}
current_data.availability[KEY_INDEXED] = True

async def _update_prices_series(
self,
sensor_key: str,
Expand Down
Loading
Loading