Skip to content

Commit

Permalink
Fix localisation in config_flow
Browse files Browse the repository at this point in the history
  • Loading branch information
vingerha committed Nov 11, 2023
1 parent f46f750 commit ce16b55
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 20 deletions.
26 changes: 12 additions & 14 deletions custom_components/gtfs2/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from homeassistant.data_entry_flow import FlowResult
import homeassistant.helpers.config_validation as cv
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import selector

from .const import DEFAULT_PATH, DOMAIN, DEFAULT_REFRESH_INTERVAL

Expand Down Expand Up @@ -81,8 +82,8 @@ async def async_step_source(self, user_input: dict | None = None) -> FlowResult:
step_id="source",
data_schema=vol.Schema(
{
vol.Required("extract_from"): selector.SelectSelector(selector.SelectSelectorConfig(options=["zip", "url"], translation_key="extract_from")),
vol.Required("file"): str,
vol.Required("extract_from"): vol.In({"zip": "Use gtfs2/zipfile with above name, without extension", "url": "Use URL below, leave 'na' if using zip"}),
vol.Required("url", default="na"): str,
},
),
Expand Down Expand Up @@ -141,9 +142,7 @@ async def async_step_route(self, user_input: dict | None = None) -> FlowResult:
data_schema=vol.Schema(
{
vol.Required("route"): vol.In(get_route_list(self._pygtfs)),
vol.Required("direction"): vol.In(
{"0": "Outward", "1": "Return"}
),
vol.Required("direction"): selector.SelectSelector(selector.SelectSelectorConfig(options=["0", "1"], translation_key="direction")),
},
),
errors=errors,
Expand Down Expand Up @@ -173,9 +172,7 @@ async def async_step_stops(self, user_input: dict | None = None) -> FlowResult:
vol.Required("destination", default=last_stop): vol.In(stops),
vol.Required("name"): str,
vol.Optional("offset", default=0): int,
vol.Required("include_tomorrow"): vol.In(
{False: "No", True: "Yes"}
),
vol.Optional("include_tomorrow", default = False): selector.BooleanSelector(),
},
),
errors=errors,
Expand Down Expand Up @@ -262,15 +259,16 @@ async def async_step_init(
self._user_inputs.update(user_input)
_LOGGER.debug(f"GTFS Options without realtime: {self._user_inputs}")
return self.async_create_entry(title="", data=self._user_inputs)

return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
{

opt1_schema = {
vol.Optional("refresh_interval", default=self.config_entry.options.get("refresh_interval", DEFAULT_REFRESH_INTERVAL)): int,
vol.Required("real_time", default=self.config_entry.options.get("real_time")): vol.In({False: "No", True: "Yes"}),
vol.Optional("real_time", default=self.config_entry.options.get("real_time")): selector.BooleanSelector()
}
),


return self.async_show_form(
step_id="init",
data_schema=vol.Schema(opt1_schema)
)

async def async_step_real_time(
Expand Down
20 changes: 18 additions & 2 deletions custom_components/gtfs2/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"source": {
"data": {
"file": "New datasource name",
"url": "external url to gtfs data (zip) file"
"url": "external url to gtfs data (zip) file",
"extract_from": "Extract data from:"
},
"description": "NOTE: with a new url/zip, this may take quite a bit of time, \n depending on file-size and system performance"
},
Expand Down Expand Up @@ -54,7 +55,8 @@
"init": {
"description": "Customize the way the integration works",
"data": {
"refresh_interval": "Data refresh interval (in minutes)"
"refresh_interval": "Data refresh interval (in minutes)",
"real_time": "Setup Realtime integration? \n (needs data from the same source)"
}
},
"real_time": {
Expand All @@ -65,5 +67,19 @@
}
}
}
},
"selector": {
"extract_from": {
"options": {
"zip": "ZIP: expects a file in gtfs2-folder with below name, without extension .zip",
"url": "URL: uses your URL below, leave 'na' if using zip"
}
},
"direction": {
"options": {
"0": "Outward",
"1": "Return"
}
}
}
}
31 changes: 27 additions & 4 deletions custom_components/gtfs2/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
"source": {
"data": {
"file": "Nom de la nouvelle source de données",
"url": "URL externe vers le fichier (zip) des données GTFS"
"url": "URL externe vers le fichier (zip) des données GTFS",
"extract_from": "Collecte données de:"
},
"description": "REMARQUE: avec une nouvelle URL/zip, cela peut prendre du temps après la soumission, \n selon la taille du fichier et performance du serveur"
"description": "REMARQUE: avec une nouvelle URL/zip, cela peut prendre du temps après la soumission, selon la taille du fichier et performance du serveur"
},
"route": {
"data": {
Expand Down Expand Up @@ -54,9 +55,31 @@
"init": {
"description": "Personnalisez le fonctionnement de l'intégration",
"data": {
"refresh_interval": "Personnalisez le fonctionnement de l'intégration"
"refresh_interval": "Intervalle d'actualisation en minutes",
"real_time": "Ajoute intégration temps réel? \n (nécessite données de la même source)"
}
},
"real_time": {
"description": "URL vers données temps réel",
"data": {
"trip_update_url": "URL vers: trip data",
"vehicle_position_url": "URL vers: position véhicule (ou trip data)"
}
}
}
},
"selector": {
"extract_from": {
"options": {
"zip": "ZIP: attend un fichier dans dossier 'gtfs2' avec le même nom, sans extension .zip",
"url": "URL: utilise l'URL below, laisse 'na' si zip"
}
},
"direction": {
"options": {
"0": "Aller",
"1": "Retour"
}
}
}
}
}

0 comments on commit ce16b55

Please sign in to comment.