diff --git a/custom_components/gtfs2/config_flow.py b/custom_components/gtfs2/config_flow.py index 2669e2b..662b70c 100644 --- a/custom_components/gtfs2/config_flow.py +++ b/custom_components/gtfs2/config_flow.py @@ -239,7 +239,7 @@ async def async_step_agency(self, user_input: dict | None = None) -> FlowResult: return await self.async_step_route_type() async def async_step_route_type(self, user_input: dict | None = None) -> FlowResult: - """Handle the route_type.""" + """Handle the dummy route_type to split between train (different mechanism) and rest.""" errors: dict[str, str] = {} if user_input is None: return self.async_show_form( @@ -259,7 +259,7 @@ async def async_step_route_type(self, user_input: dict | None = None) -> FlowRes return await self.async_step_route() async def async_step_route(self, user_input: dict | None = None) -> FlowResult: - """Handle the route.""" + """Handle the route and reset the route_type to the proper one.""" errors: dict[str, str] = {} check_data = await self._check_data(self._user_inputs) _LOGGER.debug("Source check data: %s", check_data) @@ -272,19 +272,24 @@ async def async_step_route(self, user_input: dict | None = None) -> FlowResult: self._user_inputs, False, ) - if user_input is None: + route_list = [ + selector.SelectOptionDict(value=r, label=r.split('#')[1]) + for r in get_route_list(self._pygtfs, self._user_inputs) + ] return self.async_show_form( step_id="route", data_schema=vol.Schema( { - vol.Required(CONF_ROUTE, default = ""): selector.SelectSelector(selector.SelectSelectorConfig(options = get_route_list(self._pygtfs, self._user_inputs), translation_key="route_type",custom_value=True)), + vol.Required(CONF_ROUTE, default = ""): selector.SelectSelector(selector.SelectSelectorConfig(options=route_list, translation_key="route",custom_value=True)), vol.Required(CONF_DIRECTION): selector.SelectSelector(selector.SelectSelectorConfig(options=["0", "1"], translation_key="direction")), }, ), errors=errors, ) - user_input[CONF_ROUTE_TYPE] = user_input.get(CONF_ROUTE,99).split('#')[1] + user_input[CONF_ROUTE_TYPE] = user_input.get(CONF_ROUTE).split('#')[0] + user_input[CONF_ROUTE] = user_input.get(CONF_ROUTE).split('#')[1].split(":")[0] + self._user_inputs.update(user_input) _LOGGER.debug(f"UserInputs Route: {self._user_inputs}") return await self.async_step_stops() @@ -296,7 +301,7 @@ async def async_step_stops(self, user_input: dict | None = None) -> FlowResult: try: stops = get_stop_list( self._pygtfs, - self._user_inputs[CONF_ROUTE].split(":")[0], + self._user_inputs[CONF_ROUTE], self._user_inputs[CONF_DIRECTION], ) last_stop = stops[-1:][0] @@ -332,7 +337,7 @@ async def async_step_stops_retry(self, user_input: dict | None = None) -> FlowRe try: stops = get_stop_list( self._pygtfs, - self._user_inputs[CONF_ROUTE].split(":")[0], + self._user_inputs[CONF_ROUTE], self._user_inputs[CONF_DIRECTION], ) last_stop = stops[-1:][0] diff --git a/custom_components/gtfs2/gtfs_helper.py b/custom_components/gtfs2/gtfs_helper.py index c28b2a2..eebe522 100644 --- a/custom_components/gtfs2/gtfs_helper.py +++ b/custom_components/gtfs2/gtfs_helper.py @@ -584,7 +584,7 @@ def get_route_list(schedule, data): if data["route_type"] != "99": route_type_where = f"and route_type = {data['route_type']}" sql_routes = f""" - SELECT r.route_id, r.route_type, r.route_short_name, r.route_long_name, a.agency_name + SELECT r.route_type, r.route_id, r.route_short_name, r.route_long_name, a.agency_name from routes r left join agency a on a.agency_id = r.agency_id where 1=1 @@ -602,7 +602,7 @@ def get_route_list(schedule, data): row = row_cursor._asdict() routes_list.append(list(row_cursor)) for x in routes_list: - val = str(x[0]) + ":#" + str(x[1]) + "# (" + str(x[2]) + " - " + str(x[3]) + ") " + str(x[4]) + val = str(x[0]) + "#" + str(x[1]) + ": (" + str(x[2]) + " - " + str(x[3]) + ") " + str(x[4]) routes.append(val) _LOGGER.debug(f"routes: {routes}") return routes