meteocat 0.1.48 → 0.1.50

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,20 @@
1
+ ## [0.1.50](https://github.com/figorr/meteocat/compare/v0.1.49...v0.1.50) (2025-01-04)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 0.1.50 ([cbfc022](https://github.com/figorr/meteocat/commit/cbfc0228195762f7af306a85db4c03b287cd3c24))
7
+ * fix precipitation unit ([9e6d5aa](https://github.com/figorr/meteocat/commit/9e6d5aa85ce3450341d70e2edff9a13880c69a89))
8
+
9
+ ## [0.1.49](https://github.com/figorr/meteocat/compare/v0.1.48...v0.1.49) (2025-01-03)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * 0.1.49 ([81dea76](https://github.com/figorr/meteocat/commit/81dea7618fc1b3fd6aa4edff923720e424ca7f8d))
15
+ * add daily precipitation probability sensor ([4d59c3f](https://github.com/figorr/meteocat/commit/4d59c3f9480c09da678fd6ce7efa775619a17d86))
16
+ * add daily precipitation probability sensor ([c786f26](https://github.com/figorr/meteocat/commit/c786f26d36b8f17bb9512d405a5a2ba921a8b881))
17
+
1
18
  ## [0.1.48](https://github.com/figorr/meteocat/compare/v0.1.47...v0.1.48) (2025-01-03)
2
19
 
3
20
 
@@ -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.50"
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.50"
12
12
  }
@@ -23,6 +23,7 @@ from homeassistant.const import (
23
23
  UnitOfPressure,
24
24
  UnitOfSpeed,
25
25
  UnitOfTemperature,
26
+ UnitOfPrecipitationDepth,
26
27
  UnitOfVolumetricFlux,
27
28
  UnitOfIrradiance,
28
29
  )
@@ -40,6 +41,7 @@ from .const import (
40
41
  PRESSURE,
41
42
  PRECIPITATION,
42
43
  PRECIPITATION_ACCUMULATED,
44
+ PRECIPITATION_PROBABILITY,
43
45
  SOLAR_GLOBAL_IRRADIANCE,
44
46
  UV_INDEX,
45
47
  MAX_TEMPERATURE,
@@ -76,9 +78,13 @@ from .coordinator import (
76
78
  MeteocatConditionCoordinator,
77
79
  MeteocatTempForecastCoordinator,
78
80
  MeteocatEntityCoordinator,
81
+ DailyForecastCoordinator,
79
82
  MeteocatUviCoordinator,
80
83
  )
81
84
 
85
+ # Definir la zona horaria local
86
+ TIMEZONE = ZoneInfo("Europe/Madrid")
87
+
82
88
  _LOGGER = logging.getLogger(__name__)
83
89
 
84
90
  @dataclass
@@ -129,9 +135,9 @@ SENSOR_TYPES: tuple[MeteocatSensorEntityDescription, ...] = (
129
135
  key=PRECIPITATION,
130
136
  translation_key="precipitation",
131
137
  icon="mdi:weather-rainy",
132
- device_class=None,
138
+ device_class=SensorDeviceClass.PRECIPITATION,
133
139
  state_class=SensorStateClass.MEASUREMENT,
134
- native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
140
+ native_unit_of_measurement="mm",
135
141
  ),
136
142
  MeteocatSensorEntityDescription(
137
143
  key=PRECIPITATION_ACCUMULATED,
@@ -141,6 +147,13 @@ SENSOR_TYPES: tuple[MeteocatSensorEntityDescription, ...] = (
141
147
  state_class=SensorStateClass.MEASUREMENT,
142
148
  native_unit_of_measurement="mm",
143
149
  ),
150
+ MeteocatSensorEntityDescription(
151
+ key=PRECIPITATION_PROBABILITY,
152
+ translation_key="precipitation_probability",
153
+ icon="mdi:weather-rainy",
154
+ device_class=None,
155
+ native_unit_of_measurement=PERCENTAGE,
156
+ ),
144
157
  MeteocatSensorEntityDescription(
145
158
  key=SOLAR_GLOBAL_IRRADIANCE,
146
159
  translation_key="solar_global_irradiance",
@@ -268,6 +281,7 @@ async def async_setup_entry(hass, entry, async_add_entities: AddEntitiesCallback
268
281
  uvi_file_coordinator = entry_data.get("uvi_file_coordinator")
269
282
  static_sensor_coordinator = entry_data.get("static_sensor_coordinator")
270
283
  condition_coordinator = entry_data.get("condition_coordinator")
284
+ daily_forecast_coordinator = entry_data.get("daily_forecast_coordinator")
271
285
  temp_forecast_coordinator = entry_data.get("temp_forecast_coordinator")
272
286
  entity_coordinator = entry_data.get("entity_coordinator")
273
287
  uvi_coordinator = entry_data.get("uvi_coordinator")
@@ -307,6 +321,13 @@ async def async_setup_entry(hass, entry, async_add_entities: AddEntitiesCallback
307
321
  if description.key in {MAX_TEMPERATURE_FORECAST, MIN_TEMPERATURE_FORECAST}
308
322
  )
309
323
 
324
+ # Sensor precipitación probabilidad
325
+ async_add_entities(
326
+ MeteocatPrecipitationProbabilitySensor(daily_forecast_coordinator, description, entry_data)
327
+ for description in SENSOR_TYPES
328
+ if description.key == PRECIPITATION_PROBABILITY
329
+ )
330
+
310
331
  # Sensores de estado de los archivos de previsión horaria
311
332
  async_add_entities(
312
333
  MeteocatHourlyForecastStatusSensor(entity_coordinator, description, entry_data)
@@ -750,12 +771,12 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
750
771
  )
751
772
 
752
773
  class MeteocatTempForecast(CoordinatorEntity[MeteocatTempForecastCoordinator], SensorEntity):
753
- """Representation of a Meteocat UV Index sensor."""
774
+ """Representation of a Meteocat Min and Max Temperature sensors."""
754
775
 
755
776
  _attr_has_entity_name = True # Activa el uso de nombres basados en el dispositivo
756
777
 
757
778
  def __init__(self, temp_forecast_coordinator, description, entry_data):
758
- """Initialize the UV Index sensor."""
779
+ """Initialize the Mina and Max Temperature sensors."""
759
780
  super().__init__(temp_forecast_coordinator)
760
781
  self.entity_description = description
761
782
  self._town_name = entry_data["town_name"]
@@ -796,6 +817,46 @@ class MeteocatTempForecast(CoordinatorEntity[MeteocatTempForecastCoordinator], S
796
817
  model="Meteocat API",
797
818
  )
798
819
 
820
+ class MeteocatPrecipitationProbabilitySensor(CoordinatorEntity[DailyForecastCoordinator], SensorEntity):
821
+ """Representation of a Meteocat precipitation probability sensor."""
822
+
823
+ _attr_has_entity_name = True # Enable device-based naming
824
+
825
+ def __init__(self, daily_forecast_coordinator, description, entry_data):
826
+ super().__init__(daily_forecast_coordinator)
827
+ self.entity_description = description
828
+ self._town_name = entry_data["town_name"]
829
+ self._town_id = entry_data["town_id"]
830
+ self._station_id = entry_data["station_id"]
831
+
832
+ self._attr_unique_id = f"sensor.{DOMAIN}_{self._town_id}_{self.entity_description.key}"
833
+ self._attr_entity_category = getattr(description, "entity_category", None)
834
+
835
+ _LOGGER.debug(
836
+ "Initializing sensor: %s, Unique ID: %s",
837
+ self.entity_description.name,
838
+ self._attr_unique_id,
839
+ )
840
+
841
+ @property
842
+ def native_value(self):
843
+ """Retorna la probabilidad de precipitación del día actual."""
844
+ forecast = self.coordinator.get_forecast_for_today()
845
+ if forecast:
846
+ precipitation = forecast.get("variables", {}).get("precipitacio", {}).get("valor", None)
847
+ if precipitation is not None and float(precipitation) >= 0:
848
+ return float(precipitation)
849
+ return None
850
+
851
+ @property
852
+ def device_info(self) -> DeviceInfo:
853
+ return DeviceInfo(
854
+ identifiers={(DOMAIN, self._town_id)},
855
+ name="Meteocat " + self._station_id + " " + self._town_name,
856
+ manufacturer="Meteocat",
857
+ model="Meteocat API",
858
+ )
859
+
799
860
  class MeteocatHourlyForecastStatusSensor(CoordinatorEntity[MeteocatEntityCoordinator], SensorEntity):
800
861
 
801
862
  _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.50"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meteocat",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
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.50"
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"