meteocat 0.1.33 → 0.1.34

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 CHANGED
@@ -1,3 +1,14 @@
1
+ ## [0.1.34](https://github.com/figorr/meteocat/compare/v0.1.33...v0.1.34) (2024-12-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 0.1.34 ([14c1437](https://github.com/figorr/meteocat/commit/14c1437a95fd41a014146fd63ce80892a2d4a284))
7
+ * fix data validation ([a2c4282](https://github.com/figorr/meteocat/commit/a2c428207b062a06c5c07377ab3bf8ffbc65d277))
8
+ * fix Feels Like round(1) ([6329807](https://github.com/figorr/meteocat/commit/63298077e5aa09cb61413b0578ccd7e4baeb5c51))
9
+ * remove data validation ([250e582](https://github.com/figorr/meteocat/commit/250e5825dbda556e3e8e0c2e4a8014993e1de705))
10
+ * set timeout and data validation ([b7dba2e](https://github.com/figorr/meteocat/commit/b7dba2e9e742bee04c8e16d3694c7ac647ec83ab))
11
+
1
12
  ## [0.1.33](https://github.com/figorr/meteocat/compare/v0.1.32...v0.1.33) (2024-12-14)
2
13
 
3
14
 
@@ -14,7 +14,7 @@ from .const import DOMAIN, PLATFORMS
14
14
  _LOGGER = logging.getLogger(__name__)
15
15
 
16
16
  # Versión
17
- __version__ = "0.1.33"
17
+ __version__ = "0.1.34"
18
18
 
19
19
  def safe_remove(path: Path, is_folder: bool = False):
20
20
  """Elimina de forma segura un archivo o carpeta si existe."""
@@ -4,8 +4,9 @@ import os
4
4
  import json
5
5
  import aiofiles
6
6
  import logging
7
+ import asyncio
7
8
  from datetime import timedelta
8
- from typing import Dict
9
+ from typing import Dict, Any
9
10
 
10
11
  from homeassistant.core import HomeAssistant
11
12
  from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
@@ -77,10 +78,22 @@ class MeteocatSensorCoordinator(DataUpdateCoordinator):
77
78
  async def _async_update_data(self) -> Dict:
78
79
  """Actualiza los datos de los sensores desde la API de Meteocat."""
79
80
  try:
80
- # Obtener datos desde la API
81
- data = await self.meteocat_station_data.get_station_data(self.station_id)
81
+ # Obtener datos desde la API con manejo de tiempo límite
82
+ data = await asyncio.wait_for(
83
+ self.meteocat_station_data.get_station_data(self.station_id),
84
+ timeout=30 # Tiempo límite de 30 segundos
85
+ )
82
86
  _LOGGER.debug("Datos de sensores actualizados exitosamente: %s", data)
83
87
 
88
+ # Validar que los datos sean una lista de diccionarios
89
+ if not isinstance(data, list) or not all(isinstance(item, dict) for item in data):
90
+ _LOGGER.error(
91
+ "Formato inválido: Se esperaba una lista de dicts, pero se obtuvo %s. Datos: %s",
92
+ type(data).__name__,
93
+ data,
94
+ )
95
+ raise ValueError("Formato de datos inválido")
96
+
84
97
  # Determinar la ruta al archivo en la carpeta raíz del repositorio
85
98
  output_file = os.path.join(
86
99
  self.hass.config.path(), "custom_components", "meteocat", "files", "station_data.json"
@@ -90,6 +103,9 @@ class MeteocatSensorCoordinator(DataUpdateCoordinator):
90
103
  await save_json_to_file(data, output_file)
91
104
 
92
105
  return data
106
+ except asyncio.TimeoutError as err:
107
+ _LOGGER.warning("Tiempo de espera agotado al obtener datos de la API de Meteocat.")
108
+ raise ConfigEntryNotReady from err
93
109
  except ForbiddenError as err:
94
110
  _LOGGER.error(
95
111
  "Acceso denegado al obtener datos de sensores (Station ID: %s): %s",
@@ -8,5 +8,5 @@
8
8
  "documentation": "https://gitlab.com/figorr/meteocat",
9
9
  "loggers": ["meteocatpy"],
10
10
  "requirements": ["meteocatpy==0.0.15", "packaging>=20.3", "wrapt>=1.14.0"],
11
- "version": "0.1.33"
11
+ "version": "0.1.34"
12
12
  }
@@ -323,13 +323,13 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
323
323
  # Lógica de selección
324
324
  if -50 <= temperature <= 10 and wind_speed > 4.8:
325
325
  _LOGGER.debug(f"Sensación térmica por frío, calculada según la fórmula de Wind Chill: {windchill} ºC")
326
- return round(windchill, 2)
326
+ return round(windchill, 1)
327
327
  elif temperature > 26 and humidity > 40:
328
328
  _LOGGER.debug(f"Sensación térmica por calor, calculada según la fórmula de Heat Index: {heat_index} ºC")
329
- return round(heat_index, 2)
329
+ return round(heat_index, 1)
330
330
  else:
331
331
  _LOGGER.debug(f"Sensación térmica idéntica a la temperatura actual: {temperature} ºC")
332
- return round(temperature, 2)
332
+ return round(temperature, 1)
333
333
 
334
334
  sensor_code = self.CODE_MAPPING.get(self.entity_description.key)
335
335
 
@@ -1,2 +1,2 @@
1
1
  # version.py
2
- __version__ = "0.1.33"
2
+ __version__ = "0.1.34"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meteocat",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "description": "[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\r [![Python version compatibility](https://img.shields.io/pypi/pyversions/meteocat)](https://pypi.org/project/meteocat)\r [![pipeline status](https://gitlab.com/figorr/meteocat/badges/master/pipeline.svg)](https://gitlab.com/figorr/meteocat/commits/master)",
5
5
  "main": "index.js",
6
6
  "directories": {
package/pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "meteocat"
3
- version = "0.1.33"
3
+ version = "0.1.34"
4
4
  description = "Script para obtener datos meteorológicos de la API de Meteocat"
5
5
  authors = ["figorr <jdcuartero@yahoo.es>"]
6
6
  license = "Apache-2.0"