meteocat 0.1.29 → 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,24 @@
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
+
11
+ ## [0.1.30](https://github.com/figorr/meteocat/compare/v0.1.29...v0.1.30) (2024-12-12)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * 0.1.30 ([2095760](https://github.com/figorr/meteocat/commit/20957606eae28a97e82607136f97fde1abe38f81))
17
+ * add precipitation accumulated sensor ([b05090a](https://github.com/figorr/meteocat/commit/b05090a563656123464d95b17b01ba2d7cada20f))
18
+ * add precipitation_accumulated ([261d877](https://github.com/figorr/meteocat/commit/261d877cf9f68a2106687900951731ba6a4539eb))
19
+ * delete precipitation test ([845d721](https://github.com/figorr/meteocat/commit/845d721ff4e49a2fe79c5cdcf92698d52a6cff36))
20
+ * fix variables json ([df403b1](https://github.com/figorr/meteocat/commit/df403b12ab12cd357f087dc1dceda30c51e4c8f0))
21
+
1
22
  ## [0.1.29](https://github.com/figorr/meteocat/compare/v0.1.28...v0.1.29) (2024-12-12)
2
23
 
3
24
 
@@ -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.29"
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."""
@@ -125,15 +125,6 @@ class MeteocatConfigFlow(ConfigFlow, domain=DOMAIN):
125
125
  async with aiofiles.open(variables_file, "w", encoding="utf-8") as file:
126
126
  await file.write(json.dumps({"variables": variables_data}, ensure_ascii=False, indent=4))
127
127
 
128
- # Actualizar la caché
129
- cache_data = {
130
- "symbols": symbols_data,
131
- "variables": variables_data
132
- }
133
-
134
- async with aiofiles.open(variables_file, "w", encoding="utf-8") as file:
135
- await file.write(json.dumps(cache_data, ensure_ascii=False, indent=4))
136
-
137
128
  _LOGGER.info(f"Variables guardadas en {variables_file}")
138
129
 
139
130
  # Buscar la variable de temperatura
@@ -16,10 +16,12 @@ TEMPERATURE = "temperature" # Temperatura
16
16
  HUMIDITY = "humidity" # Humedad relativa
17
17
  PRESSURE = "pressure" # Presión atmosférica
18
18
  PRECIPITATION = "precipitation" # Precipitación
19
+ PRECIPITATION_ACCUMULATED = "precipitation_accumulated" #Precipitación acumulada
19
20
  SOLAR_GLOBAL_IRRADIANCE = "solar_global_irradiance" # Irradiación solar global
20
21
  UV_INDEX = "uv_index" # UV
21
22
  MAX_TEMPERATURE = "max_temperature" # Temperatura máxima
22
23
  MIN_TEMPERATURE = "min_temperature" # Temperatura mínima
24
+ FEELS_LIKE = "feels_like" # Sensación térmica
23
25
  WIND_GUST = "wind_gust" # Racha de viento
24
26
  STATION_TIMESTAMP = "station_timestamp" # Código de tiempo de la estación
25
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.29"
10
+ "requirements": ["meteocatpy==0.0.15", "packaging>=20.3", "wrapt>=1.14.0"],
11
+ "version": "0.1.31"
12
12
  }
@@ -38,6 +38,7 @@ from .const import (
38
38
  HUMIDITY,
39
39
  PRESSURE,
40
40
  PRECIPITATION,
41
+ PRECIPITATION_ACCUMULATED,
41
42
  SOLAR_GLOBAL_IRRADIANCE,
42
43
  UV_INDEX,
43
44
  MAX_TEMPERATURE,
@@ -54,6 +55,7 @@ from .const import (
54
55
  UV_INDEX_CODE,
55
56
  MAX_TEMPERATURE_CODE,
56
57
  MIN_TEMPERATURE_CODE,
58
+ FEELS_LIKE,
57
59
  WIND_GUST_CODE,
58
60
  )
59
61
 
@@ -113,6 +115,14 @@ SENSOR_TYPES: tuple[MeteocatSensorEntityDescription, ...] = (
113
115
  state_class=SensorStateClass.MEASUREMENT,
114
116
  native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
115
117
  ),
118
+ MeteocatSensorEntityDescription(
119
+ key=PRECIPITATION_ACCUMULATED,
120
+ name="Precipitation Accumulated",
121
+ icon="mdi:weather-rainy",
122
+ device_class=SensorDeviceClass.PRECIPITATION,
123
+ state_class=SensorStateClass.MEASUREMENT,
124
+ native_unit_of_measurement="mm",
125
+ ),
116
126
  MeteocatSensorEntityDescription(
117
127
  key=SOLAR_GLOBAL_IRRADIANCE,
118
128
  name="Solar Global Irradiance",
@@ -142,6 +152,14 @@ SENSOR_TYPES: tuple[MeteocatSensorEntityDescription, ...] = (
142
152
  state_class=SensorStateClass.MEASUREMENT,
143
153
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
144
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
+ ),
145
163
  MeteocatSensorEntityDescription(
146
164
  key=WIND_GUST,
147
165
  name="Wind Gust",
@@ -253,6 +271,63 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
253
271
  if self.entity_description.key == STATION_ID:
254
272
  return self._station_id
255
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
+
256
331
  sensor_code = self.CODE_MAPPING.get(self.entity_description.key)
257
332
 
258
333
  if sensor_code is not None:
@@ -279,7 +354,8 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
279
354
  return self._convert_degrees_to_cardinal(value)
280
355
 
281
356
  return value
282
- # Lógica específica para el sensor de timestamp
357
+
358
+ # Lógica específica para el sensor de timestamp
283
359
  if self.entity_description.key == "station_timestamp":
284
360
  stations = self.coordinator.data or []
285
361
  for station in stations:
@@ -299,8 +375,31 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
299
375
  # Manejo de errores si el formato no es válido
300
376
  return None
301
377
 
302
- return None
378
+ # Nuevo sensor para la precipitación acumulada
379
+ if self.entity_description.key == "precipitation_accumulated":
380
+ stations = self.coordinator.data or []
381
+ total_precipitation = 0.0 # Usa float para permitir acumulación de decimales
303
382
 
383
+ for station in stations:
384
+ variables = station.get("variables", [])
385
+
386
+ # Filtramos por código de precipitación
387
+ variable_data = next(
388
+ (var for var in variables if var.get("codi") == PRECIPITATION_CODE),
389
+ None,
390
+ )
391
+
392
+ if variable_data:
393
+ # Sumamos las lecturas de precipitación
394
+ lectures = variable_data.get("lectures", [])
395
+ for lecture in lectures:
396
+ total_precipitation += float(lecture.get("valor", 0.0)) # Convertimos a float
397
+
398
+ _LOGGER.debug(f"Total precipitación acumulada: {total_precipitation} mm")
399
+ return total_precipitation
400
+
401
+ return None
402
+
304
403
  @staticmethod
305
404
  def _convert_degrees_to_cardinal(degree: float) -> str:
306
405
  """Convert degrees to cardinal direction."""
@@ -1,2 +1,2 @@
1
1
  # version.py
2
- __version__ = "0.1.29"
2
+ __version__ = "0.1.31"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meteocat",
3
- "version": "0.1.29",
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.29"
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"