meteocat 0.1.48 → 0.1.49

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,12 @@
1
+ ## [0.1.49](https://github.com/figorr/meteocat/compare/v0.1.48...v0.1.49) (2025-01-03)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 0.1.49 ([81dea76](https://github.com/figorr/meteocat/commit/81dea7618fc1b3fd6aa4edff923720e424ca7f8d))
7
+ * add daily precipitation probability sensor ([4d59c3f](https://github.com/figorr/meteocat/commit/4d59c3f9480c09da678fd6ce7efa775619a17d86))
8
+ * add daily precipitation probability sensor ([c786f26](https://github.com/figorr/meteocat/commit/c786f26d36b8f17bb9512d405a5a2ba921a8b881))
9
+
1
10
  ## [0.1.48](https://github.com/figorr/meteocat/compare/v0.1.47...v0.1.48) (2025-01-03)
2
11
 
3
12
 
@@ -25,7 +25,7 @@ from .const import DOMAIN, PLATFORMS
25
25
  _LOGGER = logging.getLogger(__name__)
26
26
 
27
27
  # Versión
28
- __version__ = "0.1.48"
28
+ __version__ = "0.1.49"
29
29
 
30
30
  def safe_remove(path: Path, is_folder: bool = False):
31
31
  """Elimina de forma segura un archivo o carpeta si existe."""
@@ -40,6 +40,7 @@ HUMIDITY = "humidity" # Humedad relativa
40
40
  PRESSURE = "pressure" # Presión atmosférica
41
41
  PRECIPITATION = "precipitation" # Precipitación
42
42
  PRECIPITATION_ACCUMULATED = "precipitation_accumulated" #Precipitación acumulada
43
+ PRECIPITATION_PROBABILITY = "precipitation_probability" #Precipitación probabilidad
43
44
  SOLAR_GLOBAL_IRRADIANCE = "solar_global_irradiance" # Irradiación solar global
44
45
  UV_INDEX = "uv_index" # UV
45
46
  MAX_TEMPERATURE = "max_temperature" # Temperatura máxima
@@ -8,5 +8,5 @@
8
8
  "documentation": "https://gitlab.com/figorr/meteocat",
9
9
  "loggers": ["meteocatpy"],
10
10
  "requirements": ["meteocatpy==0.0.17", "packaging>=20.3", "wrapt>=1.14.0"],
11
- "version": "0.1.48"
11
+ "version": "0.1.49"
12
12
  }
@@ -40,6 +40,7 @@ from .const import (
40
40
  PRESSURE,
41
41
  PRECIPITATION,
42
42
  PRECIPITATION_ACCUMULATED,
43
+ PRECIPITATION_PROBABILITY,
43
44
  SOLAR_GLOBAL_IRRADIANCE,
44
45
  UV_INDEX,
45
46
  MAX_TEMPERATURE,
@@ -76,9 +77,13 @@ from .coordinator import (
76
77
  MeteocatConditionCoordinator,
77
78
  MeteocatTempForecastCoordinator,
78
79
  MeteocatEntityCoordinator,
80
+ DailyForecastCoordinator,
79
81
  MeteocatUviCoordinator,
80
82
  )
81
83
 
84
+ # Definir la zona horaria local
85
+ TIMEZONE = ZoneInfo("Europe/Madrid")
86
+
82
87
  _LOGGER = logging.getLogger(__name__)
83
88
 
84
89
  @dataclass
@@ -141,6 +146,13 @@ SENSOR_TYPES: tuple[MeteocatSensorEntityDescription, ...] = (
141
146
  state_class=SensorStateClass.MEASUREMENT,
142
147
  native_unit_of_measurement="mm",
143
148
  ),
149
+ MeteocatSensorEntityDescription(
150
+ key=PRECIPITATION_PROBABILITY,
151
+ translation_key="precipitation_probability",
152
+ icon="mdi:weather-rainy",
153
+ device_class=None,
154
+ native_unit_of_measurement=PERCENTAGE,
155
+ ),
144
156
  MeteocatSensorEntityDescription(
145
157
  key=SOLAR_GLOBAL_IRRADIANCE,
146
158
  translation_key="solar_global_irradiance",
@@ -268,6 +280,7 @@ async def async_setup_entry(hass, entry, async_add_entities: AddEntitiesCallback
268
280
  uvi_file_coordinator = entry_data.get("uvi_file_coordinator")
269
281
  static_sensor_coordinator = entry_data.get("static_sensor_coordinator")
270
282
  condition_coordinator = entry_data.get("condition_coordinator")
283
+ daily_forecast_coordinator = entry_data.get("daily_forecast_coordinator")
271
284
  temp_forecast_coordinator = entry_data.get("temp_forecast_coordinator")
272
285
  entity_coordinator = entry_data.get("entity_coordinator")
273
286
  uvi_coordinator = entry_data.get("uvi_coordinator")
@@ -307,6 +320,13 @@ async def async_setup_entry(hass, entry, async_add_entities: AddEntitiesCallback
307
320
  if description.key in {MAX_TEMPERATURE_FORECAST, MIN_TEMPERATURE_FORECAST}
308
321
  )
309
322
 
323
+ # Sensor precipitación probabilidad
324
+ async_add_entities(
325
+ MeteocatPrecipitationProbabilitySensor(daily_forecast_coordinator, description, entry_data)
326
+ for description in SENSOR_TYPES
327
+ if description.key == PRECIPITATION_PROBABILITY
328
+ )
329
+
310
330
  # Sensores de estado de los archivos de previsión horaria
311
331
  async_add_entities(
312
332
  MeteocatHourlyForecastStatusSensor(entity_coordinator, description, entry_data)
@@ -750,12 +770,12 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
750
770
  )
751
771
 
752
772
  class MeteocatTempForecast(CoordinatorEntity[MeteocatTempForecastCoordinator], SensorEntity):
753
- """Representation of a Meteocat UV Index sensor."""
773
+ """Representation of a Meteocat Min and Max Temperature sensors."""
754
774
 
755
775
  _attr_has_entity_name = True # Activa el uso de nombres basados en el dispositivo
756
776
 
757
777
  def __init__(self, temp_forecast_coordinator, description, entry_data):
758
- """Initialize the UV Index sensor."""
778
+ """Initialize the Mina and Max Temperature sensors."""
759
779
  super().__init__(temp_forecast_coordinator)
760
780
  self.entity_description = description
761
781
  self._town_name = entry_data["town_name"]
@@ -796,6 +816,46 @@ class MeteocatTempForecast(CoordinatorEntity[MeteocatTempForecastCoordinator], S
796
816
  model="Meteocat API",
797
817
  )
798
818
 
819
+ class MeteocatPrecipitationProbabilitySensor(CoordinatorEntity[DailyForecastCoordinator], SensorEntity):
820
+ """Representation of a Meteocat precipitation probability sensor."""
821
+
822
+ _attr_has_entity_name = True # Enable device-based naming
823
+
824
+ def __init__(self, daily_forecast_coordinator, description, entry_data):
825
+ super().__init__(daily_forecast_coordinator)
826
+ self.entity_description = description
827
+ self._town_name = entry_data["town_name"]
828
+ self._town_id = entry_data["town_id"]
829
+ self._station_id = entry_data["station_id"]
830
+
831
+ self._attr_unique_id = f"sensor.{DOMAIN}_{self._town_id}_{self.entity_description.key}"
832
+ self._attr_entity_category = getattr(description, "entity_category", None)
833
+
834
+ _LOGGER.debug(
835
+ "Initializing sensor: %s, Unique ID: %s",
836
+ self.entity_description.name,
837
+ self._attr_unique_id,
838
+ )
839
+
840
+ @property
841
+ def native_value(self):
842
+ """Retorna la probabilidad de precipitación del día actual."""
843
+ forecast = self.coordinator.get_forecast_for_today()
844
+ if forecast:
845
+ precipitation = forecast.get("variables", {}).get("precipitacio", {}).get("valor", None)
846
+ if precipitation is not None and float(precipitation) >= 0:
847
+ return float(precipitation)
848
+ return None
849
+
850
+ @property
851
+ def device_info(self) -> DeviceInfo:
852
+ return DeviceInfo(
853
+ identifiers={(DOMAIN, self._town_id)},
854
+ name="Meteocat " + self._station_id + " " + self._town_name,
855
+ manufacturer="Meteocat",
856
+ model="Meteocat API",
857
+ )
858
+
799
859
  class MeteocatHourlyForecastStatusSensor(CoordinatorEntity[MeteocatEntityCoordinator], SensorEntity):
800
860
 
801
861
  _attr_has_entity_name = True # Activa el uso de nombres basados en el dispositivo
@@ -70,6 +70,9 @@
70
70
  "precipitation_accumulated": {
71
71
  "name": "Precipitation Accumulated"
72
72
  },
73
+ "precipitation_probability": {
74
+ "name": "Precipitation Probability"
75
+ },
73
76
  "solar_global_irradiance": {
74
77
  "name": "Solar Global Irradiance"
75
78
  },
@@ -70,6 +70,9 @@
70
70
  "precipitation_accumulated": {
71
71
  "name": "Precipitació Acumulada"
72
72
  },
73
+ "precipitation_probability": {
74
+ "name": "Precipitació Probabilitat"
75
+ },
73
76
  "solar_global_irradiance": {
74
77
  "name": "Irradiació Solar Global"
75
78
  },
@@ -70,6 +70,9 @@
70
70
  "precipitation_accumulated": {
71
71
  "name": "Precipitation Accumulated"
72
72
  },
73
+ "precipitation_probability": {
74
+ "name": "Precipitation Probability"
75
+ },
73
76
  "solar_global_irradiance": {
74
77
  "name": "Solar Global Irradiance"
75
78
  },
@@ -70,6 +70,9 @@
70
70
  "precipitation_accumulated": {
71
71
  "name": "Precipitación Acumulada"
72
72
  },
73
+ "precipitation_probability": {
74
+ "name": "Precipitación Probabilidad"
75
+ },
73
76
  "solar_global_irradiance": {
74
77
  "name": "Irradiación Solar Global"
75
78
  },
@@ -1,2 +1,2 @@
1
1
  # version.py
2
- __version__ = "0.1.48"
2
+ __version__ = "0.1.49"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meteocat",
3
- "version": "0.1.48",
3
+ "version": "0.1.49",
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.48"
3
+ version = "0.1.49"
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"