-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add config flow for Waze Travel Time #43419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 26 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
317a6cd
Add config flow for Waze Travel Time
raman325 c9421fb
update translations
raman325 0e177fd
setup entry is async
raman325 c077ba9
fix update logic during setup
raman325 d261298
support old config method in the interim
raman325 2104206
fix requirements
raman325 cfd14d4
fix requirements
raman325 a404af9
add abort string
raman325 8c267a7
changes based on @bdraco review
raman325 72b8f56
fix tests
raman325 e21c47f
add device identifier
raman325 949f588
Update homeassistant/components/waze_travel_time/__init__.py
raman325 9da8dfc
fix tests
raman325 383fa81
Merge branch 'dev' into waze_config_flow
raman325 1c9c7d7
Update homeassistant/components/waze_travel_time/sensor.py
raman325 7b5cf85
log warning for deprecation message
raman325 dc415b4
PR feedback
raman325 5b110ad
fix tests and bugs
raman325 b7b834f
re-add name to config schema to avoid breaking change
raman325 6c0e25c
handle if we get name from config in entry title
raman325 d2545ac
fix name logic
raman325 ef2a06c
always set up options with defaults
raman325 ab4d9b3
Update homeassistant/components/waze_travel_time/sensor.py
raman325 b6675c0
Update config_flow.py
raman325 add53b2
Update sensor.py
raman325 5778963
handle options updates by getting options on every update
raman325 4482be3
patch library instead of sensor
raman325 80a7b94
fixes and make sure first update writes the state
raman325 3ee638f
validate config entry data during config flow and entry setup
raman325 7cc8d62
fix input parameters
raman325 c39d7b0
fix tests
raman325 7ee56ba
invert if statement
raman325 c99f00d
remove unnecessary else
raman325 23b5291
exclude helpers from coverage
raman325 f6b2497
remove async_setup because it's no longer needed
raman325 421516c
fix patch statements
raman325 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,34 @@ | ||
| """The waze_travel_time component.""" | ||
| import asyncio | ||
|
|
||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.core import Config, HomeAssistant | ||
|
|
||
| PLATFORMS = ["sensor"] | ||
|
|
||
|
|
||
| async def async_setup(hass: HomeAssistant, config: Config) -> bool: | ||
| """Component setup.""" | ||
| return True | ||
|
|
||
|
|
||
| async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: | ||
| """Load the saved entities.""" | ||
| for platform in PLATFORMS: | ||
| hass.async_create_task( | ||
| hass.config_entries.async_forward_entry_setup(config_entry, platform) | ||
| ) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: | ||
| """Unload a config entry.""" | ||
| return all( | ||
| await asyncio.gather( | ||
| *[ | ||
| hass.config_entries.async_forward_entry_unload(config_entry, platform) | ||
| for platform in PLATFORMS | ||
| ] | ||
| ) | ||
| ) | ||
131 changes: 131 additions & 0 deletions
131
homeassistant/components/waze_travel_time/config_flow.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| """Config flow for Waze Travel Time integration.""" | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant import config_entries | ||
| from homeassistant.const import CONF_NAME, CONF_REGION | ||
| from homeassistant.core import callback | ||
| import homeassistant.helpers.config_validation as cv | ||
| from homeassistant.util import slugify | ||
|
|
||
| from .const import ( | ||
| CONF_AVOID_FERRIES, | ||
| CONF_AVOID_SUBSCRIPTION_ROADS, | ||
| CONF_AVOID_TOLL_ROADS, | ||
| CONF_DESTINATION, | ||
| CONF_EXCL_FILTER, | ||
| CONF_INCL_FILTER, | ||
| CONF_ORIGIN, | ||
| CONF_REALTIME, | ||
| CONF_UNITS, | ||
| CONF_VEHICLE_TYPE, | ||
| DEFAULT_NAME, | ||
| DOMAIN, | ||
| REGIONS, | ||
| UNITS, | ||
| VEHICLE_TYPES, | ||
| ) | ||
|
|
||
|
|
||
| class WazeOptionsFlow(config_entries.OptionsFlow): | ||
| """Handle an options flow for Waze Travel Time.""" | ||
|
|
||
| def __init__(self, config_entry: config_entries.ConfigEntry) -> None: | ||
| """Initialize waze options flow.""" | ||
| self.config_entry = config_entry | ||
|
|
||
| async def async_step_init(self, user_input=None): | ||
| """Handle the initial step.""" | ||
| if user_input is not None: | ||
| return self.async_create_entry(title="", data=user_input) | ||
|
|
||
| return self.async_show_form( | ||
| step_id="init", | ||
| data_schema=vol.Schema( | ||
| { | ||
| vol.Optional( | ||
| CONF_INCL_FILTER, | ||
| default=self.config_entry.options.get(CONF_INCL_FILTER), | ||
| ): cv.string, | ||
| vol.Optional( | ||
| CONF_EXCL_FILTER, | ||
| default=self.config_entry.options.get(CONF_EXCL_FILTER), | ||
| ): cv.string, | ||
| vol.Optional( | ||
| CONF_REALTIME, | ||
| default=self.config_entry.options[CONF_REALTIME], | ||
| ): cv.boolean, | ||
| vol.Optional( | ||
| CONF_VEHICLE_TYPE, | ||
| default=self.config_entry.options[CONF_VEHICLE_TYPE], | ||
| ): vol.In(VEHICLE_TYPES), | ||
| vol.Optional( | ||
| CONF_UNITS, | ||
| default=self.config_entry.options[CONF_UNITS], | ||
| ): vol.In(UNITS), | ||
| vol.Optional( | ||
| CONF_AVOID_TOLL_ROADS, | ||
| default=self.config_entry.options[CONF_AVOID_TOLL_ROADS], | ||
| ): cv.boolean, | ||
| vol.Optional( | ||
| CONF_AVOID_SUBSCRIPTION_ROADS, | ||
| default=self.config_entry.options[ | ||
| CONF_AVOID_SUBSCRIPTION_ROADS | ||
| ], | ||
| ): cv.boolean, | ||
| vol.Optional( | ||
| CONF_AVOID_FERRIES, | ||
| default=self.config_entry.options[CONF_AVOID_FERRIES], | ||
| ): cv.boolean, | ||
| } | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): | ||
| """Handle a config flow for Waze Travel Time.""" | ||
|
|
||
| VERSION = 1 | ||
| CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL | ||
|
|
||
| @staticmethod | ||
| @callback | ||
| def async_get_options_flow( | ||
| config_entry: config_entries.ConfigEntry, | ||
| ) -> WazeOptionsFlow: | ||
| """Get the options flow for this handler.""" | ||
| return WazeOptionsFlow(config_entry) | ||
|
|
||
| async def async_step_user(self, user_input=None): | ||
| """Handle the initial step.""" | ||
| if user_input is not None: | ||
| await self.async_set_unique_id( | ||
| slugify( | ||
| f"{DOMAIN}_{user_input[CONF_ORIGIN]}_{user_input[CONF_DESTINATION]}" | ||
| ) | ||
| ) | ||
| self._abort_if_unique_id_configured() | ||
|
MartinHjelmare marked this conversation as resolved.
Outdated
|
||
| return self.async_create_entry( | ||
| title=( | ||
| user_input.get( | ||
| CONF_NAME, | ||
| ( | ||
| f"{DEFAULT_NAME}: {user_input[CONF_ORIGIN]} -> " | ||
| f"{user_input[CONF_DESTINATION]}" | ||
| ), | ||
| ) | ||
| ), | ||
| data=user_input, | ||
| ) | ||
|
|
||
| return self.async_show_form( | ||
| step_id="user", | ||
| data_schema=vol.Schema( | ||
| { | ||
| vol.Required(CONF_ORIGIN): cv.string, | ||
| vol.Required(CONF_DESTINATION): cv.string, | ||
| vol.Required(CONF_REGION): vol.In(REGIONS), | ||
| } | ||
| ), | ||
| ) | ||
|
|
||
| async_step_import = async_step_user | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| """Constants for waze_travel_time.""" | ||
| from homeassistant.const import CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC | ||
|
|
||
| DOMAIN = "waze_travel_time" | ||
|
|
||
| ATTR_DESTINATION = "destination" | ||
| ATTR_DURATION = "duration" | ||
| ATTR_DISTANCE = "distance" | ||
| ATTR_ORIGIN = "origin" | ||
| ATTR_ROUTE = "route" | ||
|
|
||
| ATTRIBUTION = "Powered by Waze" | ||
|
|
||
| CONF_DESTINATION = "destination" | ||
| CONF_ORIGIN = "origin" | ||
| CONF_INCL_FILTER = "incl_filter" | ||
| CONF_EXCL_FILTER = "excl_filter" | ||
| CONF_REALTIME = "realtime" | ||
| CONF_UNITS = "units" | ||
| CONF_VEHICLE_TYPE = "vehicle_type" | ||
| CONF_AVOID_TOLL_ROADS = "avoid_toll_roads" | ||
| CONF_AVOID_SUBSCRIPTION_ROADS = "avoid_subscription_roads" | ||
| CONF_AVOID_FERRIES = "avoid_ferries" | ||
|
|
||
| DEFAULT_NAME = "Waze Travel Time" | ||
| DEFAULT_REALTIME = True | ||
| DEFAULT_VEHICLE_TYPE = "car" | ||
| DEFAULT_AVOID_TOLL_ROADS = False | ||
| DEFAULT_AVOID_SUBSCRIPTION_ROADS = False | ||
| DEFAULT_AVOID_FERRIES = False | ||
|
|
||
| ICON = "mdi:car" | ||
|
|
||
| UNITS = [CONF_UNIT_SYSTEM_METRIC, CONF_UNIT_SYSTEM_IMPERIAL] | ||
|
|
||
| REGIONS = ["US", "NA", "EU", "IL", "AU"] | ||
| VEHICLE_TYPES = ["car", "taxi", "motorcycle"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.