Remove name from Airly config flow (#169145)

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Maciej Bieniek
2026-04-26 13:38:50 +02:00
committed by GitHub
co-authored by Copilot
parent eed4acc745
commit e78a79a29e
8 changed files with 17 additions and 28 deletions
+9 -12
View File
@@ -12,11 +12,11 @@ from airly.exceptions import AirlyError
import voluptuous as vol
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import CONF_USE_NEAREST, DOMAIN, NO_AIRLY_SENSORS
from .const import CONF_USE_NEAREST, DEFAULT_NAME, DOMAIN, NO_AIRLY_SENSORS
DESCRIPTION_PLACEHOLDERS = {
"developer_registration_url": "https://developer.airly.eu/register",
@@ -45,16 +45,16 @@ class AirlyFlowHandler(ConfigFlow, domain=DOMAIN):
try:
location_point_valid = await check_location(
websession,
user_input["api_key"],
user_input["latitude"],
user_input["longitude"],
user_input[CONF_API_KEY],
user_input[CONF_LATITUDE],
user_input[CONF_LONGITUDE],
)
if not location_point_valid:
location_nearest_valid = await check_location(
websession,
user_input["api_key"],
user_input["latitude"],
user_input["longitude"],
user_input[CONF_API_KEY],
user_input[CONF_LATITUDE],
user_input[CONF_LONGITUDE],
use_nearest=True,
)
except AirlyError as err:
@@ -68,7 +68,7 @@ class AirlyFlowHandler(ConfigFlow, domain=DOMAIN):
return self.async_abort(reason="wrong_location")
use_nearest = True
return self.async_create_entry(
title=user_input[CONF_NAME],
title=DEFAULT_NAME,
data={**user_input, CONF_USE_NEAREST: use_nearest},
)
@@ -83,9 +83,6 @@ class AirlyFlowHandler(ConfigFlow, domain=DOMAIN):
vol.Optional(
CONF_LONGITUDE, default=self.hass.config.longitude
): cv.longitude,
vol.Optional(
CONF_NAME, default=self.hass.config.location_name
): str,
}
),
errors=errors,
+2
View File
@@ -37,3 +37,5 @@ MAX_UPDATE_INTERVAL: Final = 90
MIN_UPDATE_INTERVAL: Final = 5
NO_AIRLY_SENSORS: Final = "There are no Airly sensors in this area yet."
URL = "https://airly.org/map/#{latitude},{longitude}"
DEFAULT_NAME: Final = "Airly"
+1 -1
View File
@@ -178,7 +178,7 @@ async def async_setup_entry(
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up Airly sensor entities based on a config entry."""
name = entry.data[CONF_NAME]
name = entry.data.get(CONF_NAME) or entry.title
coordinator = entry.runtime_data
+1 -2
View File
@@ -13,8 +13,7 @@
"data": {
"api_key": "[%key:common::config_flow::data::api_key%]",
"latitude": "[%key:common::config_flow::data::latitude%]",
"longitude": "[%key:common::config_flow::data::longitude%]",
"name": "[%key:common::config_flow::data::name%]"
"longitude": "[%key:common::config_flow::data::longitude%]"
},
"description": "To generate API key go to {developer_registration_url}"
}
-1
View File
@@ -29,7 +29,6 @@ async def init_integration(
"api_key": "foo",
"latitude": 123,
"longitude": 456,
"name": "Home",
},
)
@@ -6,7 +6,6 @@
'api_key': '**REDACTED**',
'latitude': '**REDACTED**',
'longitude': '**REDACTED**',
'name': 'Home',
}),
'disabled_by': None,
'discovery_keys': dict({
+4 -5
View File
@@ -4,9 +4,9 @@ from http import HTTPStatus
from airly.exceptions import AirlyError
from homeassistant.components.airly.const import CONF_USE_NEAREST, DOMAIN
from homeassistant.components.airly.const import CONF_USE_NEAREST, DEFAULT_NAME, DOMAIN
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@@ -16,7 +16,6 @@ from tests.common import MockConfigEntry, async_load_fixture, patch
from tests.test_util.aiohttp import AiohttpClientMocker
CONFIG = {
CONF_NAME: "Home",
CONF_API_KEY: "foo",
CONF_LATITUDE: 123,
CONF_LONGITUDE: 456,
@@ -124,7 +123,7 @@ async def test_create_entry(
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == CONFIG[CONF_NAME]
assert result["title"] == DEFAULT_NAME
assert result["data"][CONF_LATITUDE] == CONFIG[CONF_LATITUDE]
assert result["data"][CONF_LONGITUDE] == CONFIG[CONF_LONGITUDE]
assert result["data"][CONF_API_KEY] == CONFIG[CONF_API_KEY]
@@ -151,7 +150,7 @@ async def test_create_entry_with_nearest_method(
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == CONFIG[CONF_NAME]
assert result["title"] == DEFAULT_NAME
assert result["data"][CONF_LATITUDE] == CONFIG[CONF_LATITUDE]
assert result["data"][CONF_LONGITUDE] == CONFIG[CONF_LONGITUDE]
assert result["data"][CONF_API_KEY] == CONFIG[CONF_API_KEY]
-6
View File
@@ -43,7 +43,6 @@ async def test_config_not_ready(
"api_key": "foo",
"latitude": 123,
"longitude": 456,
"name": "Home",
"use_nearest": True,
},
)
@@ -65,7 +64,6 @@ async def test_config_without_unique_id(
"api_key": "foo",
"latitude": 123,
"longitude": 456,
"name": "Home",
},
)
@@ -90,7 +88,6 @@ async def test_config_with_turned_off_station(
"api_key": "foo",
"latitude": 123,
"longitude": 456,
"name": "Home",
},
)
@@ -122,7 +119,6 @@ async def test_update_interval(
"api_key": "foo",
"latitude": 123,
"longitude": 456,
"name": "Home",
},
)
@@ -157,7 +153,6 @@ async def test_update_interval(
"api_key": "foo",
"latitude": 66.66,
"longitude": 111.11,
"name": "Work",
},
)
@@ -216,7 +211,6 @@ async def test_migrate_device_entry(
"api_key": "foo",
"latitude": 123,
"longitude": 456,
"name": "Home",
},
)