meteocat 0.1.30 → 0.1.31

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.31](https://github.com/figorr/meteocat/compare/v0.1.30...v0.1.31) (2024-12-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 0.1.31 ([6d49197](https://github.com/figorr/meteocat/commit/6d4919717b09d4e38a3225bf9a33d1400a0227d0))
7
+ * add feels like sensor ([caca7a0](https://github.com/figorr/meteocat/commit/caca7a0d2bc53969db584eda2e2818321f3930fc))
8
+ * add feels like sensor ([ccecfae](https://github.com/figorr/meteocat/commit/ccecfae83f1a2e72a2438cf6a189bf5d5186d6b3))
9
+ * bump meteocatpy to 0.0.15 ([8d08b6f](https://github.com/figorr/meteocat/commit/8d08b6f66ac2ce5b029569a1538d524d3d7f50dc))
10
+
1
11
  ## [0.1.30](https://github.com/figorr/meteocat/compare/v0.1.29...v0.1.30) (2024-12-12)
2
12
 
3
13
 
@@ -14,7 +14,7 @@ from .const import DOMAIN, PLATFORMS
14
14
  _LOGGER = logging.getLogger(__name__)
15
15
 
16
16
  # Versión
17
- __version__ = "0.1.30"
17
+ __version__ = "0.1.31"
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."""
@@ -21,6 +21,7 @@ SOLAR_GLOBAL_IRRADIANCE = "solar_global_irradiance" # Irradiación solar global
21
21
  UV_INDEX = "uv_index" # UV
22
22
  MAX_TEMPERATURE = "max_temperature" # Temperatura máxima
23
23
  MIN_TEMPERATURE = "min_temperature" # Temperatura mínima
24
+ FEELS_LIKE = "feels_like" # Sensación térmica
24
25
  WIND_GUST = "wind_gust" # Racha de viento
25
26
  STATION_TIMESTAMP = "station_timestamp" # Código de tiempo de la estación
26
27
 
@@ -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.14", "packaging>=20.3", "wrapt>=1.14.0"],
11
- "version": "0.1.30"
10
+ "requirements": ["meteocatpy==0.0.15", "packaging>=20.3", "wrapt>=1.14.0"],
11
+ "version": "0.1.31"
12
12
  }
@@ -55,6 +55,7 @@ from .const import (
55
55
  UV_INDEX_CODE,
56
56
  MAX_TEMPERATURE_CODE,
57
57
  MIN_TEMPERATURE_CODE,
58
+ FEELS_LIKE,
58
59
  WIND_GUST_CODE,
59
60
  )
60
61
 
@@ -151,6 +152,14 @@ SENSOR_TYPES: tuple[MeteocatSensorEntityDescription, ...] = (
151
152
  state_class=SensorStateClass.MEASUREMENT,
152
153
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
153
154
  ),
155
+ MeteocatSensorEntityDescription(
156
+ key=FEELS_LIKE,
157
+ name="Feels Like",
158
+ icon="mdi:sun-thermometer",
159
+ device_class=SensorDeviceClass.TEMPERATURE,
160
+ state_class=SensorStateClass.MEASUREMENT,
161
+ native_unit_of_measurement=UnitOfTemperature.CELSIUS,
162
+ ),
154
163
  MeteocatSensorEntityDescription(
155
164
  key=WIND_GUST,
156
165
  name="Wind Gust",
@@ -262,6 +271,63 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
262
271
  if self.entity_description.key == STATION_ID:
263
272
  return self._station_id
264
273
  # Información dinámica
274
+
275
+ if self.entity_description.key == FEELS_LIKE:
276
+ stations = self.coordinator.data or []
277
+
278
+ # Variables necesarias
279
+ temperature = None
280
+ humidity = None
281
+ wind_speed = None
282
+
283
+ # Obtener valores de las variables
284
+ for station in stations:
285
+ variables = station.get("variables", [])
286
+ for var in variables:
287
+ code = var.get("codi")
288
+ lectures = var.get("lectures", [])
289
+ if not lectures:
290
+ continue
291
+ latest_reading = lectures[-1].get("valor")
292
+
293
+ if code == TEMPERATURE_CODE:
294
+ temperature = float(latest_reading)
295
+ elif code == HUMIDITY_CODE:
296
+ humidity = float(latest_reading)
297
+ elif code == WIND_SPEED_CODE:
298
+ wind_speed = float(latest_reading)
299
+
300
+ # Verificar que todas las variables necesarias están presentes
301
+ if temperature is not None and humidity is not None and wind_speed is not None:
302
+ # Cálculo del windchill
303
+ windchill = (
304
+ 13.1267 +
305
+ 0.6215 * temperature -
306
+ 11.37 * (wind_speed ** 0.16) +
307
+ 0.3965 * temperature * (wind_speed ** 0.16)
308
+ )
309
+
310
+ # Cálculo del heat_index
311
+ heat_index = (
312
+ -8.78469476 +
313
+ 1.61139411 * temperature +
314
+ 2.338548839 * humidity -
315
+ 0.14611605 * temperature * humidity -
316
+ 0.012308094 * (temperature ** 2) -
317
+ 0.016424828 * (humidity ** 2) +
318
+ 0.002211732 * (temperature ** 2) * humidity +
319
+ 0.00072546 * temperature * (humidity ** 2) -
320
+ 0.000003582 * (temperature ** 2) * (humidity ** 2)
321
+ )
322
+
323
+ # Lógica de selección
324
+ if -50 <= temperature <= 10:
325
+ return round(windchill, 2)
326
+ elif temperature > 26 and humidity > 40:
327
+ return round(heat_index, 2)
328
+ else:
329
+ return round(temperature, 2)
330
+
265
331
  sensor_code = self.CODE_MAPPING.get(self.entity_description.key)
266
332
 
267
333
  if sensor_code is not None:
@@ -288,7 +354,8 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
288
354
  return self._convert_degrees_to_cardinal(value)
289
355
 
290
356
  return value
291
- # Lógica específica para el sensor de timestamp
357
+
358
+ # Lógica específica para el sensor de timestamp
292
359
  if self.entity_description.key == "station_timestamp":
293
360
  stations = self.coordinator.data or []
294
361
  for station in stations:
@@ -330,14 +397,9 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
330
397
 
331
398
  _LOGGER.debug(f"Total precipitación acumulada: {total_precipitation} mm")
332
399
  return total_precipitation
333
-
400
+
334
401
  return None
335
-
336
- @property
337
- def precipitation_accumulated(self):
338
- """Return the accumulated precipitation state of the sensor."""
339
402
 
340
-
341
403
  @staticmethod
342
404
  def _convert_degrees_to_cardinal(degree: float) -> str:
343
405
  """Convert degrees to cardinal direction."""
@@ -1,2 +1,2 @@
1
1
  # version.py
2
- __version__ = "0.1.30"
2
+ __version__ = "0.1.31"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meteocat",
3
- "version": "0.1.30",
3
+ "version": "0.1.31",
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.30"
3
+ version = "0.1.31"
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"