Skip to content

Commit

Permalink
Merge pull request #50 from Rudd-O/dev
Browse files Browse the repository at this point in the history
Rehabilitate integration
  • Loading branch information
Rudd-O committed Aug 23, 2024
2 parents 960b28e + 679896a commit 910bd76
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 62 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"${workspaceFolder}/../hamsclientfork"
],
"python.formatting.provider": "black",
"python.linting.mypyEnabled": true,
"[python]": {
"editor.codeActionsOnSave": [
"source.organizeImports"
Expand All @@ -17,4 +16,4 @@
"source.convertImportFormat",
"source.unusedImports"
]
}
}
3 changes: 2 additions & 1 deletion custom_components/meteoswiss/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Lifecycle of Swiss Meteo."""

import datetime
import logging
import pprint
Expand All @@ -11,9 +12,9 @@
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import Config, HomeAssistant
from homeassistant.core import HomeAssistant as HomeAssistantType
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers.issue_registry import IssueSeverity
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import (
DataUpdateCoordinator,
UpdateFailed,
Expand Down
54 changes: 37 additions & 17 deletions custom_components/meteoswiss/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Config flow to configure the Meteo-Swiss integration."""

import logging
import re
from typing import Any
Expand All @@ -20,6 +21,7 @@
CONF_UPDATE_INTERVAL,
DEFAULT_UPDATE_INTERVAL,
DOMAIN,
USER_AGENT,
)

_LOGGER = logging.getLogger(__name__)
Expand All @@ -29,7 +31,6 @@


class MeteoSwissFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): # type:ignore

VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL

Expand All @@ -43,7 +44,10 @@ def __init__(self):
self._update_interval = None

async def async_step_user(self, user_input=None):
"""Handle a flow initiated by the user."""
"""Handle a flow initiated by the user.
In this step, we collect the latitude and longitude.
"""

_LOGGER.debug(
"step user: starting with lat %s lon %s post %s",
Expand Down Expand Up @@ -95,7 +99,11 @@ def data_schema(lat, lon):
return await self.async_step_user_two()

async def async_step_user_two(self, user_input=None):
"""Handle the second step of setup."""
"""Handle the second step of setup.
In this step we collect the postal code, the name of the forecast,
and the update interval.
"""

_LOGGER.debug(
"step user two: starting with lat %s lon %s post %s",
Expand Down Expand Up @@ -144,21 +152,33 @@ def data_schema(postcode, name, interval):
user_input[CONF_UPDATE_INTERVAL],
)
else:
geodata = await self.hass.async_add_executor_job(
client.getGeoData, self._lat, self._lon
)
guessed_postal_code = str(
geodata.get("address", {}).get(
"postcode",
"",
try:
geodata = await self.hass.async_add_executor_job(
client.getGeoData,
self._lat,
self._lon,
USER_AGENT,
)
)
guessed_address = " ".join(
x.strip()
for x in str(geodata.get("display_name", "",)).split(
","
)[:3]
)
guessed_postal_code = str(
geodata.get("address", {}).get(
"postcode",
"",
)
)
guessed_address = " ".join(
x.strip()
for x in str(
geodata.get(
"display_name",
"",
)
).split(",")[:3]
)
except Exception:
errors[CONF_POSTCODE] = "cannot_query_postcode"
errors[CONF_FORECAST_NAME] = "cannot_query_address"
guessed_postal_code = ""
guessed_address = ""

schema = data_schema(
guessed_postal_code,
Expand Down
10 changes: 6 additions & 4 deletions custom_components/meteoswiss/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from typing import Final

from homeassistant.const import (
CONF_NAME,
DEGREE,
PERCENTAGE,
UnitOfIrradiance,
UnitOfPressure,
UnitOfSpeed,
UnitOfTemperature,
UnitOfIrradiance,
UnitOfTime,
CONF_NAME,
DEGREE,
PERCENTAGE,
)

DOMAIN = "meteoswiss"
Expand All @@ -28,6 +28,8 @@

DEFAULT_UPDATE_INTERVAL = 5

USER_AGENT = "Meteo Swiss Home Assistant integration"

# Mapping for conditions vs icon ID of meteoswiss
# ID < 100 for day icons
# ID > 100 for night icons
Expand Down
2 changes: 1 addition & 1 deletion custom_components/meteoswiss/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"issue_tracker": "https://github.com/Rudd-O/homeassistant-meteoswiss/issues",
"quality_scale": "silver",
"requirements": [
"hamsclientfork==0.2.8",
"hamsclientfork==0.2.10",
"geopy>=2.0"
],
"version": "1.3.1"
Expand Down
60 changes: 60 additions & 0 deletions custom_components/meteoswiss/translations/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"issues": {
"deprecated_yaml": {
"title": "Die YAML-Konfiguration von MeteoSchweiz wird entfernt",
"description": "Es ist nicht mehr möglich MeteoSchweiz durch YAML zu konfigurieren.\\n\\nDeine bestehende YAML-Konfiguration wurde in das Benutzergrensetritt automatisch importiert.\\n\\nEntfernen Sie die Meteo-Konfiguration aus ihrer configuration.yaml-Datei und starten Sie Home Assistant neu, um dieses Problem zu beheben."
},
"station_no_data": {
"title": "Die MeteoSchweiz-Wetterstation scheint verschwunden zu sein",
"description": "Die MeteoSchweiz-Wetterstation, die verwendet wird ({station}), bietet keine Daten mehr an.\\n\\nDerzeit ist es nur möglich, dies zu korrigieren, indem man den MeteoSchweiz-Integration entfernt und neu hinzufügt und eine neue Wetterstation auswählt.\\n\\nBis dieses Problem behoben ist, werden alle akuten Wetter-Sensoren und Berichte von dieser Station als unavailable angezeigt."
},
"improperly_configured": {
"title": "Die MeteoSchweiz-Integration ist nicht richtig konfiguriert",
"description": "Die MeteoSchweiz-Integration mit der ID {entry_id} ist nicht korrekt konfiguriert.\\n\\nBitte entfernen Sie ihre Konfigurations-Eintrag und erstellen Sie ihn wieder neu."
}
},
"config": {
"abort": {
"already_configured": "Bereits konfiguriert",
"unknown": "Unerkennbares Fehler: Bitte versuche es später noch einmal"
},
"error": {
"cannot_query_address": "OpenStreetMap weigerte sich, die Adresse für deine Standort zu erraten; bitte richten Sie die Informationen manuell ein",
"cannot_query_postcode": "OpenStreetMap weigerte sich, das Postleitzahl für deine Standort zu erraten; bitte richten Sie die Informationen manuell ein",
"lat": "Die gegebene Breite liegt nicht zwischen -90 und 90 Grad",
"lon": "Die gegebene Länge liegt nicht zwischen -180 und 180 Grad",
"invalid_station_name": "Stationsname ist ungültig; bitte überprüfe https://rudd-o.com/meteostations für die Liste der Wetterstationen",
"invalid_postcode": "Postleitzahl ist ungültig; diese Integration funktioniert nur mit Schweizer Postleitzahlen",
"forecast_name_empty": "Vorausberechnetes Name kann nicht leer sein",
"empty_name": "Der Anzeigename ist leer",
"update_interval_too_low": "Aktualisierungsintervall ist zu niedrig; es muss mindestens 1 Minute sein"
},
"step": {
"user": {
"data": {
"latitude": "Breite",
"longitude": "Länge"
},
"description": "Bewahrheit deinen geografischen Standort. Dies wird verwendet, um die nächste Wetterstation zu erraten und deine Postleitzahl für Vorhersagen anzunähern.",
"title": "Standort"
},
"user_two": {
"data": {
"postcode": "Postleitzahl",
"forecast_name": "Vorausberechnetes Name (Wetter) Einheit Namen",
"update_interval": "Aktualisierungsintervall in Minuten"
},
"description": "Die Postleitzahl wird verwendet, um die 5-Tages-Vorhersage zu finden. Der Name, den du hier einträgst, wird für die Vorausberechnete (Wetter) Einheit Namen verwendet.",
"title": "Vorhersage"
},
"user_three": {
"data": {
"station": "Aktuelle Wetterstation",
"real_time_name": "Real-time entity names"
},
"description": "Die aktuelle Wetterstation wird verwendet, um die aktuellen Wetterdaten am Standort zu finden und als Sensoren bereitzustellen. Wenn Sie das erste Option der Liste auswählen, deaktiveren Sie die Akuten Wetter-Sensoren.\\n\\nWenn eine Wetterstation ausgewählt wird, wird das Feld Real-time entity names verwendet, um den aktuellen Wetterdaten Namen zu benennen. Wenn keine Station gewählt ist, wird das Feld Real-time entity names ignoriert.\\n\\nhttps://rudd-o.com/meteostations listet die verfügbaren aktuelle Wetterstationen auf.",
"title": "Aktuelles Wetter"
}
}
}
}
4 changes: 3 additions & 1 deletion custom_components/meteoswiss/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"unknown": "Unknown error: please retry later"
},
"error": {
"cannot_query_address": "OpenStreetMap refused to guess the address for your location; please enter the information manually",
"cannot_query_postcode": "OpenStreetMap refused to guess the postal code for your location; please enter the information manually",
"lat": "The supplied latitude does not fall between -90 y 90 degrees",
"lon": "The supplied latitude does not fall between -180 y 180 degrees",
"lon": "The supplied longitude does not fall between -180 y 180 degrees",
"invalid_station_name": "Station name is invalid; please check https://rudd-o.com/meteostations for station list",
"invalid_postcode": "Postal code is invalid; this integration only works with Swiss postal codes",
"forecast_name_empty": "Forecast name cannot be empty",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/meteoswiss/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"unknown": "Error desconocido; por favor intente más tarde"
},
"error": {
"cannot_query_address": "OpenStreetMap no pudo inferir su dirección; por favor entre la información manualmente",
"cannot_query_postcode": "OpenStreetMap no pudo inferir su código postal; por favor entre la información manualmente",
"lat": "La latitud especificada no está entre -90 y 90 grados",
"lon": "La longitud especificada no está entre -180 y 180 grados",
"invalid_station_name": "Estación inválida (deben ser 3 caracteres); verifique las estaciones aquí: https://rudd-o.com/meteostations",
Expand Down
32 changes: 17 additions & 15 deletions custom_components/meteoswiss/translations/fr.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"issues": {
"deprecated_yaml": {
"title": "The Meteo Swiss YAML configuration is being removed",
"description": "Configuring Meteo Swiss using YAML is being removed.\n\nYour existing YAML configuration has been imported into the UI automatically.\n\nRemove the Swiss Meteo configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
"title": "La configuration YAML de Meteo Suisse est en train de être supprimée",
"description": "La configuration YAML de Meteo Suisse est en train d'être supprimée.\\n\\nL'importation automatique de votre configuration YAML a été effectuée avec succès dans l'interface utilisateur.\\n\\nSupprimez la configuration Swiss Meteo de votre fichier configuration.yaml et redémarrez Home Assistant pour résoudre ce problème."
},
"station_no_data": {
"title": "Meteo Swiss weather station appears to be gone",
"description": "The real-time weather station Meteo Swiss is using ({station}) is no longer offering data.\n\nCurrently, the only repair possible involves removing and re-adding the Meteo Swiss integration, selecting a new real-time weather station.\n\nUntil this repair is made, all real-time weather sensors and reports coming from this station will show as unavailable."
"title": "La station météo de Meteo Suisse semble avoir disparu",
"description": "La station météo en temps réel de Meteo Swiss, qui utilise ({station}), n'offre plus de données.\\n\\nActuellement, la seule possibilité de réparation consiste à supprimer et à re-ajouter l'intégration Meteo Swiss, tout en sélectionnant une nouvelle station météo en temps réel.\\n\\nJusqu'à ce que cette réparation soit effectuée, tous les capteurs météo et les rapports provenant de cette station afficheront comme indisponibles."
},
"improperly_configured": {
"title": "Meteo Swiss integration improperly configured",
"description": "The Meteo Swiss integration with entry ID {entry_id} is improperly configured.\n\nPlease remove your configuration entry and recreate it."
"title": "L'intégration de Meteo Suisse est mal configurée",
"description": "L'intégration de Meteo Swiss avec l'ID d'entrée {entry_id} n'est pas correctement configurée.\\n\\nVeuillez supprimer votre entrée de configuration et la recréer."
}
},
"config": {
Expand All @@ -19,13 +19,15 @@
"unknown": "Erreur inconnue : veuillez réessayer plus tard"
},
"error": {
"lat": "La latitude fournie n'est pas comprise entre -90 et 90 degrés.",
"lon": "La latitude fournie n'est pas comprise entre -180 et 180 degrés.",
"invalid_station_name": "Nom de la station invalide; merci de vérifier sur: https://rudd-o.com/meteostations",
"invalid_postcode": "Code postale incorrecte; cette intégration ne fonctionne que pour de codes postaux suisse",
"forecast_name_empty": "Le nom de la prévision ne peut être vide",
"empty_name": "Le nom d'affichage est vide",
"update_interval_too_low": "L'intervalle de mise à jour est trop court. Il doit être d'au moins 1 minute."
"cannot_query_address": "OpenStreetMap a refusé de deviner l'adresse pour votre emplacement; veuillez entrer les informations manuellement",
"cannot_query_postcode": "OpenStreetMap a refusé de deviner le code postal pour votre emplacement; veuillez entrer les informations manuellement",
"lat": "La latitude fournie ne tombe pas entre -90 et 90 degrés",
"lon": "La longitude fournie ne tombe pas entre -180 et 180 degrés",
"invalid_station_name": "Le nom de la station est invalide; veuillez consulter https://rudd-o.com/meteostations pour la liste des stations",
"invalid_postcode": "Le code postal est invalide. Cette intégration ne fonctionne que avec les codes postaux suisses",
"forecast_name_empty": "Le nom de prévision ne peut pas être vide",
"empty_name": "Le nom à afficher est vide",
"update_interval_too_low": "L'intervalle d'actualisation est trop bas. Doit être minimum 1 minute"
},
"step": {
"user": {
Expand All @@ -42,8 +44,8 @@
"forecast_name": "Nom de l'entité des prévisions (entity name)",
"update_interval": "Intervalle de mise à jour en minutes"
},
"description": "The postal code is used to look up the 5-day forecast. The name you enter here will be used for the forecast (weather) entity.",
"title": "Forecast"
"description": "Le code postal est utilisé pour consulter les prévisions météo à 5 jours. Le nom que vous entrez ici sera utilisé pour l'entité de prévision (météo).",
"title": "Prévisions"
},
"user_three": {
"data": {
Expand Down
Loading

0 comments on commit 910bd76

Please sign in to comment.