meteocat 2.2.7 → 3.0.0

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.
@@ -2,11 +2,23 @@ from __future__ import annotations
2
2
 
3
3
  import logging
4
4
  from datetime import datetime
5
+ from pathlib import Path
6
+ from homeassistant.core import HomeAssistant
5
7
  from homeassistant.util.dt import as_local, as_utc, start_of_local_day
6
8
  from homeassistant.helpers.sun import get_astral_event_date
7
9
 
8
10
  _LOGGER = logging.getLogger(__name__)
9
11
 
12
+ # Ruta base para guardar archivos persistentes que se descargan de la API y que son utilizados por los coordinadores
13
+ def get_storage_dir(hass: HomeAssistant, subdir: str | None = None) -> Path:
14
+ """Devuelve una ruta persistente en config/meteocat_files[/subdir]."""
15
+ base_dir = Path(hass.config.path("meteocat_files"))
16
+ if subdir:
17
+ base_dir = base_dir / subdir
18
+ base_dir.mkdir(parents=True, exist_ok=True)
19
+ return base_dir
20
+
21
+ # Cálculo de amanecer y atardecer para definir cuando es de noche
10
22
  def get_sun_times(hass, current_time=None):
11
23
  """Obtén las horas de amanecer y atardecer para el día actual."""
12
24
  if current_time is None:
@@ -1,13 +1,24 @@
1
1
  {
2
- "domain": "meteocat",
3
- "name": "Meteocat",
4
- "codeowners": ["@figorr"],
5
- "config_flow": true,
6
- "dependencies": ["persistent_notification", "http"],
7
- "documentation": "https://github.com/figorr/meteocat",
8
- "iot_class": "cloud_polling",
9
- "issue_tracker": "https://github.com/figorr/meteocat/issues",
10
- "loggers": ["meteocatpy"],
11
- "requirements": ["meteocatpy==1.0.1", "packaging>=20.3", "wrapt>=1.14.0"],
12
- "version": "2.2.7"
2
+ "domain": "meteocat",
3
+ "name": "Meteocat",
4
+ "codeowners": [
5
+ "@figorr"
6
+ ],
7
+ "config_flow": true,
8
+ "dependencies": [
9
+ "persistent_notification",
10
+ "http"
11
+ ],
12
+ "documentation": "https://github.com/figorr/meteocat",
13
+ "iot_class": "cloud_polling",
14
+ "issue_tracker": "https://github.com/figorr/meteocat/issues",
15
+ "loggers": [
16
+ "meteocatpy"
17
+ ],
18
+ "requirements": [
19
+ "meteocatpy==1.0.1",
20
+ "packaging>=20.3",
21
+ "wrapt>=1.14.0"
22
+ ],
23
+ "version": "3.0.0"
13
24
  }
@@ -43,6 +43,8 @@ class MeteocatOptionsFlowHandler(OptionsFlow):
43
43
  return await self.async_step_update_api_and_limits()
44
44
  elif user_input["option"] == "update_limits_only":
45
45
  return await self.async_step_update_limits_only()
46
+ elif user_input["option"] == "regenerate_assets":
47
+ return await self.async_step_confirm_regenerate_assets()
46
48
 
47
49
  return self.async_show_form(
48
50
  step_id="init",
@@ -51,7 +53,8 @@ class MeteocatOptionsFlowHandler(OptionsFlow):
51
53
  SelectSelectorConfig(
52
54
  options=[
53
55
  "update_api_and_limits",
54
- "update_limits_only"
56
+ "update_limits_only",
57
+ "regenerate_assets"
55
58
  ],
56
59
  translation_key="option"
57
60
  )
@@ -173,4 +176,45 @@ class MeteocatOptionsFlowHandler(OptionsFlow):
173
176
  })
174
177
  return self.async_show_form(
175
178
  step_id="update_limits_only", data_schema=schema, errors=errors
176
- )
179
+ )
180
+
181
+ async def async_step_confirm_regenerate_assets(self, user_input: dict | None = None):
182
+ """Confirma si el usuario realmente quiere regenerar los assets."""
183
+ if user_input is not None:
184
+ if user_input.get("confirm") is True:
185
+ return await self.async_step_regenerate_assets()
186
+ else:
187
+ # Volver al menú inicial si el usuario cancela
188
+ return await self.async_step_init()
189
+
190
+ schema = vol.Schema({
191
+ vol.Required("confirm", default=False): bool
192
+ })
193
+ return self.async_show_form(
194
+ step_id="confirm_regenerate_assets",
195
+ data_schema=schema,
196
+ description_placeholders={
197
+ "warning": "Esto regenerará los archivos faltantes de towns.json, stations.json, variables.json, symbols.json y stations_<town_id>.json. ¿Desea continuar?"
198
+ }
199
+ )
200
+
201
+ async def async_step_regenerate_assets(self, user_input: dict | None = None):
202
+ """Regenera los archivos de assets."""
203
+ from . import ensure_assets_exist # importamos la función desde __init__.py
204
+
205
+ errors = {}
206
+ try:
207
+ # Llamar a la función que garantiza que los assets existan
208
+ await ensure_assets_exist(self.hass, self._config_entry.data)
209
+
210
+ _LOGGER.info("Archivos de assets regenerados correctamente.")
211
+ # Forzar recarga de la integración
212
+ await self.hass.config_entries.async_reload(self._config_entry.entry_id)
213
+
214
+ return self.async_create_entry(title="", data={})
215
+
216
+ except Exception as ex:
217
+ _LOGGER.error("Error al regenerar assets: %s", ex)
218
+ errors["base"] = "regenerate_failed"
219
+
220
+ return self.async_show_form(step_id="regenerate_assets", errors=errors)
@@ -608,7 +608,7 @@ class MeteocatStaticSensor(CoordinatorEntity[MeteocatStaticSensorCoordinator], S
608
608
  self._region_id = entry_data["region_id"]
609
609
 
610
610
  # Unique ID for the entity
611
- self._attr_unique_id = f"sensor.{DOMAIN}_{self._station_id}_{self.entity_description.key}"
611
+ self._attr_unique_id = f"sensor.{DOMAIN}_{self._town_id}_{self.entity_description.key}"
612
612
 
613
613
  # Assign entity_category if defined in the description
614
614
  self._attr_entity_category = getattr(description, "entity_category", None)
@@ -785,7 +785,7 @@ class MeteocatSensor(CoordinatorEntity[MeteocatSensorCoordinator], SensorEntity)
785
785
  self._station_id = entry_data["station_id"]
786
786
 
787
787
  # Unique ID for the entity
788
- self._attr_unique_id = f"sensor.{DOMAIN}_{self._station_id}_{self.entity_description.key}"
788
+ self._attr_unique_id = f"sensor.{DOMAIN}_{self._town_id}_{self.entity_description.key}"
789
789
 
790
790
  # Asigna entity_category desde description (si está definido)
791
791
  self._attr_entity_category = getattr(description, "entity_category", None)
@@ -1075,7 +1075,7 @@ class MeteocatHourlyForecastStatusSensor(CoordinatorEntity[MeteocatEntityCoordin
1075
1075
  self._station_id = entry_data["station_id"]
1076
1076
 
1077
1077
  # Unique ID for the entity
1078
- self._attr_unique_id = f"sensor.{DOMAIN}_{self._station_id}_hourly_status"
1078
+ self._attr_unique_id = f"sensor.{DOMAIN}_{self._town_id}_hourly_status"
1079
1079
 
1080
1080
  # Assign entity_category if defined in the description
1081
1081
  self._attr_entity_category = getattr(description, "entity_category", None)
@@ -1138,7 +1138,7 @@ class MeteocatDailyForecastStatusSensor(CoordinatorEntity[MeteocatEntityCoordina
1138
1138
  self._station_id = entry_data["station_id"]
1139
1139
 
1140
1140
  # Unique ID for the entity
1141
- self._attr_unique_id = f"sensor.{DOMAIN}_{self._station_id}_daily_status"
1141
+ self._attr_unique_id = f"sensor.{DOMAIN}_{self._town_id}_daily_status"
1142
1142
 
1143
1143
  # Assign entity_category if defined in the description
1144
1144
  self._attr_entity_category = getattr(description, "entity_category", None)
@@ -1201,7 +1201,7 @@ class MeteocatUviStatusSensor(CoordinatorEntity[MeteocatUviCoordinator], SensorE
1201
1201
  self._station_id = entry_data["station_id"]
1202
1202
 
1203
1203
  # Unique ID for the entity
1204
- self._attr_unique_id = f"sensor.{DOMAIN}_{self._station_id}_uvi_status"
1204
+ self._attr_unique_id = f"sensor.{DOMAIN}_{self._town_id}_uvi_status"
1205
1205
 
1206
1206
  # Assign entity_category if defined in the description
1207
1207
  self._attr_entity_category = getattr(description, "entity_category", None)
@@ -1264,7 +1264,7 @@ class MeteocatAlertStatusSensor(CoordinatorEntity[MeteocatAlertsCoordinator], Se
1264
1264
  self._limit_prediccio = entry_data["limit_prediccio"]
1265
1265
 
1266
1266
  # Unique ID for the entity
1267
- self._attr_unique_id = f"sensor.{DOMAIN}_{self._region_id}_alert_status"
1267
+ self._attr_unique_id = f"sensor.{DOMAIN}_{self._town_id}_alert_status"
1268
1268
 
1269
1269
  # Assign entity_category if defined in the description
1270
1270
  self._attr_entity_category = getattr(description, "entity_category", None)
@@ -1352,7 +1352,7 @@ class MeteocatAlertRegionSensor(CoordinatorEntity[MeteocatAlertsRegionCoordinato
1352
1352
  self._region_id = entry_data["region_id"]
1353
1353
 
1354
1354
  # Unique ID for the entity
1355
- self._attr_unique_id = f"sensor.{DOMAIN}_{self._region_id}_alerts"
1355
+ self._attr_unique_id = f"sensor.{DOMAIN}_{self._town_id}_alerts"
1356
1356
 
1357
1357
  # Assign entity_category if defined in the description
1358
1358
  self._attr_entity_category = getattr(description, "entity_category", None)
@@ -1459,7 +1459,7 @@ class MeteocatAlertMeteorSensor(CoordinatorEntity[MeteocatAlertsRegionCoordinato
1459
1459
  self._region_id = entry_data["region_id"]
1460
1460
 
1461
1461
  # Unique ID for the entity
1462
- self._attr_unique_id = f"sensor.{DOMAIN}_{self._region_id}_{self.entity_description.key}"
1462
+ self._attr_unique_id = f"sensor.{DOMAIN}_{self._town_id}_{self.entity_description.key}"
1463
1463
 
1464
1464
  # Assign entity_category if defined in the description
1465
1465
  self._attr_entity_category = getattr(description, "entity_category", None)
@@ -36,7 +36,7 @@
36
36
  "options": {
37
37
  "step":{
38
38
  "init": {
39
- "description": "Setup the API Key and the API limits.",
39
+ "description": "Setup the API Key, the API limits and regenerate 'assets' files.",
40
40
  "title": "Setup options",
41
41
  "data": {
42
42
  "option": "Options"
@@ -49,6 +49,13 @@
49
49
  "update_limits_only": {
50
50
  "description": "Setup the API limits.",
51
51
  "title": "API limits"
52
+ },
53
+ "confirm_regenerate_assets": {
54
+ "description": "Regenerate missing assets files.",
55
+ "title": "Regenerate assets",
56
+ "data": {
57
+ "confirm": "Confirm"
58
+ }
52
59
  }
53
60
  },
54
61
  "error": {
@@ -61,7 +68,8 @@
61
68
  "option": {
62
69
  "options": {
63
70
  "update_api_and_limits": "Update API Key and limits.",
64
- "update_limits_only": "Update API limits."
71
+ "update_limits_only": "Update API limits.",
72
+ "regenerate_assets": "Regenerate 'assets' files."
65
73
  }
66
74
  }
67
75
  },
@@ -2,7 +2,7 @@
2
2
  "config": {
3
3
  "step": {
4
4
  "user": {
5
- "description": "Introduïu la API Key subministrada per Meteocat per poder iniciar el procés de validació.",
5
+ "description": "Introduïu l'API Key subministrada per Meteocat per poder iniciar el procés de validació.",
6
6
  "title": "API Key"
7
7
  },
8
8
  "select_municipi": {
@@ -21,11 +21,11 @@
21
21
  },
22
22
  "set_api_limits": {
23
23
  "description": "Defineix els límits del pla de l'API.",
24
- "title": "API límits"
24
+ "title": "Límits de l'API"
25
25
  }
26
26
  },
27
27
  "error": {
28
- "bad_request": "Petició no vàlida. Reviseu la vostra API Key.",
28
+ "bad_request": "Petició invàlida. Reviseu la vostra API Key.",
29
29
  "forbidden": "Accés denegat. Reviseu els permisos de la vostra API Key.",
30
30
  "rate_limit_exceeded": "Excés del límit de peticions. Si us plau, torneu-ho a provar més tard.",
31
31
  "server_error": "Error del servidor. Torneu-ho a provar més tard.",
@@ -36,7 +36,7 @@
36
36
  "options": {
37
37
  "step":{
38
38
  "init": {
39
- "description": "Configura l'API Key i els límits de l'API.",
39
+ "description": "Configura l'API Key, els límits de l'API i regenera els arxius a 'assets'.",
40
40
  "title": "Opcions de configuració",
41
41
  "data": {
42
42
  "option": "Opcions"
@@ -49,6 +49,13 @@
49
49
  "update_limits_only": {
50
50
  "description": "Configura els límits de l'API.",
51
51
  "title": "Límits de l'API"
52
+ },
53
+ "confirm_regenerate_assets": {
54
+ "description": "Regenera els arxius a 'assets'.",
55
+ "title": "Regenera 'assets'",
56
+ "data": {
57
+ "confirm": "Confirmar"
58
+ }
52
59
  }
53
60
  },
54
61
  "error": {
@@ -60,8 +67,9 @@
60
67
  "selector": {
61
68
  "option": {
62
69
  "options": {
63
- "update_api_and_limits": "Actualitzar API Key i limits.",
64
- "update_limits_only": "Actualitzar API limits."
70
+ "update_api_and_limits": "Actualitzar API Key i límits.",
71
+ "update_limits_only": "Actualitzar API límits.",
72
+ "regenerate_assets": "Regenera arxius a 'assets'."
65
73
  }
66
74
  }
67
75
  },
@@ -161,15 +169,15 @@
161
169
  "name": "Estat del Cel",
162
170
  "state": {
163
171
  "sunny": "Assolellat",
164
- "clear-night": "Nit Clara",
172
+ "clear-night": "Nit serena",
165
173
  "partlycloudy": "Parcialment ennuvolat",
166
174
  "cloudy": "Ennuvolat",
167
175
  "rainy": "Plovent",
168
- "pouring": "Tormenta",
169
- "lightning-rainy": "Tormenta amb Llamps",
176
+ "pouring": "Tempesta",
177
+ "lightning-rainy": "Tempesta amb llamps",
170
178
  "hail": "Calamarsa",
171
179
  "snowy": "Nevant",
172
- "snow-rainy": "Neu amb Pluja"
180
+ "snow-rainy": "Aiguaneu"
173
181
  },
174
182
  "state_attributes": {
175
183
  "hour": {
@@ -812,4 +820,4 @@
812
820
  }
813
821
  }
814
822
  }
815
-
823
+
@@ -36,7 +36,7 @@
36
36
  "options": {
37
37
  "step":{
38
38
  "init": {
39
- "description": "Setup the API Key and the API limits.",
39
+ "description": "Setup the API Key, the API limits and regenerate 'assets' files.",
40
40
  "title": "Setup options",
41
41
  "data": {
42
42
  "option": "Options"
@@ -49,6 +49,13 @@
49
49
  "update_limits_only": {
50
50
  "description": "Setup the API limits.",
51
51
  "title": "API limits"
52
+ },
53
+ "confirm_regenerate_assets": {
54
+ "description": "Regenerate missing assets files.",
55
+ "title": "Regenerate assets",
56
+ "data": {
57
+ "confirm": "Confirm"
58
+ }
52
59
  }
53
60
  },
54
61
  "error": {
@@ -61,7 +68,8 @@
61
68
  "option": {
62
69
  "options": {
63
70
  "update_api_and_limits": "Update API Key and limits.",
64
- "update_limits_only": "Update API limits."
71
+ "update_limits_only": "Update API limits.",
72
+ "regenerate_assets": "Regenerate 'assets' files."
65
73
  }
66
74
  }
67
75
  },
@@ -36,7 +36,7 @@
36
36
  "options": {
37
37
  "step":{
38
38
  "init": {
39
- "description": "Configura el API Key y los límites de la API.",
39
+ "description": "Configura el API Key, los límites de la API y regenera los archivos en 'assets'.",
40
40
  "title": "Opciones de configuración",
41
41
  "data": {
42
42
  "option": "Opciones"
@@ -49,6 +49,13 @@
49
49
  "update_limits_only": {
50
50
  "description": "Configura los límites de la API.",
51
51
  "title": "Límites de la API"
52
+ },
53
+ "confirm_regenerate_assets": {
54
+ "description": "Regenera los archivos de 'assets'.",
55
+ "title": "Regenera 'assets'",
56
+ "data": {
57
+ "confirm": "Confirmar"
58
+ }
52
59
  }
53
60
  },
54
61
  "error": {
@@ -61,7 +68,8 @@
61
68
  "option": {
62
69
  "options": {
63
70
  "update_api_and_limits": "Actualizar API Key y límites.",
64
- "update_limits_only": "Actualizar API límites."
71
+ "update_limits_only": "Actualizar API límites.",
72
+ "regenerate_assets": "Regenerar archivos de 'assets'."
65
73
  }
66
74
  }
67
75
  },
@@ -1,2 +1 @@
1
- # version.py
2
- __version__ = "2.2.7"
1
+ __version__ = "3.0.0"
@@ -107,7 +107,7 @@ class MeteocatWeatherEntity(CoordinatorEntity, WeatherEntity):
107
107
  @property
108
108
  def unique_id(self) -> str:
109
109
  """Return the unique ID of the entity."""
110
- return f"weather.{DOMAIN}_{self._station_id}"
110
+ return f"weather.{DOMAIN}_{self._town_id}"
111
111
 
112
112
  @property
113
113
  def condition(self) -> Optional[str]:
package/filetree.txt CHANGED
@@ -1,7 +1,15 @@
1
1
  └── .github/
2
+ └── ISSUE_TEMPLATE/
3
+ ├── bug_report.md
4
+ ├── config.yml
2
5
  └── workflows/
6
+ ├── autocloser.yaml
7
+ ├── close-duplicates.yml
3
8
  ├── hassfest.yaml
9
+ ├── publish-zip.yml
4
10
  ├── release.yml
11
+ ├── stale.yml
12
+ ├── sync-gitlab.yml
5
13
  ├── validate.yaml
6
14
  ├── .gitignore
7
15
  ├── .gitlab-ci.yml
@@ -42,6 +50,7 @@
42
50
  ├── diagnostic_sensors.png
43
51
  ├── dynamic_sensors.png
44
52
  ├── login.png
53
+ ├── options.png
45
54
  ├── pick_area.png
46
55
  ├── pick_station.png
47
56
  ├── pick_town.png
package/hacs.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "Meteocat",
3
- "homeassistant": "2025.3.0",
3
+ "homeassistant": "2025.9.1",
4
4
  "hide_default_branch": true,
5
5
  "render_readme": true,
6
6
  "zip_release": true,
7
7
  "filename": "meteocat.zip"
8
- }
8
+ }
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meteocat",
3
- "version": "2.2.7",
3
+ "version": "3.0.0",
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 = "2.2.7"
3
+ version = "3.0.0"
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"
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ version="$1"
5
+
6
+ # pyproject.toml
7
+ sed -i "s/^version = \".*\"/version = \"$version\"/" pyproject.toml
8
+
9
+ # manifest.json
10
+ jq --arg ver "$version" '.version = $ver' custom_components/meteocat/manifest.json > tmp.json && mv tmp.json custom_components/meteocat/manifest.json
11
+
12
+ # version.py
13
+ echo "__version__ = \"$version\"" > custom_components/meteocat/version.py
14
+
15
+ # __init__.py
16
+ sed -i "s/^__version__ = \".*\"/__version__ = \"$version\"/" custom_components/meteocat/__init__.py
package/.releaserc.toml DELETED
@@ -1,14 +0,0 @@
1
- branches = ["master"]
2
-
3
- [plugins]
4
- "@semantic-release/gitlab" = {}
5
- "@semantic-release/github" = {}
6
- "@semantic-release/changelog" = {}
7
- "@semantic-release/commit-analyzer" = { preset = "conventional" }
8
- "@semantic-release/release-notes-generator" = {}
9
- "@semantic-release/git" = {}
10
-
11
- [[plugins]]
12
- path = "@semantic-release/git"
13
- assets = ["meteocat/version.py"]
14
- message = "chore(release): update version to ${nextRelease.version}"
package/releaserc.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "branches": ["master"],
3
- "plugins": [
4
- "@semantic-release/commit-analyzer",
5
- "@semantic-release/release-notes-generator",
6
- "@semantic-release/changelog",
7
- [
8
- "@semantic-release/exec",
9
- {
10
- "prepareCmd": "python setup.py sdist bdist_wheel",
11
- "publishCmd": "twine upload dist/* -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD}"
12
- }
13
- ],
14
- "@semantic-release/github",
15
- "@semantic-release/git"
16
- ]
17
- }
18
-