meteocat 0.1.28 → 0.1.29

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,13 @@
1
+ ## [0.1.29](https://github.com/figorr/meteocat/compare/v0.1.28...v0.1.29) (2024-12-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 0.1.29 ([f80cb9e](https://github.com/figorr/meteocat/commit/f80cb9eda9bd7d731489b51c161bc16a00ac57f0))
7
+ * bump meteocatpy to 0.0.14 ([74cc591](https://github.com/figorr/meteocat/commit/74cc591ac7e9911c77649a20088af15d3af2d350))
8
+ * remove cache ([8c4f29b](https://github.com/figorr/meteocat/commit/8c4f29b0b2c2cfa33f2b45f72bed57bf45b9a3dd))
9
+ * remove cache tests ([6082096](https://github.com/figorr/meteocat/commit/6082096a92ade5a033e0493a819b20e950aff7a3))
10
+
1
11
  ## [0.1.28](https://github.com/figorr/meteocat/compare/v0.1.27...v0.1.28) (2024-12-11)
2
12
 
3
13
 
@@ -8,13 +8,13 @@ from homeassistant.core import HomeAssistant
8
8
  from homeassistant.exceptions import HomeAssistantError
9
9
  from homeassistant.helpers.entity_platform import async_get_platforms
10
10
 
11
- from .coordinator import MeteocatSensorCoordinator #, MeteocatEntityCoordinator
11
+ from .coordinator import MeteocatSensorCoordinator # , MeteocatEntityCoordinator
12
12
  from .const import DOMAIN, PLATFORMS
13
13
 
14
14
  _LOGGER = logging.getLogger(__name__)
15
15
 
16
16
  # Versión
17
- __version__ = "0.1.28"
17
+ __version__ = "0.1.29"
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."""
@@ -28,12 +28,10 @@ def safe_remove(path: Path, is_folder: bool = False):
28
28
  except OSError as e:
29
29
  _LOGGER.error(f"Error al intentar eliminar {path.name}: {e}")
30
30
 
31
-
32
31
  async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
33
32
  """Configuración inicial del componente Meteocat."""
34
33
  return True
35
34
 
36
-
37
35
  async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
38
36
  """Configura una entrada de configuración para Meteocat."""
39
37
  _LOGGER.info("Configurando la integración de Meteocat...")
@@ -57,11 +55,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
57
55
  f"Estación '{entry_data['station_name']}' (ID: {entry_data['station_id']})."
58
56
  )
59
57
 
60
- # Configurar ruta de la caché
61
- cache_dir = Path(hass.config.path("custom_components", DOMAIN, ".meteocat_cache"))
62
- cache_dir.mkdir(parents=True, exist_ok=True)
63
- _LOGGER.debug(f"Directorio de caché configurado en: {cache_dir}")
64
-
65
58
  # Inicializar coordinadores
66
59
  try:
67
60
  sensor_coordinator = MeteocatSensorCoordinator(hass=hass, entry_data=entry_data)
@@ -87,7 +80,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
87
80
 
88
81
  return True
89
82
 
90
-
91
83
  async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
92
84
  """Desactiva una entrada de configuración para Meteocat."""
93
85
  platforms = async_get_platforms(hass, DOMAIN)
@@ -100,7 +92,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
100
92
 
101
93
  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
102
94
 
103
-
104
95
  async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
105
96
  """Limpia cualquier dato adicional al desinstalar la integración."""
106
97
  _LOGGER.info(f"Eliminando datos residuales de la integración: {entry.entry_id}")
@@ -109,7 +100,6 @@ async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
109
100
  custom_components_path = Path(hass.config.path("custom_components")) / DOMAIN
110
101
  assets_folder = custom_components_path / "assets"
111
102
  files_folder = custom_components_path / "files"
112
- cache_folder = custom_components_path / ".meteocat_cache"
113
103
  symbols_file = assets_folder / "symbols.json"
114
104
  variables_file = assets_folder / "variables.json"
115
105
  station_data_file = files_folder / "station_data.json"
@@ -125,4 +115,3 @@ async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
125
115
  safe_remove(station_data_file)
126
116
  safe_remove(assets_folder, is_folder=True)
127
117
  safe_remove(files_folder, is_folder=True)
128
- safe_remove(cache_folder, is_folder=True)
@@ -47,6 +47,7 @@ class MeteocatConfigFlow(ConfigFlow, domain=DOMAIN):
47
47
  self.variable_id: str | None = None
48
48
  self.station_id: str | None = None
49
49
  self.station_name: str | None = None
50
+ self._cache = {}
50
51
 
51
52
  async def async_step_user(
52
53
  self, user_input: dict[str, Any] | None = None
@@ -97,46 +98,57 @@ class MeteocatConfigFlow(ConfigFlow, domain=DOMAIN):
97
98
  return self.async_show_form(step_id="select_municipi", data_schema=schema, errors=errors)
98
99
 
99
100
  async def fetch_symbols_and_variables(self):
100
- """Descarga los símbolos y las variables después de seleccionar el municipio."""
101
+ """Descarga y guarda los símbolos y variables después de seleccionar el municipio."""
101
102
 
102
103
  errors = {}
103
104
 
104
- # Descargar y guardar los símbolos
105
+ # Crear directorio de activos (assets) si no existe
105
106
  assets_dir = Path(__file__).parent / "assets"
106
107
  assets_dir.mkdir(parents=True, exist_ok=True)
107
108
  symbols_file = assets_dir / "symbols.json"
108
109
  variables_file = assets_dir / "variables.json"
109
- symbols_client = MeteocatSymbols(self.api_key)
110
110
 
111
111
  try:
112
+ # Descargar y guardar los símbolos
113
+ symbols_client = MeteocatSymbols(self.api_key)
112
114
  symbols_data = await symbols_client.fetch_symbols()
115
+
113
116
  async with aiofiles.open(symbols_file, "w", encoding="utf-8") as file:
114
117
  await file.write(json.dumps({"symbols": symbols_data}, ensure_ascii=False, indent=4))
115
- except (BadRequestError, ForbiddenError, TooManyRequestsError, InternalServerError, UnknownAPIError) as ex:
116
- _LOGGER.error("Error al descargar o guardar los símbolos: %s", ex)
117
- errors["base"] = "symbols_download_failed"
118
+
119
+ _LOGGER.info(f"Símbolos guardados en {symbols_file}")
118
120
 
119
- if not errors:
120
- # Configurar la ruta para la caché en la carpeta `custom_components/meteocat`
121
- cache_dir = os.path.join(os.path.dirname(__file__), ".meteocat_cache")
121
+ # Descargar y guardar las variables
122
+ variables_client = MeteocatVariables(self.api_key)
123
+ variables_data = await variables_client.get_variables()
122
124
 
123
- # Crear la carpeta de caché si no existe
124
- os.makedirs(cache_dir, exist_ok=True)
125
+ async with aiofiles.open(variables_file, "w", encoding="utf-8") as file:
126
+ await file.write(json.dumps({"variables": variables_data}, ensure_ascii=False, indent=4))
125
127
 
126
- variables_client = MeteocatVariables(self.api_key, cache_dir=cache_dir)
127
- try:
128
- variables_data = await variables_client.get_variables()
129
- self.variable_id = next(
130
- (v["codi"] for v in variables_data if v["nom"].lower() == "temperatura"), None
131
- )
132
- async with aiofiles.open(variables_file, "w", encoding="utf-8") as file:
133
- await file.write(json.dumps({"variables": variables_data}, ensure_ascii=False, indent=4))
134
- if not self.variable_id:
135
- _LOGGER.error("No se encontró la variable 'Temperatura'")
136
- errors["base"] = "variable_not_found"
137
- except (BadRequestError, ForbiddenError, TooManyRequestsError, InternalServerError, UnknownAPIError) as ex:
138
- _LOGGER.error("Error al obtener las variables: %s", ex)
139
- errors["base"] = "variables_fetch_failed"
128
+ # Actualizar la caché
129
+ cache_data = {
130
+ "symbols": symbols_data,
131
+ "variables": variables_data
132
+ }
133
+
134
+ async with aiofiles.open(variables_file, "w", encoding="utf-8") as file:
135
+ await file.write(json.dumps(cache_data, ensure_ascii=False, indent=4))
136
+
137
+ _LOGGER.info(f"Variables guardadas en {variables_file}")
138
+
139
+ # Buscar la variable de temperatura
140
+ self.variable_id = next(
141
+ (v["codi"] for v in variables_data if v["nom"].lower() == "temperatura"), None
142
+ )
143
+ if not self.variable_id:
144
+ _LOGGER.error("No se encontró la variable 'Temperatura'")
145
+ errors["base"] = "variable_not_found"
146
+ except (BadRequestError, ForbiddenError, TooManyRequestsError, InternalServerError, UnknownAPIError) as ex:
147
+ _LOGGER.error("Error al conectar con la API de Meteocat: %s", ex)
148
+ errors["base"] = "cannot_connect"
149
+ except Exception as ex:
150
+ _LOGGER.error("Error inesperado al descargar los datos: %s", ex)
151
+ errors["base"] = "unknown"
140
152
 
141
153
  if errors:
142
154
  raise HomeAssistantError(errors)
@@ -7,6 +7,6 @@
7
7
  "iot_class": "cloud_polling",
8
8
  "documentation": "https://gitlab.com/figorr/meteocat",
9
9
  "loggers": ["meteocatpy"],
10
- "requirements": ["meteocatpy==0.0.13", "packaging>=20.3", "wrapt>=1.14.0"],
11
- "version": "0.1.28"
10
+ "requirements": ["meteocatpy==0.0.14", "packaging>=20.3", "wrapt>=1.14.0"],
11
+ "version": "0.1.29"
12
12
  }
@@ -1,2 +1,2 @@
1
1
  # version.py
2
- __version__ = "0.1.28"
2
+ __version__ = "0.1.29"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meteocat",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
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.28"
3
+ version = "0.1.29"
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"