meteocat 0.1.21 → 0.1.23
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/.releaserc +1 -1
- package/CHANGELOG.md +20 -2
- package/custom_components/meteocat/__init__.py +21 -53
- package/custom_components/meteocat/const.py +27 -19
- package/custom_components/meteocat/coordinator.py +38 -44
- package/custom_components/meteocat/entity.py +9 -2
- package/custom_components/meteocat/manifest.json +2 -2
- package/custom_components/meteocat/sensor.py +38 -28
- package/custom_components/meteocat/version.py +1 -1
- package/package.json +1 -1
- package/pyproject.toml +1 -1
package/.releaserc
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@semantic-release/git",
|
|
16
16
|
{
|
|
17
17
|
"assets": ["CHANGELOG.md", "package.json", "pyproject.toml"],
|
|
18
|
-
"message": "
|
|
18
|
+
"message": "v${nextRelease.version}\n\n${nextRelease.notes}"
|
|
19
19
|
}
|
|
20
20
|
]
|
|
21
21
|
],
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## [0.1.23](https://github.com/figorr/meteocat/compare/v0.1.22...v0.1.23) (2024-12-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* 0.1.23 ([dda17ae](https://github.com/figorr/meteocat/commit/dda17ae1d73d31879d029d4c7a8f12a1a74f2379))
|
|
7
|
+
* fix sensor data recovery ([564ceb7](https://github.com/figorr/meteocat/commit/564ceb7ff372acd7d2d035272e9784ad583ccece))
|
|
8
|
+
* fix unis of measurement ([c65bce2](https://github.com/figorr/meteocat/commit/c65bce26add578bc32ebb05b82381aa72dfbf9a6))
|
|
9
|
+
|
|
10
|
+
## [0.1.22](https://github.com/figorr/meteocat/compare/v0.1.21...v0.1.22) (2024-12-07)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* 0.1.22 ([54b39fa](https://github.com/figorr/meteocat/commit/54b39fad5e645673c2d46ca3209e82d92db03b95))
|
|
16
|
+
* add platforms ([fbbad49](https://github.com/figorr/meteocat/commit/fbbad49a6de960719d0c4f6a734c6dd1e0f3dfb5))
|
|
17
|
+
* bump meteocatpy to 0.0.7 ([f00b48d](https://github.com/figorr/meteocat/commit/f00b48da53e0f309686fa7214c60647bb0965495))
|
|
18
|
+
* fix coordinator to use entry_data ([5ca5050](https://github.com/figorr/meteocat/commit/5ca50501e04e8b3f6cb222f0f183dea1cc726242))
|
|
19
|
+
* fix UV icon ([f2c86e3](https://github.com/figorr/meteocat/commit/f2c86e3e03df987e40bdf955113f2235db347229))
|
|
20
|
+
|
|
1
21
|
## [0.1.21](https://github.com/figorr/meteocat/compare/v0.1.20...v0.1.21) (2024-12-06)
|
|
2
22
|
|
|
3
23
|
|
|
@@ -8,8 +28,6 @@
|
|
|
8
28
|
* new repo file structure ([7ef2dbe](https://github.com/figorr/meteocat/commit/7ef2dbe67bc41c77e0f931d833578540dafe0ca8))
|
|
9
29
|
* semantic-release job ([a78eb5c](https://github.com/figorr/meteocat/commit/a78eb5c6dbbaef556a40053f98257906adeeecaa))
|
|
10
30
|
|
|
11
|
-
# CHANGELOG
|
|
12
|
-
|
|
13
31
|
|
|
14
32
|
## v0.1.14 (2024-11-22)
|
|
15
33
|
|
|
@@ -7,24 +7,12 @@ from homeassistant.config_entries import ConfigEntry
|
|
|
7
7
|
from homeassistant.core import HomeAssistant
|
|
8
8
|
from homeassistant.exceptions import HomeAssistantError
|
|
9
9
|
from .coordinator import MeteocatSensorCoordinator, MeteocatEntityCoordinator
|
|
10
|
-
from .const import
|
|
11
|
-
DOMAIN,
|
|
12
|
-
CONF_API_KEY,
|
|
13
|
-
TOWN_NAME,
|
|
14
|
-
TOWN_ID,
|
|
15
|
-
VARIABLE_NAME,
|
|
16
|
-
VARIABLE_ID,
|
|
17
|
-
STATION_NAME,
|
|
18
|
-
STATION_ID,
|
|
19
|
-
)
|
|
10
|
+
from .const import DOMAIN, PLATFORMS
|
|
20
11
|
|
|
21
12
|
_LOGGER = logging.getLogger(__name__)
|
|
22
13
|
|
|
23
14
|
# Versión
|
|
24
|
-
__version__ = "0.1.
|
|
25
|
-
|
|
26
|
-
# Plataformas soportadas por la integración
|
|
27
|
-
PLATFORMS = ["sensor", "entity"]
|
|
15
|
+
__version__ = "0.1.23"
|
|
28
16
|
|
|
29
17
|
|
|
30
18
|
async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
|
|
@@ -38,71 +26,50 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
38
26
|
|
|
39
27
|
# Extraer los datos necesarios de la entrada de configuración
|
|
40
28
|
entry_data = entry.data
|
|
41
|
-
required_fields = [
|
|
42
|
-
CONF_API_KEY, TOWN_NAME, TOWN_ID, VARIABLE_ID, STATION_NAME, STATION_ID
|
|
43
|
-
]
|
|
44
29
|
|
|
45
30
|
# Validar que todos los campos requeridos estén presentes
|
|
31
|
+
required_fields = [
|
|
32
|
+
"api_key", "town_name", "town_id", "variable_name",
|
|
33
|
+
"variable_id", "station_name", "station_id"
|
|
34
|
+
]
|
|
46
35
|
if not all(field in entry_data for field in required_fields):
|
|
47
36
|
_LOGGER.error("Faltan datos en la configuración. Por favor, reconfigura la integración.")
|
|
48
37
|
return False
|
|
49
38
|
|
|
50
|
-
api_key = entry_data[CONF_API_KEY]
|
|
51
|
-
town_name = entry_data[TOWN_NAME]
|
|
52
|
-
town_id = entry_data[TOWN_ID]
|
|
53
|
-
variable_name = entry_data[VARIABLE_NAME]
|
|
54
|
-
variable_id = entry_data[VARIABLE_ID]
|
|
55
|
-
station_name = entry_data[STATION_NAME]
|
|
56
|
-
station_id = entry_data[STATION_ID]
|
|
57
|
-
|
|
58
39
|
_LOGGER.info(
|
|
59
|
-
f"Integración configurada para el municipio '{town_name}'
|
|
60
|
-
f"
|
|
40
|
+
f"Integración configurada para el municipio '{entry_data['town_name']}' "
|
|
41
|
+
f"(ID: {entry_data['town_id']}), variable '{entry_data['variable_name']}' "
|
|
42
|
+
f"(ID: {entry_data['variable_id']}), estación '{entry_data['station_name']}' "
|
|
43
|
+
f"(ID: {entry_data['station_id']})."
|
|
61
44
|
)
|
|
62
45
|
|
|
63
46
|
# Inicializa y refresca los coordinadores
|
|
64
47
|
try:
|
|
65
|
-
#
|
|
48
|
+
# Crear el coordinador para sensores
|
|
66
49
|
sensor_coordinator = MeteocatSensorCoordinator(
|
|
67
|
-
hass,
|
|
68
|
-
|
|
69
|
-
town_name=town_name,
|
|
70
|
-
town_id=town_id,
|
|
71
|
-
station_name=station_name,
|
|
72
|
-
station_id=station_id,
|
|
73
|
-
variable_name=variable_name,
|
|
74
|
-
variable_id=variable_id,
|
|
50
|
+
hass=hass,
|
|
51
|
+
entry_data=entry_data, # Pasa los datos como un diccionario
|
|
75
52
|
)
|
|
76
|
-
|
|
53
|
+
|
|
54
|
+
# Crear el coordinador para entidades de predicción
|
|
77
55
|
entity_coordinator = MeteocatEntityCoordinator(
|
|
78
|
-
hass,
|
|
79
|
-
|
|
80
|
-
town_name=town_name,
|
|
81
|
-
town_id=town_id,
|
|
82
|
-
station_name=station_name,
|
|
83
|
-
station_id=station_id,
|
|
84
|
-
variable_name=variable_name,
|
|
85
|
-
variable_id=variable_id,
|
|
56
|
+
hass=hass,
|
|
57
|
+
entry_data=entry_data, # Pasa los mismos datos
|
|
86
58
|
)
|
|
87
59
|
|
|
60
|
+
# Ejecutar la primera actualización
|
|
88
61
|
await sensor_coordinator.async_config_entry_first_refresh()
|
|
89
62
|
await entity_coordinator.async_config_entry_first_refresh()
|
|
90
63
|
except HomeAssistantError as err:
|
|
91
64
|
_LOGGER.error(f"Error al inicializar los coordinadores: {err}")
|
|
92
65
|
return False
|
|
93
66
|
|
|
94
|
-
# Guardar los
|
|
67
|
+
# Guardar los coordinadores en hass.data
|
|
95
68
|
hass.data.setdefault(DOMAIN, {})
|
|
96
69
|
hass.data[DOMAIN][entry.entry_id] = {
|
|
97
70
|
"sensor_coordinator": sensor_coordinator,
|
|
98
71
|
"entity_coordinator": entity_coordinator,
|
|
99
|
-
|
|
100
|
-
"town_id": town_id,
|
|
101
|
-
"town_name": town_name,
|
|
102
|
-
"station_id": station_id,
|
|
103
|
-
"station_name": station_name,
|
|
104
|
-
"variable_id": variable_id,
|
|
105
|
-
"variable_name": variable_name,
|
|
72
|
+
**entry_data,
|
|
106
73
|
}
|
|
107
74
|
|
|
108
75
|
# Configurar las plataformas
|
|
@@ -110,6 +77,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
110
77
|
|
|
111
78
|
return True
|
|
112
79
|
|
|
80
|
+
|
|
113
81
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
114
82
|
"""Desactiva una entrada de configuración para Meteocat."""
|
|
115
83
|
if entry.entry_id in hass.data.get(DOMAIN, {}):
|
|
@@ -10,25 +10,16 @@ STATION_NAME = "station_name"
|
|
|
10
10
|
STATION_ID = "station_id"
|
|
11
11
|
|
|
12
12
|
# Códigos de sensores de la API
|
|
13
|
-
WIND_SPEED = "
|
|
14
|
-
WIND_DIRECTION = "
|
|
15
|
-
TEMPERATURE = "
|
|
16
|
-
HUMIDITY = "
|
|
17
|
-
PRESSURE = "
|
|
18
|
-
PRECIPITATION = "
|
|
19
|
-
UV_INDEX = "
|
|
20
|
-
MAX_TEMPERATURE = "
|
|
21
|
-
MIN_TEMPERATURE = "
|
|
22
|
-
WIND_GUST = "
|
|
23
|
-
|
|
24
|
-
# Unidades de medida de los sensores
|
|
25
|
-
WIND_SPEED_UNIT = "m/s"
|
|
26
|
-
WIND_DIRECTION_UNIT = "°"
|
|
27
|
-
TEMPERATURE_UNIT = "°C"
|
|
28
|
-
HUMIDITY_UNIT = "%"
|
|
29
|
-
PRESSURE_UNIT = "hPa"
|
|
30
|
-
PRECIPITATION_UNIT = "mm"
|
|
31
|
-
UV_INDEX_UNIT = "UV"
|
|
13
|
+
WIND_SPEED = "wind_speed" # Velocidad del viento
|
|
14
|
+
WIND_DIRECTION = "wind_direction" # Dirección del viento
|
|
15
|
+
TEMPERATURE = "temperature" # Temperatura
|
|
16
|
+
HUMIDITY = "humidity" # Humedad relativa
|
|
17
|
+
PRESSURE = "pressure" # Presión atmosférica
|
|
18
|
+
PRECIPITATION = "precipitation" # Precipitación
|
|
19
|
+
UV_INDEX = "uv_index" # UV
|
|
20
|
+
MAX_TEMPERATURE = "max_temperature" # Temperatura máxima
|
|
21
|
+
MIN_TEMPERATURE = "min_temperature" # Temperatura mínima
|
|
22
|
+
WIND_GUST = "wind_gust" # Racha de viento
|
|
32
23
|
|
|
33
24
|
# Mapeo de códigos 'estatCel' a condiciones de Home Assistant
|
|
34
25
|
CONDITION_MAPPING = {
|
|
@@ -44,3 +35,20 @@ CONDITION_MAPPING = {
|
|
|
44
35
|
"fog": [11, 12],
|
|
45
36
|
"snow-rainy": [27, 29, 30],
|
|
46
37
|
}
|
|
38
|
+
|
|
39
|
+
# Mapeo de códigos a claves de sensores
|
|
40
|
+
VARIABLE_CODE_MAPPING = {
|
|
41
|
+
30: WIND_SPEED,
|
|
42
|
+
31: WIND_DIRECTION,
|
|
43
|
+
32: TEMPERATURE,
|
|
44
|
+
33: HUMIDITY,
|
|
45
|
+
34: PRESSURE,
|
|
46
|
+
35: PRECIPITATION,
|
|
47
|
+
39: UV_INDEX,
|
|
48
|
+
40: MAX_TEMPERATURE,
|
|
49
|
+
42: MIN_TEMPERATURE,
|
|
50
|
+
50: WIND_GUST,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
# Platforms
|
|
54
|
+
PLATFORMS = ["sensor"]
|
|
@@ -33,24 +33,26 @@ class MeteocatSensorCoordinator(DataUpdateCoordinator):
|
|
|
33
33
|
def __init__(
|
|
34
34
|
self,
|
|
35
35
|
hass: HomeAssistant,
|
|
36
|
-
|
|
37
|
-
town_name: str,
|
|
38
|
-
town_id: str,
|
|
39
|
-
station_name: str,
|
|
40
|
-
station_id: str,
|
|
41
|
-
variable_name: str,
|
|
42
|
-
variable_id: str,
|
|
36
|
+
entry_data: dict,
|
|
43
37
|
update_interval: timedelta = DEFAULT_SENSOR_UPDATE_INTERVAL,
|
|
44
38
|
):
|
|
45
|
-
"""
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
self.
|
|
39
|
+
"""
|
|
40
|
+
Inicializa el coordinador de sensores de Meteocat.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
hass (HomeAssistant): Instancia de Home Assistant.
|
|
44
|
+
entry_data (dict): Datos de configuración obtenidos de core.config_entries.
|
|
45
|
+
update_interval (timedelta): Intervalo de actualización.
|
|
46
|
+
"""
|
|
47
|
+
self.api_key = entry_data["api_key"] # Usamos la API key de la configuración
|
|
48
|
+
self.town_name = entry_data["town_name"] # Usamos el nombre del municipio
|
|
49
|
+
self.town_id = entry_data["town_id"] # Usamos el ID del municipio
|
|
50
|
+
self.station_name = entry_data["station_name"] # Usamos el nombre de la estación
|
|
51
|
+
self.station_id = entry_data["station_id"] # Usamos el ID de la estación
|
|
52
|
+
self.variable_name = entry_data["variable_name"] # Usamos el nombre de la variable
|
|
53
|
+
self.variable_id = entry_data["variable_id"] # Usamos el ID de la variable
|
|
54
|
+
self.meteocat_station_data = MeteocatStationData(self.api_key)
|
|
55
|
+
|
|
54
56
|
super().__init__(
|
|
55
57
|
hass,
|
|
56
58
|
_LOGGER,
|
|
@@ -59,12 +61,7 @@ class MeteocatSensorCoordinator(DataUpdateCoordinator):
|
|
|
59
61
|
)
|
|
60
62
|
|
|
61
63
|
async def _async_update_data(self) -> Dict:
|
|
62
|
-
"""
|
|
63
|
-
Actualiza los datos de los sensores desde la API de Meteocat.
|
|
64
|
-
|
|
65
|
-
Returns:
|
|
66
|
-
dict: Datos actualizados de los sensores.
|
|
67
|
-
"""
|
|
64
|
+
"""Actualiza los datos de los sensores desde la API de Meteocat."""
|
|
68
65
|
try:
|
|
69
66
|
data = await self.meteocat_station_data.get_station_data_with_variables(self.station_id)
|
|
70
67
|
_LOGGER.debug("Datos de sensores actualizados exitosamente: %s", data)
|
|
@@ -105,24 +102,26 @@ class MeteocatEntityCoordinator(DataUpdateCoordinator):
|
|
|
105
102
|
def __init__(
|
|
106
103
|
self,
|
|
107
104
|
hass: HomeAssistant,
|
|
108
|
-
|
|
109
|
-
town_name: str,
|
|
110
|
-
town_id: str,
|
|
111
|
-
station_name: str,
|
|
112
|
-
station_id: str,
|
|
113
|
-
variable_name: str,
|
|
114
|
-
variable_id: str,
|
|
105
|
+
entry_data: dict,
|
|
115
106
|
update_interval: timedelta = DEFAULT_ENTITY_UPDATE_INTERVAL,
|
|
116
107
|
):
|
|
117
|
-
"""
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
self.
|
|
108
|
+
"""
|
|
109
|
+
Inicializa el coordinador de datos para entidades de predicción.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
hass (HomeAssistant): Instancia de Home Assistant.
|
|
113
|
+
entry_data (dict): Datos de configuración obtenidos de core.config_entries.
|
|
114
|
+
update_interval (timedelta): Intervalo de actualización.
|
|
115
|
+
"""
|
|
116
|
+
self.api_key = entry_data["api_key"]
|
|
117
|
+
self.town_name = entry_data["town_name"]
|
|
118
|
+
self.town_id = entry_data["town_id"]
|
|
119
|
+
self.station_name = entry_data["station_name"]
|
|
120
|
+
self.station_id = entry_data["station_id"]
|
|
121
|
+
self.variable_name = entry_data["variable_name"]
|
|
122
|
+
self.variable_id = entry_data["variable_id"]
|
|
123
|
+
self.meteocat_forecast = MeteocatForecast(self.api_key)
|
|
124
|
+
|
|
126
125
|
super().__init__(
|
|
127
126
|
hass,
|
|
128
127
|
_LOGGER,
|
|
@@ -131,12 +130,7 @@ class MeteocatEntityCoordinator(DataUpdateCoordinator):
|
|
|
131
130
|
)
|
|
132
131
|
|
|
133
132
|
async def _async_update_data(self) -> Dict:
|
|
134
|
-
"""
|
|
135
|
-
Actualiza los datos de las entidades de predicción desde la API de Meteocat.
|
|
136
|
-
|
|
137
|
-
Returns:
|
|
138
|
-
dict: Datos actualizados de predicción horaria y diaria.
|
|
139
|
-
"""
|
|
133
|
+
"""Actualiza los datos de las entidades de predicción desde la API de Meteocat."""
|
|
140
134
|
try:
|
|
141
135
|
hourly_forecast = await self.meteocat_forecast.get_prediccion_horaria(self.town_id)
|
|
142
136
|
daily_forecast = await self.meteocat_forecast.get_prediccion_diaria(self.town_id)
|
|
@@ -3,7 +3,14 @@ from __future__ import annotations
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import logging
|
|
5
5
|
from homeassistant.components.weather import WeatherEntity
|
|
6
|
-
from homeassistant.const import
|
|
6
|
+
from homeassistant.const import (
|
|
7
|
+
DEGREE,
|
|
8
|
+
PERCENTAGE,
|
|
9
|
+
UnitOfPressure,
|
|
10
|
+
UnitOfSpeed,
|
|
11
|
+
UnitOfTemperature,
|
|
12
|
+
UnitOfVolumetricFlux,
|
|
13
|
+
)
|
|
7
14
|
|
|
8
15
|
from .const import (
|
|
9
16
|
DOMAIN,
|
|
@@ -38,7 +45,7 @@ class MeteocatWeatherEntity(WeatherEntity):
|
|
|
38
45
|
def __init__(self, coordinator: MeteocatEntityCoordinator):
|
|
39
46
|
"""Inicializa la entidad MeteocatWeather."""
|
|
40
47
|
self._coordinator = coordinator
|
|
41
|
-
self._attr_temperature_unit =
|
|
48
|
+
self._attr_temperature_unit = UnitOfTemperature.CELSIUS
|
|
42
49
|
self._data = {}
|
|
43
50
|
|
|
44
51
|
async def async_update(self):
|
|
@@ -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.7", "packaging>=20.3", "wrapt>=1.14.0"],
|
|
11
|
+
"version": "0.1.23"
|
|
12
12
|
}
|
|
@@ -11,7 +11,14 @@ from homeassistant.components.sensor import (
|
|
|
11
11
|
from homeassistant.core import callback
|
|
12
12
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
13
13
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
14
|
-
from homeassistant.const import
|
|
14
|
+
from homeassistant.const import (
|
|
15
|
+
DEGREE,
|
|
16
|
+
PERCENTAGE,
|
|
17
|
+
UnitOfPressure,
|
|
18
|
+
UnitOfSpeed,
|
|
19
|
+
UnitOfTemperature,
|
|
20
|
+
UnitOfVolumetricFlux,
|
|
21
|
+
)
|
|
15
22
|
|
|
16
23
|
from .const import (
|
|
17
24
|
DOMAIN,
|
|
@@ -25,11 +32,7 @@ from .const import (
|
|
|
25
32
|
MAX_TEMPERATURE,
|
|
26
33
|
MIN_TEMPERATURE,
|
|
27
34
|
WIND_GUST,
|
|
28
|
-
|
|
29
|
-
PRESSURE_UNIT,
|
|
30
|
-
PRECIPITATION_UNIT,
|
|
31
|
-
UV_INDEX_UNIT,
|
|
32
|
-
WIND_DIRECTION_UNIT,
|
|
35
|
+
VARIABLE_CODE_MAPPING,
|
|
33
36
|
)
|
|
34
37
|
|
|
35
38
|
from .coordinator import MeteocatSensorCoordinator
|
|
@@ -47,14 +50,13 @@ SENSOR_TYPES: tuple[MeteocatSensorEntityDescription, ...] = (
|
|
|
47
50
|
icon="mdi:weather-windy",
|
|
48
51
|
device_class=SensorDeviceClass.WIND_SPEED,
|
|
49
52
|
state_class=SensorStateClass.MEASUREMENT,
|
|
50
|
-
native_unit_of_measurement=
|
|
53
|
+
native_unit_of_measurement=UnitOfSpeed.METERS_PER_SECOND,
|
|
51
54
|
),
|
|
52
55
|
MeteocatSensorEntityDescription(
|
|
53
56
|
key=WIND_DIRECTION,
|
|
54
57
|
name="Wind Direction",
|
|
55
58
|
icon="mdi:compass",
|
|
56
59
|
device_class=None,
|
|
57
|
-
native_unit_of_measurement=WIND_DIRECTION_UNIT,
|
|
58
60
|
),
|
|
59
61
|
MeteocatSensorEntityDescription(
|
|
60
62
|
key=TEMPERATURE,
|
|
@@ -78,7 +80,7 @@ SENSOR_TYPES: tuple[MeteocatSensorEntityDescription, ...] = (
|
|
|
78
80
|
icon="mdi:gauge",
|
|
79
81
|
device_class=SensorDeviceClass.ATMOSPHERIC_PRESSURE,
|
|
80
82
|
state_class=SensorStateClass.MEASUREMENT,
|
|
81
|
-
native_unit_of_measurement=
|
|
83
|
+
native_unit_of_measurement=UnitOfPressure.HPA,
|
|
82
84
|
),
|
|
83
85
|
MeteocatSensorEntityDescription(
|
|
84
86
|
key=PRECIPITATION,
|
|
@@ -86,14 +88,12 @@ SENSOR_TYPES: tuple[MeteocatSensorEntityDescription, ...] = (
|
|
|
86
88
|
icon="mdi:weather-rainy",
|
|
87
89
|
device_class=None,
|
|
88
90
|
state_class=SensorStateClass.MEASUREMENT,
|
|
89
|
-
native_unit_of_measurement=
|
|
91
|
+
native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
|
90
92
|
),
|
|
91
93
|
MeteocatSensorEntityDescription(
|
|
92
94
|
key=UV_INDEX,
|
|
93
95
|
name="UV Index",
|
|
94
|
-
icon="mdi:
|
|
95
|
-
state_class=SensorStateClass.MEASUREMENT,
|
|
96
|
-
native_unit_of_measurement=UV_INDEX_UNIT,
|
|
96
|
+
icon="mdi:weather-sunny",
|
|
97
97
|
),
|
|
98
98
|
MeteocatSensorEntityDescription(
|
|
99
99
|
key=MAX_TEMPERATURE,
|
|
@@ -117,7 +117,7 @@ SENSOR_TYPES: tuple[MeteocatSensorEntityDescription, ...] = (
|
|
|
117
117
|
icon="mdi:weather-windy",
|
|
118
118
|
device_class=SensorDeviceClass.WIND_SPEED,
|
|
119
119
|
state_class=SensorStateClass.MEASUREMENT,
|
|
120
|
-
native_unit_of_measurement=
|
|
120
|
+
native_unit_of_measurement=UnitOfSpeed.METERS_PER_SECOND,
|
|
121
121
|
),
|
|
122
122
|
)
|
|
123
123
|
|
|
@@ -155,25 +155,40 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
|
|
|
155
155
|
@property
|
|
156
156
|
def native_value(self):
|
|
157
157
|
"""Return the state of the sensor."""
|
|
158
|
-
|
|
158
|
+
sensor_code = next(
|
|
159
|
+
(code for code, key in VARIABLE_CODE_MAPPING.items() if key == self.entity_description.key),
|
|
160
|
+
None,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
if sensor_code is not None:
|
|
164
|
+
variable_data = next(
|
|
165
|
+
(var for var in self.coordinator.data.get("variables", []) if var["codi"] == sensor_code),
|
|
166
|
+
None,
|
|
167
|
+
)
|
|
168
|
+
if variable_data:
|
|
169
|
+
# Asume que quieres el último valor registrado
|
|
170
|
+
latest_reading = variable_data["lectures"][-1]
|
|
171
|
+
value = latest_reading.get("valor")
|
|
159
172
|
|
|
160
|
-
|
|
161
|
-
|
|
173
|
+
# Convertir grados a direcciones cardinales para WIND_DIRECTION
|
|
174
|
+
if self.entity_description.key == WIND_DIRECTION and isinstance(value, (int, float)):
|
|
175
|
+
return self._convert_degrees_to_cardinal(value)
|
|
162
176
|
|
|
163
|
-
|
|
177
|
+
return value
|
|
178
|
+
|
|
179
|
+
return None
|
|
164
180
|
|
|
165
181
|
@staticmethod
|
|
166
|
-
def _convert_degrees_to_cardinal(degree: float
|
|
182
|
+
def _convert_degrees_to_cardinal(degree: float) -> str:
|
|
167
183
|
"""Convert degrees to cardinal direction."""
|
|
168
|
-
if degree is None:
|
|
169
|
-
return None
|
|
170
184
|
directions = [
|
|
171
185
|
"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
|
|
172
186
|
"S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N",
|
|
173
187
|
]
|
|
174
|
-
index =
|
|
188
|
+
index = round(degree / 22.5) % 16
|
|
175
189
|
return directions[index]
|
|
176
190
|
|
|
191
|
+
|
|
177
192
|
@property
|
|
178
193
|
def device_info(self) -> DeviceInfo:
|
|
179
194
|
"""Return the device info."""
|
|
@@ -181,10 +196,5 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
|
|
|
181
196
|
identifiers={(DOMAIN, self._town_id)},
|
|
182
197
|
name=self._town_name,
|
|
183
198
|
manufacturer="Meteocat",
|
|
184
|
-
model="Meteocat API"
|
|
185
|
-
additional_properties={
|
|
186
|
-
"Town ID": self._town_id,
|
|
187
|
-
"Station Name": self._station_name,
|
|
188
|
-
"Station ID": self._station_id,
|
|
189
|
-
},
|
|
199
|
+
model="Meteocat API"
|
|
190
200
|
)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
# version.py
|
|
2
|
-
__version__ = "0.1.
|
|
2
|
+
__version__ = "0.1.23"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meteocat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
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": {
|