diff --git a/CHANGELOG.md b/CHANGELOG.md index 200ffab..e056f65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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**), @@ -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 diff --git a/aiopvpc/parser.py b/aiopvpc/parser.py index 7772a4f..b87f0b1 100644 --- a/aiopvpc/parser.py +++ b/aiopvpc/parser.py @@ -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}, ) @@ -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 diff --git a/aiopvpc/pvpc_data.py b/aiopvpc/pvpc_data.py index 581b244..39cdf7e 100644 --- a/aiopvpc/pvpc_data.py +++ b/aiopvpc/pvpc_data.py @@ -26,6 +26,7 @@ DEFAULT_TIMEOUT, EsiosApiData, EsiosResponse, + KEY_INDEXED, KEY_PVPC, REFERENCE_TZ, SENSOR_KEY_TO_API_SERIES, @@ -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( @@ -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,