From e81f35423c47374803c353c81d7c47990f376f9f Mon Sep 17 00:00:00 2001 From: Jordan H Date: Sat, 6 Jan 2024 20:02:18 +0000 Subject: [PATCH] complete #1 --- custom_components/fuel_prices/config_flow.py | 37 ++++++++++- custom_components/fuel_prices/strings.json | 62 ++++++++++++++++++- .../fuel_prices/translations/en.json | 62 ++++++++++++++++++- 3 files changed, 154 insertions(+), 7 deletions(-) diff --git a/custom_components/fuel_prices/config_flow.py b/custom_components/fuel_prices/config_flow.py index 7e8795f..bcd6fbd 100644 --- a/custom_components/fuel_prices/config_flow.py +++ b/custom_components/fuel_prices/config_flow.py @@ -282,10 +282,32 @@ async def async_step_main_menu(self, _: None = None): menu_options={ "area_menu": "Configure areas to create devices/sensors", "sources": "Configure data collector sources", - "finished": "Complete save", + "finished": "Complete re-configuration", }, ) + async def async_step_sources(self, user_input: dict[str, Any] | None = None): + """Source configuration step.""" + if user_input is not None: + self.configured_sources = user_input[CONF_SOURCES] + return await self.async_step_main_menu(None) + return self.async_show_form( + step_id="sources", + data_schema=vol.Schema( + { + vol.Optional( + CONF_SOURCES, default=self.configured_sources + ): selector.SelectSelector( + selector.SelectSelectorConfig( + mode=selector.SelectSelectorMode.DROPDOWN, + options=list(SOURCE_MAP), + multiple=True, + ) + ) + } + ), + ) + async def async_step_area_menu(self, _: None = None) -> FlowResult: """Show the area menu.""" return self.async_show_menu( @@ -415,6 +437,19 @@ async def async_step_area_delete(self, user_input: dict[str, Any] | None = None) ) return await self.async_step_area_menu() + async def async_step_finished(self, user_input: dict[str, Any] | None = None): + """Final confirmation step.""" + errors: dict[str, str] = {} + if user_input is not None: + user_input[CONF_SOURCES] = ( + self.configured_sources + if len(self.configured_sources) > 0 + else list(SOURCE_MAP) + ) + user_input[CONF_AREAS] = self.configured_areas + return self.async_create_entry(title=NAME, data=user_input) + return self.async_show_form(step_id="finished", errors=errors, last_step=True) + class CannotConnect(HomeAssistantError): """Error to indicate we cannot connect.""" diff --git a/custom_components/fuel_prices/strings.json b/custom_components/fuel_prices/strings.json index eb79f12..2fa5a5b 100644 --- a/custom_components/fuel_prices/strings.json +++ b/custom_components/fuel_prices/strings.json @@ -54,11 +54,11 @@ "name": "Area name" } } + }, + "abort": { + "already_configured": "For performance considerations and memory efficiency, only one instance of this integration is allowed." } }, - "error": { - "already_configured": "Only one instance of this integration is allowed." - }, "services": { "find_fuels": { "name": "Find fuel prices from location", @@ -84,5 +84,61 @@ } } } + }, + "options": { + "step": { + "finished": { + "title": "Fuel Prices", + "description": "Click submit to finish setup" + }, + "sources": { + "title": "Configure data collection sources", + "description": "Using this menu you can change what providers the integration will collect data from.", + "data": { + "sources": "Data source(s)" + } + }, + "area_menu": { + "title": "Configure areas to register devices and sensors", + "menu_options": { + "area_create": "Create an area", + "area_update_select": "Update an area", + "area_delete": "Delete an area", + "main_menu": "Return to main menu" + } + }, + "area_create": { + "title": "Create an area", + "description": "Using this menu you can create areas to register devices and sensors. This integration will create a device for each fuel station discovered, under this a sensor will be created for each fuel type.", + "data": { + "name": "Area name (must be unique)", + "radius": "Maximum search radius", + "latitude": "Latitude for the center of the search location", + "longitude": "Longitude for the center of the search location" + } + }, + "area_update_select": { + "title": "Select area to update", + "data": { + "name": "Area name" + } + }, + "area_update": { + "title": "Create an area", + "description": "Using this menu you can create areas to register devices and sensors. This integration will create a device for each fuel station discovered, under this a sensor will be created for each fuel type.", + "data": { + "name": "Area name (must be unique)", + "radius": "Maximum search radius", + "latitude": "Latitude for the center of the search location", + "longitude": "Longitude for the center of the search location" + } + }, + "area_delete": { + "title": "Select area to delete", + "data": { + "name": "Area name" + } + } + } } } \ No newline at end of file diff --git a/custom_components/fuel_prices/translations/en.json b/custom_components/fuel_prices/translations/en.json index eb79f12..2fa5a5b 100644 --- a/custom_components/fuel_prices/translations/en.json +++ b/custom_components/fuel_prices/translations/en.json @@ -54,11 +54,11 @@ "name": "Area name" } } + }, + "abort": { + "already_configured": "For performance considerations and memory efficiency, only one instance of this integration is allowed." } }, - "error": { - "already_configured": "Only one instance of this integration is allowed." - }, "services": { "find_fuels": { "name": "Find fuel prices from location", @@ -84,5 +84,61 @@ } } } + }, + "options": { + "step": { + "finished": { + "title": "Fuel Prices", + "description": "Click submit to finish setup" + }, + "sources": { + "title": "Configure data collection sources", + "description": "Using this menu you can change what providers the integration will collect data from.", + "data": { + "sources": "Data source(s)" + } + }, + "area_menu": { + "title": "Configure areas to register devices and sensors", + "menu_options": { + "area_create": "Create an area", + "area_update_select": "Update an area", + "area_delete": "Delete an area", + "main_menu": "Return to main menu" + } + }, + "area_create": { + "title": "Create an area", + "description": "Using this menu you can create areas to register devices and sensors. This integration will create a device for each fuel station discovered, under this a sensor will be created for each fuel type.", + "data": { + "name": "Area name (must be unique)", + "radius": "Maximum search radius", + "latitude": "Latitude for the center of the search location", + "longitude": "Longitude for the center of the search location" + } + }, + "area_update_select": { + "title": "Select area to update", + "data": { + "name": "Area name" + } + }, + "area_update": { + "title": "Create an area", + "description": "Using this menu you can create areas to register devices and sensors. This integration will create a device for each fuel station discovered, under this a sensor will be created for each fuel type.", + "data": { + "name": "Area name (must be unique)", + "radius": "Maximum search radius", + "latitude": "Latitude for the center of the search location", + "longitude": "Longitude for the center of the search location" + } + }, + "area_delete": { + "title": "Select area to delete", + "data": { + "name": "Area name" + } + } + } } } \ No newline at end of file