meteocat 2.2.4 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/custom_components/meteocat/__init__.py +1 -1
- package/custom_components/meteocat/const.py +1 -1
- package/custom_components/meteocat/coordinator.py +14 -10
- package/custom_components/meteocat/manifest.json +1 -1
- package/custom_components/meteocat/sensor.py +21 -8
- package/custom_components/meteocat/version.py +1 -1
- package/package.json +1 -1
- package/pyproject.toml +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## [2.2.5](https://github.com/figorr/meteocat/compare/v2.2.4...v2.2.5) (2025-02-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* 2.2.5 ([cd8fb52](https://github.com/figorr/meteocat/commit/cd8fb52c607e3a74308246136b6ac2d47b51e125))
|
|
7
|
+
* fix lightning status sensor native value ([dc3badc](https://github.com/figorr/meteocat/commit/dc3badc7b66d9afbcc14e23da3f0909f845cef2f))
|
|
8
|
+
* fix validity at lightning coordinator and cached data ([d959bc5](https://github.com/figorr/meteocat/commit/d959bc56dfb19a475b2e34a2649bbabd803ab41e))
|
|
9
|
+
* new lighting validity hour ([eab0215](https://github.com/figorr/meteocat/commit/eab0215cc3d68de9f900a4ecf1844ef3c6c22610))
|
|
10
|
+
|
|
1
11
|
## [2.2.4](https://github.com/figorr/meteocat/compare/v2.2.3...v2.2.4) (2025-02-09)
|
|
2
12
|
|
|
3
13
|
|
|
@@ -56,7 +56,7 @@ DEFAULT_VALIDITY_MINUTES = 0 # Minutos a partir de los cuales la API tiene la i
|
|
|
56
56
|
DEFAULT_ALERT_VALIDITY_TIME = 120 # Minutos a partir de los cuales las alertas están obsoletas y se se debe proceder a una nueva llamada a la API
|
|
57
57
|
DEFAULT_QUOTES_VALIDITY_TIME = 240 # Minutos a partir de los cuales los datos de cuotas están obsoletos y se se debe proceder a una nueva llamada a la API
|
|
58
58
|
DEFAULT_LIGHTNING_VALIDITY_TIME = 240 # Minutos a partir de los cuales los datos de rayos están obsoletos y se se debe proceder a una nueva llamada a la API
|
|
59
|
-
DEFAULT_LIGHTNING_VALIDITY_HOURS =
|
|
59
|
+
DEFAULT_LIGHTNING_VALIDITY_HOURS = 1 # Hora a partir de la cual la API tiene la información actualizada de rayos disponible para descarga
|
|
60
60
|
DEFAULT_LIGHTNING_VALIDITY_MINUTES = 0 # Minutos a partir de los cuales la API tiene la información actualizada de rayos disponible para descarga
|
|
61
61
|
|
|
62
62
|
# Multiplicadores para la duración de validez basada en limit_prediccio
|
|
@@ -1334,7 +1334,7 @@ class MeteocatAlertsCoordinator(DataUpdateCoordinator):
|
|
|
1334
1334
|
"Usando datos en caché para las alertas. Última actualización: %s",
|
|
1335
1335
|
cached_data["actualitzat"]["dataUpdate"],
|
|
1336
1336
|
)
|
|
1337
|
-
return cached_data
|
|
1337
|
+
return {"actualizado": cached_data['actualitzat']['dataUpdate']}
|
|
1338
1338
|
|
|
1339
1339
|
# Si no se puede actualizar ni cargar datos en caché, retornar None
|
|
1340
1340
|
_LOGGER.error("No se pudo obtener datos actualizados ni cargar datos en caché de alertas.")
|
|
@@ -1783,7 +1783,7 @@ class MeteocatQuotesCoordinator(DataUpdateCoordinator):
|
|
|
1783
1783
|
cached_data = await load_json_from_file(self.quotes_file)
|
|
1784
1784
|
if cached_data:
|
|
1785
1785
|
_LOGGER.warning("Usando datos en caché para las cuotas de la API de Meteocat.")
|
|
1786
|
-
return cached_data
|
|
1786
|
+
return {"actualizado": cached_data['actualitzat']['dataUpdate']}
|
|
1787
1787
|
|
|
1788
1788
|
_LOGGER.error("No se pudo obtener datos actualizados ni cargar datos en caché.")
|
|
1789
1789
|
return None
|
|
@@ -1910,15 +1910,19 @@ class MeteocatLightningCoordinator(DataUpdateCoordinator):
|
|
|
1910
1910
|
existing_data = await load_json_from_file(self.lightning_file) or {}
|
|
1911
1911
|
|
|
1912
1912
|
# Definir la duración de validez de los datos
|
|
1913
|
-
|
|
1914
|
-
|
|
1913
|
+
now = datetime.now(timezone.utc).astimezone(TIMEZONE)
|
|
1914
|
+
current_time = now.time() # Extraer solo la parte de la hora
|
|
1915
|
+
offset = now.utcoffset().total_seconds() / 3600 # Obtener el offset en horas
|
|
1916
|
+
|
|
1917
|
+
# Determinar la hora de validez considerando el offset horario, el horario de verano (+02:00) o invierno (+01:00)
|
|
1918
|
+
validity_start_time = time(int(DEFAULT_LIGHTNING_VALIDITY_HOURS + offset), DEFAULT_LIGHTNING_VALIDITY_MINUTES)
|
|
1919
|
+
|
|
1915
1920
|
validity_duration = timedelta(minutes=DEFAULT_LIGHTNING_VALIDITY_TIME)
|
|
1916
1921
|
|
|
1917
1922
|
if not existing_data:
|
|
1918
1923
|
return await self._fetch_and_save_new_data()
|
|
1919
1924
|
else:
|
|
1920
1925
|
last_update = datetime.fromisoformat(existing_data['actualitzat']['dataUpdate'])
|
|
1921
|
-
now = datetime.now(timezone.utc).astimezone(TIMEZONE)
|
|
1922
1926
|
|
|
1923
1927
|
if now - last_update >= validity_duration and current_time >= validity_start_time:
|
|
1924
1928
|
return await self._fetch_and_save_new_data()
|
|
@@ -1967,7 +1971,7 @@ class MeteocatLightningCoordinator(DataUpdateCoordinator):
|
|
|
1967
1971
|
cached_data = await load_json_from_file(self.lightning_file)
|
|
1968
1972
|
if cached_data:
|
|
1969
1973
|
_LOGGER.warning("Usando datos en caché para los datos de rayos de la API de Meteocat.")
|
|
1970
|
-
return cached_data
|
|
1974
|
+
return {"actualizado": cached_data['actualitzat']['dataUpdate']}
|
|
1971
1975
|
|
|
1972
1976
|
_LOGGER.error("No se pudo obtener datos actualizados ni cargar datos en caché.")
|
|
1973
1977
|
return None
|
|
@@ -2012,20 +2016,20 @@ class MeteocatLightningFileCoordinator(DataUpdateCoordinator):
|
|
|
2012
2016
|
if not existing_data:
|
|
2013
2017
|
_LOGGER.warning("No se encontraron datos en %s.", self.lightning_file)
|
|
2014
2018
|
return {
|
|
2015
|
-
"actualizado": datetime.now(
|
|
2019
|
+
"actualizado": datetime.now(TIMEZONE).isoformat(),
|
|
2016
2020
|
"region": self._reset_data(),
|
|
2017
2021
|
"town": self._reset_data()
|
|
2018
2022
|
}
|
|
2019
2023
|
|
|
2020
2024
|
# Convertir la cadena de fecha a un objeto datetime y ajustar a la zona horaria local
|
|
2021
2025
|
update_date = datetime.fromisoformat(existing_data.get("actualitzat", {}).get("dataUpdate", ""))
|
|
2022
|
-
update_date = update_date.astimezone(
|
|
2023
|
-
now = datetime.now(
|
|
2026
|
+
update_date = update_date.astimezone(TIMEZONE)
|
|
2027
|
+
now = datetime.now(TIMEZONE)
|
|
2024
2028
|
|
|
2025
2029
|
if update_date.date() != now.date(): # Si la fecha no es la de hoy
|
|
2026
2030
|
_LOGGER.info("Los datos de rayos son de un día diferente. Reiniciando valores a cero.")
|
|
2027
2031
|
region_data = town_data = self._reset_data()
|
|
2028
|
-
update_date = datetime.now(
|
|
2032
|
+
update_date = datetime.now(TIMEZONE).isoformat() # Usar la fecha actual
|
|
2029
2033
|
else:
|
|
2030
2034
|
region_data = self._process_region_data(existing_data.get("dades", []))
|
|
2031
2035
|
town_data = self._process_town_data(existing_data.get("dades", []))
|
|
@@ -103,6 +103,8 @@ from .const import (
|
|
|
103
103
|
ALERT_VALIDITY_MULTIPLIER_500,
|
|
104
104
|
ALERT_VALIDITY_MULTIPLIER_DEFAULT,
|
|
105
105
|
DEFAULT_LIGHTNING_VALIDITY_TIME,
|
|
106
|
+
DEFAULT_LIGHTNING_VALIDITY_HOURS,
|
|
107
|
+
DEFAULT_LIGHTNING_VALIDITY_MINUTES,
|
|
106
108
|
)
|
|
107
109
|
|
|
108
110
|
from .coordinator import (
|
|
@@ -1687,29 +1689,40 @@ class MeteocatLightningStatusSensor(CoordinatorEntity[MeteocatLightningCoordinat
|
|
|
1687
1689
|
self._attr_entity_category = getattr(description, "entity_category", None)
|
|
1688
1690
|
|
|
1689
1691
|
def _get_data_update(self):
|
|
1690
|
-
"""Obtiene la fecha de actualización directamente desde el coordinador."""
|
|
1692
|
+
"""Obtiene la fecha de actualización directamente desde el coordinador y la convierte a UTC."""
|
|
1691
1693
|
data_update = self.coordinator.data.get("actualizado")
|
|
1692
1694
|
if data_update:
|
|
1693
1695
|
try:
|
|
1694
|
-
|
|
1696
|
+
local_time = datetime.fromisoformat(data_update) # Ya tiene offset (+01:00 o +02:00)
|
|
1697
|
+
return local_time.astimezone(ZoneInfo("UTC")) # Convertir a UTC
|
|
1695
1698
|
except ValueError:
|
|
1696
1699
|
_LOGGER.error("Formato de fecha de actualización inválido: %s", data_update)
|
|
1697
1700
|
return None
|
|
1701
|
+
|
|
1702
|
+
def _determine_status(self, now, data_update, current_time, validity_start_time, validity_duration):
|
|
1703
|
+
"""Determina el estado basado en la fecha de actualización."""
|
|
1704
|
+
if now - data_update > timedelta(days=1):
|
|
1705
|
+
return "obsolete"
|
|
1706
|
+
elif now - data_update < validity_duration or current_time < validity_start_time:
|
|
1707
|
+
return "updated"
|
|
1708
|
+
return "obsolete"
|
|
1698
1709
|
|
|
1699
1710
|
@property
|
|
1700
1711
|
def native_value(self):
|
|
1701
|
-
"""Devuelve el estado
|
|
1712
|
+
"""Devuelve el estado del archivo de rayos basado en la fecha de actualización."""
|
|
1702
1713
|
data_update = self._get_data_update()
|
|
1703
1714
|
if not data_update:
|
|
1704
1715
|
return "unknown"
|
|
1705
1716
|
|
|
1706
|
-
|
|
1717
|
+
now = datetime.now(timezone.utc).astimezone(TIMEZONE)
|
|
1718
|
+
current_time = now.time() # Extraer solo la parte de la hora
|
|
1719
|
+
offset = now.utcoffset().total_seconds() / 3600 # Obtener el offset en horas
|
|
1707
1720
|
|
|
1708
|
-
#
|
|
1709
|
-
|
|
1710
|
-
|
|
1721
|
+
# Determinar la hora de validez considerando el offset horario, el horario de verano (+02:00) o invierno (+01:00)
|
|
1722
|
+
validity_start_time = time(int(DEFAULT_LIGHTNING_VALIDITY_HOURS + offset), DEFAULT_LIGHTNING_VALIDITY_MINUTES)
|
|
1723
|
+
validity_duration = timedelta(minutes=DEFAULT_LIGHTNING_VALIDITY_TIME)
|
|
1711
1724
|
|
|
1712
|
-
return
|
|
1725
|
+
return self._determine_status(now, data_update, current_time, validity_start_time, validity_duration)
|
|
1713
1726
|
|
|
1714
1727
|
@property
|
|
1715
1728
|
def extra_state_attributes(self):
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
# version.py
|
|
2
|
-
__version__ = "2.2.
|
|
2
|
+
__version__ = "2.2.5"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meteocat",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "[](https://opensource.org/licenses/Apache-2.0)\r [](https://pypi.org/project/meteocat)\r [](https://gitlab.com/figorr/meteocat/commits/master)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|