meteocat 0.1.45 → 0.1.46
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 +8 -0
- package/custom_components/meteocat/__init__.py +1 -1
- package/custom_components/meteocat/const.py +4 -0
- package/custom_components/meteocat/coordinator.py +10 -3
- package/custom_components/meteocat/manifest.json +1 -1
- package/custom_components/meteocat/sensor.py +46 -7
- 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,11 @@
|
|
|
1
|
+
## [0.1.46](https://github.com/figorr/meteocat/compare/v0.1.45...v0.1.46) (2025-01-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* 0.1.46 ([e2e736e](https://github.com/figorr/meteocat/commit/e2e736e102f25da704060bc6329696eec8c8fac6))
|
|
7
|
+
* add validity days, hours and minutes ([61a6761](https://github.com/figorr/meteocat/commit/61a6761cde31c321dbed4dce126416f65062a90f))
|
|
8
|
+
|
|
1
9
|
## [0.1.45](https://github.com/figorr/meteocat/compare/v0.1.44...v0.1.45) (2024-12-31)
|
|
2
10
|
|
|
3
11
|
|
|
@@ -25,7 +25,7 @@ from .const import DOMAIN, PLATFORMS
|
|
|
25
25
|
_LOGGER = logging.getLogger(__name__)
|
|
26
26
|
|
|
27
27
|
# Versión
|
|
28
|
-
__version__ = "0.1.
|
|
28
|
+
__version__ = "0.1.46"
|
|
29
29
|
|
|
30
30
|
def safe_remove(path: Path, is_folder: bool = False):
|
|
31
31
|
"""Elimina de forma segura un archivo o carpeta si existe."""
|
|
@@ -27,6 +27,10 @@ ATTRIBUTION = "Powered by Meteocatpy"
|
|
|
27
27
|
PLATFORMS = [Platform.SENSOR, Platform.WEATHER]
|
|
28
28
|
DEFAULT_NAME = "METEOCAT"
|
|
29
29
|
|
|
30
|
+
# Tiempos para validación de API
|
|
31
|
+
DEFAULT_VALIDITY_DAYS = 1 # Número de días a partir de los cuales se considera que el archivo de información está obsoleto
|
|
32
|
+
DEFAULT_VALIDITY_HOURS = 5 # Hora a partir de la cuall la API tiene la información actualizada de predicciones disponible para descarga
|
|
33
|
+
DEFAULT_VALIDITY_MINUTES = 0 # Minutos a partir de los cuales la API tiene la información actualizada de predicciones disponible para descarga
|
|
30
34
|
|
|
31
35
|
# Códigos de sensores de la API
|
|
32
36
|
WIND_SPEED = "wind_speed" # Velocidad del viento
|
|
@@ -5,7 +5,7 @@ import json
|
|
|
5
5
|
import aiofiles
|
|
6
6
|
import logging
|
|
7
7
|
import asyncio
|
|
8
|
-
from datetime import datetime, timedelta, timezone
|
|
8
|
+
from datetime import datetime, timedelta, timezone, time
|
|
9
9
|
from typing import Dict, Any
|
|
10
10
|
|
|
11
11
|
from homeassistant.core import HomeAssistant
|
|
@@ -29,6 +29,9 @@ from .condition import get_condition_from_statcel
|
|
|
29
29
|
from .const import (
|
|
30
30
|
DOMAIN,
|
|
31
31
|
CONDITION_MAPPING,
|
|
32
|
+
DEFAULT_VALIDITY_DAYS,
|
|
33
|
+
DEFAULT_VALIDITY_HOURS,
|
|
34
|
+
DEFAULT_VALIDITY_MINUTES,
|
|
32
35
|
)
|
|
33
36
|
|
|
34
37
|
_LOGGER = logging.getLogger(__name__)
|
|
@@ -285,6 +288,7 @@ class MeteocatUviCoordinator(DataUpdateCoordinator):
|
|
|
285
288
|
# Validar la fecha del primer elemento superior a 1 día
|
|
286
289
|
first_date = datetime.strptime(data["uvi"][0].get("date"), "%Y-%m-%d").date()
|
|
287
290
|
today = datetime.now(timezone.utc).date()
|
|
291
|
+
current_time = datetime.now(timezone.utc).time()
|
|
288
292
|
|
|
289
293
|
# Log detallado
|
|
290
294
|
_LOGGER.info(
|
|
@@ -292,10 +296,11 @@ class MeteocatUviCoordinator(DataUpdateCoordinator):
|
|
|
292
296
|
self.uvi_file,
|
|
293
297
|
today,
|
|
294
298
|
first_date,
|
|
299
|
+
current_time,
|
|
295
300
|
)
|
|
296
301
|
|
|
297
302
|
# Verificar si la antigüedad es mayor a un día
|
|
298
|
-
if (today - first_date).days >
|
|
303
|
+
if (today - first_date).days > DEFAULT_VALIDITY_DAYS and current_time >= time(DEFAULT_VALIDITY_HOURS, DEFAULT_VALIDITY_MINUTES):
|
|
299
304
|
_LOGGER.info(
|
|
300
305
|
"Los datos en %s son antiguos. Se procederá a llamar a la API.",
|
|
301
306
|
self.uvi_file,
|
|
@@ -508,6 +513,7 @@ class MeteocatEntityCoordinator(DataUpdateCoordinator):
|
|
|
508
513
|
# Obtener la fecha del primer día
|
|
509
514
|
first_date = datetime.fromisoformat(data["dies"][0]["data"].rstrip("Z")).date()
|
|
510
515
|
today = datetime.now(timezone.utc).date()
|
|
516
|
+
current_time = datetime.now(timezone.utc).time()
|
|
511
517
|
|
|
512
518
|
# Log detallado
|
|
513
519
|
_LOGGER.info(
|
|
@@ -515,10 +521,11 @@ class MeteocatEntityCoordinator(DataUpdateCoordinator):
|
|
|
515
521
|
file_path,
|
|
516
522
|
today,
|
|
517
523
|
first_date,
|
|
524
|
+
current_time,
|
|
518
525
|
)
|
|
519
526
|
|
|
520
527
|
# Verificar si la antigüedad es mayor a un día
|
|
521
|
-
if (today - first_date).days >
|
|
528
|
+
if (today - first_date).days > DEFAULT_VALIDITY_DAYS and current_time >= time(DEFAULT_VALIDITY_HOURS, DEFAULT_VALIDITY_MINUTES):
|
|
522
529
|
_LOGGER.info(
|
|
523
530
|
"Los datos en %s son antiguos. Se procederá a llamar a la API.",
|
|
524
531
|
file_path,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass
|
|
4
|
-
from datetime import datetime, timezone
|
|
4
|
+
from datetime import datetime, timezone, time
|
|
5
5
|
import logging
|
|
6
6
|
from homeassistant.helpers.entity import (
|
|
7
7
|
DeviceInfo,
|
|
@@ -63,6 +63,9 @@ from .const import (
|
|
|
63
63
|
MIN_TEMPERATURE_CODE,
|
|
64
64
|
FEELS_LIKE,
|
|
65
65
|
WIND_GUST_CODE,
|
|
66
|
+
DEFAULT_VALIDITY_DAYS,
|
|
67
|
+
DEFAULT_VALIDITY_HOURS,
|
|
68
|
+
DEFAULT_VALIDITY_MINUTES,
|
|
66
69
|
)
|
|
67
70
|
|
|
68
71
|
from .coordinator import (
|
|
@@ -793,9 +796,21 @@ class MeteocatHourlyForecastStatusSensor(CoordinatorEntity[MeteocatEntityCoordin
|
|
|
793
796
|
first_date = self._get_first_date()
|
|
794
797
|
if first_date:
|
|
795
798
|
today = datetime.now(timezone.utc).date()
|
|
799
|
+
current_time = datetime.now(timezone.utc).time()
|
|
796
800
|
days_difference = (today - first_date).days
|
|
797
|
-
_LOGGER.debug(
|
|
798
|
-
|
|
801
|
+
_LOGGER.debug(
|
|
802
|
+
f"Diferencia de días para predicciones horarias: {days_difference}."
|
|
803
|
+
f"Hora actual de validación: {current_time}."
|
|
804
|
+
f"Para la validación: "
|
|
805
|
+
f"número de días= {DEFAULT_VALIDITY_DAYS}, "
|
|
806
|
+
f"hora de contacto a la API >= {DEFAULT_VALIDITY_HOURS}, "
|
|
807
|
+
f"minutos de contacto a la API >= {DEFAULT_VALIDITY_MINUTES}."
|
|
808
|
+
)
|
|
809
|
+
|
|
810
|
+
# Validar fecha y hora según la lógica del coordinador
|
|
811
|
+
if days_difference > DEFAULT_VALIDITY_DAYS and current_time >= time(DEFAULT_VALIDITY_HOURS, DEFAULT_VALIDITY_MINUTES):
|
|
812
|
+
return "obsolete"
|
|
813
|
+
return "updated"
|
|
799
814
|
return "unknown"
|
|
800
815
|
|
|
801
816
|
@property
|
|
@@ -844,9 +859,21 @@ class MeteocatDailyForecastStatusSensor(CoordinatorEntity[MeteocatEntityCoordina
|
|
|
844
859
|
first_date = self._get_first_date()
|
|
845
860
|
if first_date:
|
|
846
861
|
today = datetime.now(timezone.utc).date()
|
|
862
|
+
current_time = datetime.now(timezone.utc).time()
|
|
847
863
|
days_difference = (today - first_date).days
|
|
848
|
-
_LOGGER.debug(
|
|
849
|
-
|
|
864
|
+
_LOGGER.debug(
|
|
865
|
+
f"Diferencia de días para predicciones diarias: {days_difference}."
|
|
866
|
+
f"Hora actual de validación: {current_time}."
|
|
867
|
+
f"Para la validación: "
|
|
868
|
+
f"número de días= {DEFAULT_VALIDITY_DAYS}, "
|
|
869
|
+
f"hora de contacto a la API >= {DEFAULT_VALIDITY_HOURS}, "
|
|
870
|
+
f"minutos de contacto a la API >= {DEFAULT_VALIDITY_MINUTES}."
|
|
871
|
+
)
|
|
872
|
+
|
|
873
|
+
# Validar fecha y hora según la lógica del coordinador
|
|
874
|
+
if days_difference > DEFAULT_VALIDITY_DAYS and current_time >= time(DEFAULT_VALIDITY_HOURS, DEFAULT_VALIDITY_MINUTES):
|
|
875
|
+
return "obsolete"
|
|
876
|
+
return "updated"
|
|
850
877
|
return "unknown"
|
|
851
878
|
|
|
852
879
|
@property
|
|
@@ -894,9 +921,21 @@ class MeteocatUviStatusSensor(CoordinatorEntity[MeteocatUviCoordinator], SensorE
|
|
|
894
921
|
first_date = self._get_first_date()
|
|
895
922
|
if first_date:
|
|
896
923
|
today = datetime.now(timezone.utc).date()
|
|
924
|
+
current_time = datetime.now(timezone.utc).time()
|
|
897
925
|
days_difference = (today - first_date).days
|
|
898
|
-
_LOGGER.debug(
|
|
899
|
-
|
|
926
|
+
_LOGGER.debug(
|
|
927
|
+
f"Diferencia de días para datos UVI: {days_difference}."
|
|
928
|
+
f"Hora actual de validación: {current_time}."
|
|
929
|
+
f"Para la validación: "
|
|
930
|
+
f"número de días= {DEFAULT_VALIDITY_DAYS}, "
|
|
931
|
+
f"hora de contacto a la API >= {DEFAULT_VALIDITY_HOURS}, "
|
|
932
|
+
f"minutos de contacto a la API >= {DEFAULT_VALIDITY_MINUTES}."
|
|
933
|
+
)
|
|
934
|
+
|
|
935
|
+
# Validar fecha y hora según la lógica del coordinador
|
|
936
|
+
if days_difference > DEFAULT_VALIDITY_DAYS and current_time >= time(DEFAULT_VALIDITY_HOURS, DEFAULT_VALIDITY_MINUTES):
|
|
937
|
+
return "obsolete"
|
|
938
|
+
return "updated"
|
|
900
939
|
return "unknown"
|
|
901
940
|
|
|
902
941
|
@property
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
# version.py
|
|
2
|
-
__version__ = "0.1.
|
|
2
|
+
__version__ = "0.1.46"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meteocat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
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": {
|