Skip to content
Open
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
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
- ✨ Implement **support to access the extended ESIOS API** with a personal token
(you must request yours by mailing to [consultasios@ree.es](mailto:consultasios@ree.es?subject=Personal%20token%20request)),
with initial support for the existent PVPC price sensor (ESIOS indicator code: **1001**), and **3 new ones** 🤩:

- **Inyection price** sensor (ESIOS indicator code: **1739**),
name: "Precio de la energía excedentaria del autoconsumo para el mecanismo de compensación simplificada"
- **MAG price** sensor (ESIOS indicator code: **1900**),
Expand Down Expand Up @@ -108,7 +107,6 @@ with the same information than the current one, available without authentication
and make `tariff` and `websession` required arguments

- :sparkles: Add alternative data-source from 'apidatos.ree.es'

- Implement data parsing from `apidatos.ree.es`, using endpoint at `/es/datos/mercados/precios-mercados-tiempo-real`
- Add `data_source` parameter with valid keys 'apidatos' and 'esios_public', setting the new one as default ;-)
- Remove retry call if 403 status is received, but maintain the User-Agent loop, and also toggle the data-source for the next call
Expand Down
4 changes: 2 additions & 2 deletions aiopvpc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _parse_tariff_val(value, prec=PRICE_PRECISION) -> float:
return EsiosResponse(
name="PVPC ESIOS",
data_id="legacy",
last_update=datetime.utcnow().replace(microsecond=0, tzinfo=UTC_TZ),
last_update=datetime.now(UTC_TZ).replace(microsecond=0),
unit="€/kWh",
series={KEY_PVPC: pvpc_prices},
)
Expand All @@ -72,7 +72,7 @@ def extract_prices_from_esios_token(
unit = "•".join(mag["name"] for mag in indicator_data["magnitud"])
unit_tiempo = "•".join(mag["name"] for mag in indicator_data["tiempo"])
unit += f"/{unit_tiempo}"
ts_update = datetime.utcnow().replace(microsecond=0, tzinfo=UTC_TZ)
ts_update = datetime.now(UTC_TZ).replace(microsecond=0)

def _parse_dt(ts: str) -> datetime:
return datetime.fromisoformat(ts).astimezone(UTC_TZ) + offset_timezone
Expand Down
13 changes: 5 additions & 8 deletions aiopvpc/pvpc_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
DEFAULT_TIMEOUT,
EsiosApiData,
EsiosResponse,
KEY_INDEXED,
KEY_PVPC,
REFERENCE_TZ,
SENSOR_KEY_TO_API_SERIES,
Expand Down Expand Up @@ -301,13 +302,9 @@ async def _update_prices_series(
next(iter(current_prices)).strftime("%Y-%m-%d %Hh"),
)
return None
elif (
local_ref_now.hour < 20
and current_num_prices > 20
and (
list(current_prices)[-12].astimezone(REFERENCE_TZ).date()
== local_ref_now.date()
)
elif local_ref_now.hour < 20 < current_num_prices and (
list(current_prices)[-12].astimezone(REFERENCE_TZ).date()
== local_ref_now.date()
):
# already have today prices, avoid request
_LOGGER.debug(
Expand Down Expand Up @@ -407,7 +404,7 @@ def process_state_and_attributes(
)

# generate PVPC 2.0TD sensor attributes
if sensor_key == KEY_PVPC:
if sensor_key in [KEY_PVPC, KEY_INDEXED]:
local_time = utc_time.astimezone(self._local_timezone)
(
current_period,
Expand Down