diff --git a/homeassistant/components/here_travel_time/config_flow.py b/homeassistant/components/here_travel_time/config_flow.py index e8a05796b669911f491d22cf41eb71ec1224d057..b4756c829224831c157a32aebc3b1531d150ff1b 100644 --- a/homeassistant/components/here_travel_time/config_flow.py +++ b/homeassistant/components/here_travel_time/config_flow.py @@ -11,6 +11,8 @@ from homeassistant import config_entries from homeassistant.const import ( CONF_API_KEY, CONF_ENTITY_NAMESPACE, + CONF_LATITUDE, + CONF_LONGITUDE, CONF_MODE, CONF_NAME, CONF_UNIT_SYSTEM, @@ -30,6 +32,8 @@ from .const import ( CONF_ARRIVAL_TIME, CONF_DEPARTURE, CONF_DEPARTURE_TIME, + CONF_DESTINATION, + CONF_ORIGIN, CONF_ROUTE_MODE, CONF_TRAFFIC_MODE, DEFAULT_NAME, @@ -187,13 +191,25 @@ class HERETravelTimeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ) -> FlowResult: """Configure origin by using gps coordinates.""" if user_input is not None: - self._config[CONF_ORIGIN_LATITUDE] = user_input["origin"]["latitude"] - self._config[CONF_ORIGIN_LONGITUDE] = user_input["origin"]["longitude"] + self._config[CONF_ORIGIN_LATITUDE] = user_input[CONF_ORIGIN][CONF_LATITUDE] + self._config[CONF_ORIGIN_LONGITUDE] = user_input[CONF_ORIGIN][ + CONF_LONGITUDE + ] return self.async_show_menu( step_id="destination_menu", menu_options=["destination_coordinates", "destination_entity"], ) - schema = vol.Schema({"origin": selector({LocationSelector.selector_type: {}})}) + schema = vol.Schema( + { + vol.Required( + CONF_ORIGIN, + default={ + CONF_LATITUDE: self.hass.config.latitude, + CONF_LONGITUDE: self.hass.config.longitude, + }, + ): LocationSelector() + } + ) return self.async_show_form(step_id="origin_coordinates", data_schema=schema) async def async_step_origin_entity( @@ -206,9 +222,7 @@ class HERETravelTimeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): step_id="destination_menu", menu_options=["destination_coordinates", "destination_entity"], ) - schema = vol.Schema( - {CONF_ORIGIN_ENTITY_ID: selector({EntitySelector.selector_type: {}})} - ) + schema = vol.Schema({vol.Required(CONF_ORIGIN_ENTITY_ID): EntitySelector()}) return self.async_show_form(step_id="origin_entity", data_schema=schema) async def async_step_destination_coordinates( @@ -217,11 +231,11 @@ class HERETravelTimeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ) -> FlowResult: """Configure destination by using gps coordinates.""" if user_input is not None: - self._config[CONF_DESTINATION_LATITUDE] = user_input["destination"][ - "latitude" + self._config[CONF_DESTINATION_LATITUDE] = user_input[CONF_DESTINATION][ + CONF_LATITUDE ] - self._config[CONF_DESTINATION_LONGITUDE] = user_input["destination"][ - "longitude" + self._config[CONF_DESTINATION_LONGITUDE] = user_input[CONF_DESTINATION][ + CONF_LONGITUDE ] return self.async_create_entry( title=self._config[CONF_NAME], @@ -229,7 +243,15 @@ class HERETravelTimeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): options=default_options(self.hass), ) schema = vol.Schema( - {"destination": selector({LocationSelector.selector_type: {}})} + { + vol.Required( + CONF_DESTINATION, + default={ + CONF_LATITUDE: self.hass.config.latitude, + CONF_LONGITUDE: self.hass.config.longitude, + }, + ): LocationSelector() + } ) return self.async_show_form( step_id="destination_coordinates", data_schema=schema @@ -250,7 +272,7 @@ class HERETravelTimeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): options=default_options(self.hass), ) schema = vol.Schema( - {CONF_DESTINATION_ENTITY_ID: selector({EntitySelector.selector_type: {}})} + {vol.Required(CONF_DESTINATION_ENTITY_ID): EntitySelector()} ) return self.async_show_form(step_id="destination_entity", data_schema=schema) diff --git a/homeassistant/components/here_travel_time/const.py b/homeassistant/components/here_travel_time/const.py index b3768b2d69dfa09921d62d0f60b7215968730085..4e9b8beaf12549617f3c0f539660bc95b6a47c63 100644 --- a/homeassistant/components/here_travel_time/const.py +++ b/homeassistant/components/here_travel_time/const.py @@ -9,9 +9,11 @@ DOMAIN = "here_travel_time" DEFAULT_SCAN_INTERVAL = 300 +CONF_DESTINATION = "destination" CONF_DESTINATION_LATITUDE = "destination_latitude" CONF_DESTINATION_LONGITUDE = "destination_longitude" CONF_DESTINATION_ENTITY_ID = "destination_entity_id" +CONF_ORIGIN = "origin" CONF_ORIGIN_LATITUDE = "origin_latitude" CONF_ORIGIN_LONGITUDE = "origin_longitude" CONF_ORIGIN_ENTITY_ID = "origin_entity_id"