From 1a335e971531a4a904859af1c16f5f312b358bcb Mon Sep 17 00:00:00 2001 From: Martin <32802427+mstu01@users.noreply.github.com> Date: Sun, 19 Jul 2026 19:39:51 +0200 Subject: [PATCH] Remove name field from Google Travel Time config flow (#176838) --- .../google_travel_time/config_flow.py | 16 ++++------------ .../components/google_travel_time/sensor.py | 3 +-- .../google_travel_time/strings.json | 1 - .../components/google_travel_time/conftest.py | 3 ++- .../google_travel_time/test_config_flow.py | 4 ++-- .../google_travel_time/test_sensor.py | 19 +++++++++++++++++++ 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/google_travel_time/config_flow.py b/homeassistant/components/google_travel_time/config_flow.py index cb2aaf8b18b2..c3ae0c0382cf 100644 --- a/homeassistant/components/google_travel_time/config_flow.py +++ b/homeassistant/components/google_travel_time/config_flow.py @@ -10,7 +10,7 @@ from homeassistant.config_entries import ( ConfigFlowResult, OptionsFlow, ) -from homeassistant.const import CONF_API_KEY, CONF_LANGUAGE, CONF_MODE, CONF_NAME +from homeassistant.const import CONF_API_KEY, CONF_LANGUAGE, CONF_MODE from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import config_validation as cv from homeassistant.helpers.selector import ( @@ -57,7 +57,7 @@ from .schemas import ( UNITS_SELECTOR, ) -RECONFIGURE_SCHEMA = vol.Schema( +CONFIG_SCHEMA = vol.Schema( { vol.Required(CONF_API_KEY): cv.string, vol.Required(CONF_DESTINATION): cv.string, @@ -65,14 +65,6 @@ RECONFIGURE_SCHEMA = vol.Schema( } ) -CONFIG_SCHEMA = RECONFIGURE_SCHEMA.extend( - { - # Name field is no longer allowed in config flow schemas - # pylint: disable-next=home-assistant-config-flow-name-field - vol.Required(CONF_NAME, default=DEFAULT_NAME): cv.string, - } -) - OPTIONS_SCHEMA = vol.Schema( { vol.Optional(CONF_LANGUAGE): LANGUAGE_SELECTOR, @@ -184,7 +176,7 @@ class GoogleTravelTimeConfigFlow(ConfigFlow, domain=DOMAIN): errors = await validate_input(self.hass, user_input) if not errors: return self.async_create_entry( - title=user_input.get(CONF_NAME, DEFAULT_NAME), + title=DEFAULT_NAME, data=user_input, options=default_options(self.hass), ) @@ -210,7 +202,7 @@ class GoogleTravelTimeConfigFlow(ConfigFlow, domain=DOMAIN): return self.async_show_form( step_id="reconfigure", data_schema=self.add_suggested_values_to_schema( - RECONFIGURE_SCHEMA, self._get_reconfigure_entry().data + CONFIG_SCHEMA, self._get_reconfigure_entry().data ), errors=errors, ) diff --git a/homeassistant/components/google_travel_time/sensor.py b/homeassistant/components/google_travel_time/sensor.py index ab1b01b8a640..3697998e262b 100644 --- a/homeassistant/components/google_travel_time/sensor.py +++ b/homeassistant/components/google_travel_time/sensor.py @@ -19,7 +19,6 @@ from homeassistant.const import ( CONF_API_KEY, CONF_LANGUAGE, CONF_MODE, - CONF_NAME, EVENT_HOMEASSISTANT_STARTED, UnitOfTime, ) @@ -74,7 +73,7 @@ async def async_setup_entry( api_key = config_entry.data[CONF_API_KEY] origin = config_entry.data[CONF_ORIGIN] destination = config_entry.data[CONF_DESTINATION] - name = config_entry.data.get(CONF_NAME, DEFAULT_NAME) + name = config_entry.title client_options = ClientOptions(api_key=api_key) client = RoutesAsyncClient(client_options=client_options) diff --git a/homeassistant/components/google_travel_time/strings.json b/homeassistant/components/google_travel_time/strings.json index 277f6e20b913..ea01c8f56d51 100644 --- a/homeassistant/components/google_travel_time/strings.json +++ b/homeassistant/components/google_travel_time/strings.json @@ -23,7 +23,6 @@ "data": { "api_key": "[%key:common::config_flow::data::api_key%]", "destination": "Destination", - "name": "[%key:common::config_flow::data::name%]", "origin": "Origin" }, "description": "You can specify the origin and destination in the form of an address, latitude/longitude coordinates or an entity ID that provides this information in its state, an entity ID with latitude and longitude attributes, or a zone's friendly name (case-sensitive)" diff --git a/tests/components/google_travel_time/conftest.py b/tests/components/google_travel_time/conftest.py index 23e5f540594b..e8d461c582bd 100644 --- a/tests/components/google_travel_time/conftest.py +++ b/tests/components/google_travel_time/conftest.py @@ -9,7 +9,7 @@ from google.protobuf import duration_pb2 from google.type import localized_text_pb2 import pytest -from homeassistant.components.google_travel_time.const import DOMAIN +from homeassistant.components.google_travel_time.const import DEFAULT_NAME, DOMAIN from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -22,6 +22,7 @@ async def mock_config_fixture( """Mock a Google Travel Time config entry.""" config_entry = MockConfigEntry( domain=DOMAIN, + title=DEFAULT_NAME, data=data, options=options, entry_id="test", diff --git a/tests/components/google_travel_time/test_config_flow.py b/tests/components/google_travel_time/test_config_flow.py index 460bb63b0d56..a6c2db43f605 100644 --- a/tests/components/google_travel_time/test_config_flow.py +++ b/tests/components/google_travel_time/test_config_flow.py @@ -29,7 +29,7 @@ from homeassistant.components.google_travel_time.const import ( UNITS_IMPERIAL, ) from homeassistant.config_entries import SOURCE_USER, ConfigFlowResult -from homeassistant.const import CONF_API_KEY, CONF_LANGUAGE, CONF_MODE, CONF_NAME +from homeassistant.const import CONF_API_KEY, CONF_LANGUAGE, CONF_MODE from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType @@ -63,6 +63,7 @@ async def assert_common_reconfigure_steps( await hass.async_block_till_done() entry = hass.config_entries.async_entries(DOMAIN)[0] + assert entry.title == DEFAULT_NAME assert entry.data == RECONFIGURE_CONFIG @@ -77,7 +78,6 @@ async def assert_common_create_steps( assert result["type"] is FlowResultType.CREATE_ENTRY assert result["title"] == DEFAULT_NAME assert result["data"] == { - CONF_NAME: DEFAULT_NAME, CONF_API_KEY: "api_key", CONF_ORIGIN: "location1", CONF_DESTINATION: "49.983862755708444,8.223882827079068", diff --git a/tests/components/google_travel_time/test_sensor.py b/tests/components/google_travel_time/test_sensor.py index 1d9e92004a7e..f405a924cf03 100644 --- a/tests/components/google_travel_time/test_sensor.py +++ b/tests/components/google_travel_time/test_sensor.py @@ -74,6 +74,25 @@ async def test_sensor(hass: HomeAssistant) -> None: ) +@pytest.mark.usefixtures("routes_mock") +async def test_sensor_name_from_entry_title(hass: HomeAssistant) -> None: + """Test that the sensor name is taken from the config entry title.""" + config_entry = MockConfigEntry( + domain=DOMAIN, + title="Home to work", + data=MOCK_CONFIG, + options=DEFAULT_OPTIONS, + entry_id="test", + ) + config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + + assert (state := hass.states.get("sensor.google_travel_time_home_to_work")) + assert state.name == "Google Travel Time Home to work" + assert state.state == "27.0" + + @pytest.mark.usefixtures("mock_update_empty", "mock_config") @pytest.mark.parametrize( ("data", "options"),