Skip to content

Commit

Permalink
complete #1
Browse files Browse the repository at this point in the history
  • Loading branch information
pantherale0 committed Jan 6, 2024
1 parent 0d2d9d9 commit e81f354
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 7 deletions.
37 changes: 36 additions & 1 deletion custom_components/fuel_prices/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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."""
62 changes: 59 additions & 3 deletions custom_components/fuel_prices/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
}
}
}
62 changes: 59 additions & 3 deletions custom_components/fuel_prices/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
}
}
}

0 comments on commit e81f354

Please sign in to comment.