meteocat 0.1.22 → 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/CHANGELOG.md +9 -0
- package/custom_components/meteocat/__init__.py +1 -1
- package/custom_components/meteocat/const.py +25 -23
- package/custom_components/meteocat/entity.py +9 -2
- package/custom_components/meteocat/manifest.json +1 -1
- package/custom_components/meteocat/sensor.py +36 -21
- 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,12 @@
|
|
|
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
|
+
|
|
1
10
|
## [0.1.22](https://github.com/figorr/meteocat/compare/v0.1.21...v0.1.22) (2024-12-07)
|
|
2
11
|
|
|
3
12
|
|
|
@@ -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 = {
|
|
@@ -45,8 +36,19 @@ CONDITION_MAPPING = {
|
|
|
45
36
|
"snow-rainy": [27, 29, 30],
|
|
46
37
|
}
|
|
47
38
|
|
|
48
|
-
#
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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,
|
|
52
51
|
}
|
|
52
|
+
|
|
53
|
+
# Platforms
|
|
54
|
+
PLATFORMS = ["sensor"]
|
|
@@ -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):
|
|
@@ -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
96
|
icon="mdi:weather-sunny",
|
|
95
|
-
state_class=SensorStateClass.MEASUREMENT,
|
|
96
|
-
native_unit_of_measurement=UV_INDEX_UNIT,
|
|
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."""
|
|
@@ -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": {
|