meteocat 0.1.27 → 0.1.28
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 +13 -0
- package/custom_components/meteocat/__init__.py +41 -49
- package/custom_components/meteocat/config_flow.py +3 -0
- package/custom_components/meteocat/manifest.json +2 -2
- package/custom_components/meteocat/sensor.py +1 -1
- 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,16 @@
|
|
|
1
|
+
## [0.1.28](https://github.com/figorr/meteocat/compare/v0.1.27...v0.1.28) (2024-12-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* 0.1.28 ([2c329cb](https://github.com/figorr/meteocat/commit/2c329cb960aa7bd6ec6bec0c6145db791349758f))
|
|
7
|
+
* bump meteocatpy to 0.0.13 ([52c11c6](https://github.com/figorr/meteocat/commit/52c11c66f66b0ebff40fea58a8a5c4d4a74482be))
|
|
8
|
+
* fix entity_id ([fa61841](https://github.com/figorr/meteocat/commit/fa61841ba3857a79d6b97d0e0ed12a543525c205))
|
|
9
|
+
* fix name sensors to include station_id ([7b868fd](https://github.com/figorr/meteocat/commit/7b868fd0eea66f8ec2655e92137d9ab6dd9d0149))
|
|
10
|
+
* ignore test_call_api ([976826a](https://github.com/figorr/meteocat/commit/976826a978889fcec304a8b3620ccf738e1a1946))
|
|
11
|
+
* save variables.json in assets folder ([d2c2234](https://github.com/figorr/meteocat/commit/d2c2234621aaabbbdc65367429b56b304855f710))
|
|
12
|
+
* setup cache folder and new async_remove_entry ([4dfddc0](https://github.com/figorr/meteocat/commit/4dfddc03a64f82582b39eff47870c561d0775d6d))
|
|
13
|
+
|
|
1
14
|
## [0.1.27](https://github.com/figorr/meteocat/compare/v0.1.26...v0.1.27) (2024-12-10)
|
|
2
15
|
|
|
3
16
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
3
|
import logging
|
|
4
|
+
from pathlib import Path
|
|
5
5
|
from homeassistant import core
|
|
6
6
|
from homeassistant.config_entries import ConfigEntry
|
|
7
7
|
from homeassistant.core import HomeAssistant
|
|
@@ -14,7 +14,19 @@ from .const import DOMAIN, PLATFORMS
|
|
|
14
14
|
_LOGGER = logging.getLogger(__name__)
|
|
15
15
|
|
|
16
16
|
# Versión
|
|
17
|
-
__version__ = "0.1.
|
|
17
|
+
__version__ = "0.1.28"
|
|
18
|
+
|
|
19
|
+
def safe_remove(path: Path, is_folder: bool = False):
|
|
20
|
+
"""Elimina de forma segura un archivo o carpeta si existe."""
|
|
21
|
+
try:
|
|
22
|
+
if is_folder and path.exists() and not any(path.iterdir()):
|
|
23
|
+
path.rmdir()
|
|
24
|
+
_LOGGER.info(f"Carpeta {path.name} eliminada correctamente.")
|
|
25
|
+
elif not is_folder and path.exists():
|
|
26
|
+
path.unlink()
|
|
27
|
+
_LOGGER.info(f"Archivo {path.name} eliminado correctamente.")
|
|
28
|
+
except OSError as e:
|
|
29
|
+
_LOGGER.error(f"Error al intentar eliminar {path.name}: {e}")
|
|
18
30
|
|
|
19
31
|
|
|
20
32
|
async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
|
|
@@ -45,12 +57,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
45
57
|
f"Estación '{entry_data['station_name']}' (ID: {entry_data['station_id']})."
|
|
46
58
|
)
|
|
47
59
|
|
|
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
|
+
|
|
48
65
|
# Inicializar coordinadores
|
|
49
66
|
try:
|
|
50
67
|
sensor_coordinator = MeteocatSensorCoordinator(hass=hass, entry_data=entry_data)
|
|
51
|
-
# entity_coordinator = MeteocatEntityCoordinator(hass=hass, entry_data=entry_data)
|
|
52
|
-
|
|
53
68
|
await sensor_coordinator.async_config_entry_first_refresh()
|
|
69
|
+
|
|
70
|
+
# entity_coordinator = MeteocatEntityCoordinator(hass=hass, entry_data=entry_data)
|
|
54
71
|
# await entity_coordinator.async_config_entry_first_refresh()
|
|
55
72
|
except Exception as err: # Capturar todos los errores
|
|
56
73
|
_LOGGER.exception(f"Error al inicializar los coordinadores: {err}")
|
|
@@ -89,48 +106,23 @@ async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|
|
89
106
|
_LOGGER.info(f"Eliminando datos residuales de la integración: {entry.entry_id}")
|
|
90
107
|
|
|
91
108
|
# Definir las rutas de los archivos y carpetas a eliminar
|
|
92
|
-
custom_components_path = hass.config.path("custom_components"
|
|
93
|
-
assets_folder =
|
|
94
|
-
files_folder =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
_LOGGER.info("Archivo station_data.json eliminado correctamente.")
|
|
113
|
-
else:
|
|
114
|
-
_LOGGER.info("El archivo station_data.json no se encontró.")
|
|
115
|
-
except OSError as e:
|
|
116
|
-
_LOGGER.error(f"Error al intentar eliminar el archivo station_data.json: {e}")
|
|
117
|
-
|
|
118
|
-
# Eliminar la carpeta assets si está vacía
|
|
119
|
-
try:
|
|
120
|
-
if os.path.exists(assets_folder) and not os.listdir(assets_folder):
|
|
121
|
-
os.rmdir(assets_folder)
|
|
122
|
-
_LOGGER.info("Carpeta assets eliminada correctamente.")
|
|
123
|
-
elif os.path.exists(assets_folder):
|
|
124
|
-
_LOGGER.warning("La carpeta assets no está vacía y no se pudo eliminar.")
|
|
125
|
-
except OSError as e:
|
|
126
|
-
_LOGGER.error(f"Error al intentar eliminar la carpeta assets: {e}")
|
|
127
|
-
|
|
128
|
-
# Eliminar la carpeta files si está vacía
|
|
129
|
-
try:
|
|
130
|
-
if os.path.exists(files_folder) and not os.listdir(files_folder):
|
|
131
|
-
os.rmdir(files_folder)
|
|
132
|
-
_LOGGER.info("Carpeta files eliminada correctamente.")
|
|
133
|
-
elif os.path.exists(files_folder):
|
|
134
|
-
_LOGGER.warning("La carpeta files no está vacía y no se pudo eliminar.")
|
|
135
|
-
except OSError as e:
|
|
136
|
-
_LOGGER.error(f"Error al intentar eliminar la carpeta files: {e}")
|
|
109
|
+
custom_components_path = Path(hass.config.path("custom_components")) / DOMAIN
|
|
110
|
+
assets_folder = custom_components_path / "assets"
|
|
111
|
+
files_folder = custom_components_path / "files"
|
|
112
|
+
cache_folder = custom_components_path / ".meteocat_cache"
|
|
113
|
+
symbols_file = assets_folder / "symbols.json"
|
|
114
|
+
variables_file = assets_folder / "variables.json"
|
|
115
|
+
station_data_file = files_folder / "station_data.json"
|
|
116
|
+
|
|
117
|
+
# Validar la ruta base
|
|
118
|
+
if not custom_components_path.exists():
|
|
119
|
+
_LOGGER.warning(f"La ruta {custom_components_path} no existe. No se realizará la limpieza.")
|
|
120
|
+
return
|
|
121
|
+
|
|
122
|
+
# Eliminar archivos y carpetas
|
|
123
|
+
safe_remove(symbols_file)
|
|
124
|
+
safe_remove(variables_file)
|
|
125
|
+
safe_remove(station_data_file)
|
|
126
|
+
safe_remove(assets_folder, is_folder=True)
|
|
127
|
+
safe_remove(files_folder, is_folder=True)
|
|
128
|
+
safe_remove(cache_folder, is_folder=True)
|
|
@@ -105,6 +105,7 @@ class MeteocatConfigFlow(ConfigFlow, domain=DOMAIN):
|
|
|
105
105
|
assets_dir = Path(__file__).parent / "assets"
|
|
106
106
|
assets_dir.mkdir(parents=True, exist_ok=True)
|
|
107
107
|
symbols_file = assets_dir / "symbols.json"
|
|
108
|
+
variables_file = assets_dir / "variables.json"
|
|
108
109
|
symbols_client = MeteocatSymbols(self.api_key)
|
|
109
110
|
|
|
110
111
|
try:
|
|
@@ -128,6 +129,8 @@ class MeteocatConfigFlow(ConfigFlow, domain=DOMAIN):
|
|
|
128
129
|
self.variable_id = next(
|
|
129
130
|
(v["codi"] for v in variables_data if v["nom"].lower() == "temperatura"), None
|
|
130
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))
|
|
131
134
|
if not self.variable_id:
|
|
132
135
|
_LOGGER.error("No se encontró la variable 'Temperatura'")
|
|
133
136
|
errors["base"] = "variable_not_found"
|
|
@@ -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.
|
|
11
|
-
"version": "0.1.
|
|
10
|
+
"requirements": ["meteocatpy==0.0.13", "packaging>=20.3", "wrapt>=1.14.0"],
|
|
11
|
+
"version": "0.1.28"
|
|
12
12
|
}
|
|
@@ -319,7 +319,7 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
|
|
|
319
319
|
"""Return the device info."""
|
|
320
320
|
return DeviceInfo(
|
|
321
321
|
identifiers={(DOMAIN, self._town_id)},
|
|
322
|
-
name=self._town_name,
|
|
322
|
+
name="Meteocat " + self._station_id + " " + self._town_name,
|
|
323
323
|
manufacturer="Meteocat",
|
|
324
324
|
model="Meteocat API",
|
|
325
325
|
)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
# version.py
|
|
2
|
-
__version__ = "0.1.
|
|
2
|
+
__version__ = "0.1.28"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meteocat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
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": {
|