meteocat 0.1.26 → 0.1.27
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 +16 -0
- package/custom_components/meteocat/__init__.py +5 -5
- package/custom_components/meteocat/config_flow.py +8 -1
- package/custom_components/meteocat/coordinator.py +74 -74
- package/custom_components/meteocat/entity.py +98 -98
- package/custom_components/meteocat/manifest.json +2 -2
- package/custom_components/meteocat/version.py +1 -1
- package/package.json +1 -1
- package/poetry.lock +513 -519
- package/pyproject.toml +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## [0.1.27](https://github.com/figorr/meteocat/compare/v0.1.26...v0.1.27) (2024-12-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* 0.1.27 ([99feff1](https://github.com/figorr/meteocat/commit/99feff14eb85201028c1e6156a13354b05b446c3))
|
|
7
|
+
* bump meteocatpy to 0.0.11 ([03b9485](https://github.com/figorr/meteocat/commit/03b9485b0486a2bef7f0b7f3c0bf9bf1fca3da8c))
|
|
8
|
+
* bump meteocatpy to 0.0.9 ([1fb0de9](https://github.com/figorr/meteocat/commit/1fb0de97181b802494cb8371eb472a37c9a51f40))
|
|
9
|
+
* delete .meteocat_cache ([7941005](https://github.com/figorr/meteocat/commit/79410050e68667ca8162ff6575c0541a5f8b6207))
|
|
10
|
+
* fix python version ([07e3264](https://github.com/figorr/meteocat/commit/07e3264f5dde756c322ca431f4b895a211be998f))
|
|
11
|
+
* fix python version ([32f539b](https://github.com/figorr/meteocat/commit/32f539bb33a343881ebd26eb7ad3f12a58ecbed4))
|
|
12
|
+
* fix python version ([2ff2dfc](https://github.com/figorr/meteocat/commit/2ff2dfcfa597d9fbba0fc59c330f975c6b00a55b))
|
|
13
|
+
* ignore cache tests ([238d148](https://github.com/figorr/meteocat/commit/238d148630a5f84123f8d2d5db66dbd6e6b372f8))
|
|
14
|
+
* set variables cache ([ba77035](https://github.com/figorr/meteocat/commit/ba7703511c4e0604bd5d87f7d07ce487be67bafe))
|
|
15
|
+
* set variables cache ([ba55568](https://github.com/figorr/meteocat/commit/ba55568526fe74e83feaf4d7a0cd5127334ee139))
|
|
16
|
+
|
|
1
17
|
## [0.1.26](https://github.com/figorr/meteocat/compare/v0.1.25...v0.1.26) (2024-12-09)
|
|
2
18
|
|
|
3
19
|
|
|
@@ -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
|
|
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.
|
|
17
|
+
__version__ = "0.1.27"
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
|
|
@@ -48,10 +48,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
48
48
|
# Inicializar coordinadores
|
|
49
49
|
try:
|
|
50
50
|
sensor_coordinator = MeteocatSensorCoordinator(hass=hass, entry_data=entry_data)
|
|
51
|
-
entity_coordinator = MeteocatEntityCoordinator(hass=hass, entry_data=entry_data)
|
|
51
|
+
# entity_coordinator = MeteocatEntityCoordinator(hass=hass, entry_data=entry_data)
|
|
52
52
|
|
|
53
53
|
await sensor_coordinator.async_config_entry_first_refresh()
|
|
54
|
-
await entity_coordinator.async_config_entry_first_refresh()
|
|
54
|
+
# await entity_coordinator.async_config_entry_first_refresh()
|
|
55
55
|
except Exception as err: # Capturar todos los errores
|
|
56
56
|
_LOGGER.exception(f"Error al inicializar los coordinadores: {err}")
|
|
57
57
|
return False
|
|
@@ -60,7 +60,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
60
60
|
hass.data.setdefault(DOMAIN, {})
|
|
61
61
|
hass.data[DOMAIN][entry.entry_id] = {
|
|
62
62
|
"sensor_coordinator": sensor_coordinator,
|
|
63
|
-
"entity_coordinator": entity_coordinator,
|
|
63
|
+
# "entity_coordinator": entity_coordinator,
|
|
64
64
|
**entry_data,
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import os
|
|
3
4
|
import json
|
|
4
5
|
import logging
|
|
5
6
|
from pathlib import Path
|
|
@@ -115,7 +116,13 @@ class MeteocatConfigFlow(ConfigFlow, domain=DOMAIN):
|
|
|
115
116
|
errors["base"] = "symbols_download_failed"
|
|
116
117
|
|
|
117
118
|
if not errors:
|
|
118
|
-
|
|
119
|
+
# Configurar la ruta para la caché en la carpeta `custom_components/meteocat`
|
|
120
|
+
cache_dir = os.path.join(os.path.dirname(__file__), ".meteocat_cache")
|
|
121
|
+
|
|
122
|
+
# Crear la carpeta de caché si no existe
|
|
123
|
+
os.makedirs(cache_dir, exist_ok=True)
|
|
124
|
+
|
|
125
|
+
variables_client = MeteocatVariables(self.api_key, cache_dir=cache_dir)
|
|
119
126
|
try:
|
|
120
127
|
variables_data = await variables_client.get_variables()
|
|
121
128
|
self.variable_id = next(
|
|
@@ -12,7 +12,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
|
|
12
12
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
13
13
|
|
|
14
14
|
from meteocatpy.data import MeteocatStationData
|
|
15
|
-
from meteocatpy.forecast import MeteocatForecast
|
|
15
|
+
# from meteocatpy.forecast import MeteocatForecast
|
|
16
16
|
from meteocatpy.exceptions import (
|
|
17
17
|
BadRequestError,
|
|
18
18
|
ForbiddenError,
|
|
@@ -119,76 +119,76 @@ class MeteocatSensorCoordinator(DataUpdateCoordinator):
|
|
|
119
119
|
)
|
|
120
120
|
raise
|
|
121
121
|
|
|
122
|
-
class MeteocatEntityCoordinator(DataUpdateCoordinator):
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
122
|
+
# class MeteocatEntityCoordinator(DataUpdateCoordinator):
|
|
123
|
+
# """Coordinator para manejar la actualización de datos de las entidades de predicción."""
|
|
124
|
+
|
|
125
|
+
# def __init__(
|
|
126
|
+
# self,
|
|
127
|
+
# hass: HomeAssistant,
|
|
128
|
+
# entry_data: dict,
|
|
129
|
+
# update_interval: timedelta = DEFAULT_ENTITY_UPDATE_INTERVAL,
|
|
130
|
+
# ):
|
|
131
|
+
# """
|
|
132
|
+
# Inicializa el coordinador de datos para entidades de predicción.
|
|
133
|
+
|
|
134
|
+
# Args:
|
|
135
|
+
# hass (HomeAssistant): Instancia de Home Assistant.
|
|
136
|
+
# entry_data (dict): Datos de configuración obtenidos de core.config_entries.
|
|
137
|
+
# update_interval (timedelta): Intervalo de actualización.
|
|
138
|
+
# """
|
|
139
|
+
# self.api_key = entry_data["api_key"]
|
|
140
|
+
# self.town_name = entry_data["town_name"]
|
|
141
|
+
# self.town_id = entry_data["town_id"]
|
|
142
|
+
# self.station_name = entry_data["station_name"]
|
|
143
|
+
# self.station_id = entry_data["station_id"]
|
|
144
|
+
# self.variable_name = entry_data["variable_name"]
|
|
145
|
+
# self.variable_id = entry_data["variable_id"]
|
|
146
|
+
# self.meteocat_forecast = MeteocatForecast(self.api_key)
|
|
147
|
+
|
|
148
|
+
# super().__init__(
|
|
149
|
+
# hass,
|
|
150
|
+
# _LOGGER,
|
|
151
|
+
# name=f"{DOMAIN} Entity Coordinator",
|
|
152
|
+
# update_interval=update_interval,
|
|
153
|
+
# )
|
|
154
|
+
|
|
155
|
+
# async def _async_update_data(self) -> Dict:
|
|
156
|
+
# """Actualiza los datos de las entidades de predicción desde la API de Meteocat."""
|
|
157
|
+
# try:
|
|
158
|
+
# hourly_forecast = await self.meteocat_forecast.get_prediccion_horaria(self.town_id)
|
|
159
|
+
# daily_forecast = await self.meteocat_forecast.get_prediccion_diaria(self.town_id)
|
|
160
|
+
# _LOGGER.debug(
|
|
161
|
+
# "Datos de predicción actualizados exitosamente (Town ID: %s)", self.town_id
|
|
162
|
+
# )
|
|
163
|
+
# return {
|
|
164
|
+
# "hourly_forecast": hourly_forecast,
|
|
165
|
+
# "daily_forecast": daily_forecast,
|
|
166
|
+
# }
|
|
167
|
+
# except ForbiddenError as err:
|
|
168
|
+
# _LOGGER.error(
|
|
169
|
+
# "Acceso denegado al obtener datos de predicción (Town ID: %s): %s",
|
|
170
|
+
# self.town_id,
|
|
171
|
+
# err,
|
|
172
|
+
# )
|
|
173
|
+
# raise ConfigEntryNotReady from err
|
|
174
|
+
# except TooManyRequestsError as err:
|
|
175
|
+
# _LOGGER.warning(
|
|
176
|
+
# "Límite de solicitudes alcanzado al obtener datos de predicción (Town ID: %s): %s",
|
|
177
|
+
# self.town_id,
|
|
178
|
+
# err,
|
|
179
|
+
# )
|
|
180
|
+
# raise ConfigEntryNotReady from err
|
|
181
|
+
# except (BadRequestError, InternalServerError, UnknownAPIError) as err:
|
|
182
|
+
# _LOGGER.error(
|
|
183
|
+
# "Error al obtener datos de predicción (Town ID: %s): %s",
|
|
184
|
+
# self.town_id,
|
|
185
|
+
# err,
|
|
186
|
+
# )
|
|
187
|
+
# raise
|
|
188
|
+
# except Exception as err:
|
|
189
|
+
# _LOGGER.exception(
|
|
190
|
+
# "Error inesperado al obtener datos de predicción (Town ID: %s): %s",
|
|
191
|
+
# self.town_id,
|
|
192
|
+
# err,
|
|
193
|
+
# )
|
|
194
|
+
# raise
|
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import asyncio
|
|
4
|
-
import logging
|
|
5
|
-
from homeassistant.components.weather import WeatherEntity
|
|
6
|
-
from homeassistant.const import (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
from .const import (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
)
|
|
24
|
-
from .condition import get_condition_from_statcel
|
|
25
|
-
from .coordinator import MeteocatEntityCoordinator
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_LOGGER = logging.getLogger(__name__)
|
|
29
|
-
|
|
30
|
-
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
class MeteocatWeatherEntity(WeatherEntity):
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
1
|
+
# from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
# import asyncio
|
|
4
|
+
# import logging
|
|
5
|
+
# from homeassistant.components.weather import WeatherEntity
|
|
6
|
+
# from homeassistant.const import (
|
|
7
|
+
# DEGREE,
|
|
8
|
+
# PERCENTAGE,
|
|
9
|
+
# UnitOfPressure,
|
|
10
|
+
# UnitOfSpeed,
|
|
11
|
+
# UnitOfTemperature,
|
|
12
|
+
# UnitOfVolumetricFlux,
|
|
13
|
+
# )
|
|
14
|
+
|
|
15
|
+
# from .const import (
|
|
16
|
+
# DOMAIN,
|
|
17
|
+
# CONF_API_KEY,
|
|
18
|
+
# TOWN_ID,
|
|
19
|
+
# TEMPERATURE,
|
|
20
|
+
# HUMIDITY,
|
|
21
|
+
# WIND_SPEED,
|
|
22
|
+
# WIND_DIRECTION,
|
|
23
|
+
# )
|
|
24
|
+
# from .condition import get_condition_from_statcel
|
|
25
|
+
# from .coordinator import MeteocatEntityCoordinator
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# _LOGGER = logging.getLogger(__name__)
|
|
29
|
+
|
|
30
|
+
# async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
31
|
+
# """Configura el componente weather basado en una entrada de configuración."""
|
|
32
|
+
# api_key = config_entry.data[CONF_API_KEY]
|
|
33
|
+
# town_id = config_entry.data[TOWN_ID]
|
|
34
|
+
|
|
35
|
+
# # Crear el coordinador
|
|
36
|
+
# coordinator = MeteocatEntityCoordinator(hass, api_key, town_id)
|
|
37
|
+
# # Asegurarse de que el coordinador esté actualizado antes de agregar la entidad
|
|
38
|
+
# await coordinator.async_refresh()
|
|
39
|
+
|
|
40
|
+
# async_add_entities([MeteocatWeatherEntity(coordinator)], True)
|
|
41
|
+
|
|
42
|
+
# class MeteocatWeatherEntity(WeatherEntity):
|
|
43
|
+
# """Entidad de clima para la integración Meteocat."""
|
|
44
|
+
|
|
45
|
+
# def __init__(self, coordinator: MeteocatEntityCoordinator):
|
|
46
|
+
# """Inicializa la entidad MeteocatWeather."""
|
|
47
|
+
# self._coordinator = coordinator
|
|
48
|
+
# self._attr_temperature_unit = UnitOfTemperature.CELSIUS
|
|
49
|
+
# self._data = {}
|
|
50
|
+
|
|
51
|
+
# async def async_update(self):
|
|
52
|
+
# """Actualiza los datos meteorológicos."""
|
|
53
|
+
# try:
|
|
54
|
+
# # Usamos el coordinador para obtener los datos actualizados
|
|
55
|
+
# if self._coordinator.data:
|
|
56
|
+
# hourly_forecast = self._coordinator.data["hourly_forecast"]
|
|
57
|
+
# current_forecast = hourly_forecast["variables"]
|
|
58
|
+
# codi_estatcel = current_forecast.get("estatCel", {}).get("valor")
|
|
59
|
+
# is_night = current_forecast.get("is_night", False)
|
|
60
|
+
# self._data = {
|
|
61
|
+
# "temperature": current_forecast.get(TEMPERATURE, {}).get("valor"),
|
|
62
|
+
# "humidity": current_forecast.get(HUMIDITY, {}).get("valor"),
|
|
63
|
+
# "wind_speed": current_forecast.get(WIND_SPEED, {}).get("valor"),
|
|
64
|
+
# "wind_bearing": current_forecast.get(WIND_DIRECTION, {}).get("valor"),
|
|
65
|
+
# "condition": get_condition_from_statcel(codi_estatcel, is_night)["condition"],
|
|
66
|
+
# }
|
|
67
|
+
# except Exception as err:
|
|
68
|
+
# _LOGGER.error("Error al actualizar la predicción de Meteocat: %s", err)
|
|
69
|
+
|
|
70
|
+
# @property
|
|
71
|
+
# def name(self):
|
|
72
|
+
# """Retorna el nombre de la entidad."""
|
|
73
|
+
# return f"Clima {self._coordinator._town_id}"
|
|
74
|
+
|
|
75
|
+
# @property
|
|
76
|
+
# def temperature(self):
|
|
77
|
+
# """Retorna la temperatura actual."""
|
|
78
|
+
# return self._data.get("temperature")
|
|
79
|
+
|
|
80
|
+
# @property
|
|
81
|
+
# def humidity(self):
|
|
82
|
+
# """Retorna la humedad relativa actual."""
|
|
83
|
+
# return self._data.get("humidity")
|
|
84
|
+
|
|
85
|
+
# @property
|
|
86
|
+
# def wind_speed(self):
|
|
87
|
+
# """Retorna la velocidad del viento."""
|
|
88
|
+
# return self._data.get("wind_speed")
|
|
89
|
+
|
|
90
|
+
# @property
|
|
91
|
+
# def wind_bearing(self):
|
|
92
|
+
# """Retorna la dirección del viento."""
|
|
93
|
+
# return self._data.get("wind_bearing")
|
|
94
|
+
|
|
95
|
+
# @property
|
|
96
|
+
# def condition(self):
|
|
97
|
+
# """Retorna la condición climática."""
|
|
98
|
+
# return self._data.get("condition")
|
|
@@ -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.11", "packaging>=20.3", "wrapt>=1.14.0"],
|
|
11
|
+
"version": "0.1.27"
|
|
12
12
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
# version.py
|
|
2
|
-
__version__ = "0.1.
|
|
2
|
+
__version__ = "0.1.27"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meteocat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
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": {
|