meteocat 0.1.33 → 0.1.35

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,22 @@
1
+ ## [0.1.35](https://github.com/figorr/meteocat/compare/v0.1.34...v0.1.35) (2024-12-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 0.1.35 ([87adbc5](https://github.com/figorr/meteocat/commit/87adbc5c76941af1ff837f63920ca65164df38c2))
7
+ * fix station data json name ([2c411bd](https://github.com/figorr/meteocat/commit/2c411bd5d040d8c50bd00dae3c4b7858c049e522))
8
+
9
+ ## [0.1.34](https://github.com/figorr/meteocat/compare/v0.1.33...v0.1.34) (2024-12-14)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * 0.1.34 ([14c1437](https://github.com/figorr/meteocat/commit/14c1437a95fd41a014146fd63ce80892a2d4a284))
15
+ * fix data validation ([a2c4282](https://github.com/figorr/meteocat/commit/a2c428207b062a06c5c07377ab3bf8ffbc65d277))
16
+ * fix Feels Like round(1) ([6329807](https://github.com/figorr/meteocat/commit/63298077e5aa09cb61413b0578ccd7e4baeb5c51))
17
+ * remove data validation ([250e582](https://github.com/figorr/meteocat/commit/250e5825dbda556e3e8e0c2e4a8014993e1de705))
18
+ * set timeout and data validation ([b7dba2e](https://github.com/figorr/meteocat/commit/b7dba2e9e742bee04c8e16d3694c7ac647ec83ab))
19
+
1
20
  ## [0.1.33](https://github.com/figorr/meteocat/compare/v0.1.32...v0.1.33) (2024-12-14)
2
21
 
3
22
 
@@ -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.35"
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."""
@@ -96,13 +96,23 @@ async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
96
96
  """Limpia cualquier dato adicional al desinstalar la integración."""
97
97
  _LOGGER.info(f"Eliminando datos residuales de la integración: {entry.entry_id}")
98
98
 
99
- # Definir las rutas de los archivos y carpetas a eliminar
99
+ # Definir las rutas base a eliminar
100
100
  custom_components_path = Path(hass.config.path("custom_components")) / DOMAIN
101
101
  assets_folder = custom_components_path / "assets"
102
102
  files_folder = custom_components_path / "files"
103
+
104
+ # Definir archivos relacionados a eliminar
103
105
  symbols_file = assets_folder / "symbols.json"
104
106
  variables_file = assets_folder / "variables.json"
105
- station_data_file = files_folder / "station_data.json"
107
+
108
+ # Obtener el `station_id` para identificar el archivo a eliminar
109
+ station_id = entry.data.get("station_id")
110
+ if not station_id:
111
+ _LOGGER.warning("No se encontró 'station_id' en la configuración. No se puede eliminar el archivo de datos de la estación.")
112
+ return
113
+
114
+ # Archivo JSON de la estación
115
+ station_data_file = files_folder / f"station_{station_id.lower()}_data.json"
106
116
 
107
117
  # Validar la ruta base
108
118
  if not custom_components_path.exists():
@@ -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,19 +78,38 @@ 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
- self.hass.config.path(), "custom_components", "meteocat", "files", "station_data.json"
99
+ self.hass.config.path(),
100
+ "custom_components",
101
+ "meteocat",
102
+ "files",
103
+ f"station_{self.station_id.lower()}_data.json"
87
104
  )
88
105
 
89
106
  # Guardar los datos en un archivo JSON
90
107
  await save_json_to_file(data, output_file)
91
108
 
92
109
  return data
110
+ except asyncio.TimeoutError as err:
111
+ _LOGGER.warning("Tiempo de espera agotado al obtener datos de la API de Meteocat.")
112
+ raise ConfigEntryNotReady from err
93
113
  except ForbiddenError as err:
94
114
  _LOGGER.error(
95
115
  "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.35"
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.35"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meteocat",
3
- "version": "0.1.33",
3
+ "version": "0.1.35",
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.35"
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"