Remove name field from Google Travel Time config flow (#176838)

This commit is contained in:
Martin
2026-07-19 10:39:51 -07:00
committed by GitHub
parent 68368e6315
commit 1a335e9715
6 changed files with 28 additions and 18 deletions
@@ -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,
)
@@ -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)
@@ -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)"
@@ -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",
@@ -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",
@@ -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"),