mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Use automatic title during config flow setup in Aurora (#99199)
This commit is contained in:
parent
bc665a1368
commit
9be5005a70
@ -5,7 +5,7 @@ import logging
|
||||
from auroranoaa import AuroraForecast
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, Platform
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
|
||||
@ -29,11 +29,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
longitude = conf[CONF_LONGITUDE]
|
||||
latitude = conf[CONF_LATITUDE]
|
||||
threshold = options.get(CONF_THRESHOLD, DEFAULT_THRESHOLD)
|
||||
name = conf[CONF_NAME]
|
||||
|
||||
coordinator = AuroraDataUpdateCoordinator(
|
||||
hass=hass,
|
||||
name=name,
|
||||
api=api,
|
||||
latitude=latitude,
|
||||
longitude=longitude,
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""Config flow for SpaceX Launches and Starman."""
|
||||
"""Config flow for Aurora."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
@ -8,7 +8,7 @@ from auroranoaa import AuroraForecast
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
||||
from homeassistant.helpers.schema_config_entry_flow import (
|
||||
@ -16,7 +16,7 @@ from homeassistant.helpers.schema_config_entry_flow import (
|
||||
SchemaOptionsFlowHandler,
|
||||
)
|
||||
|
||||
from .const import CONF_THRESHOLD, DEFAULT_NAME, DEFAULT_THRESHOLD, DOMAIN
|
||||
from .const import CONF_THRESHOLD, DEFAULT_THRESHOLD, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -50,7 +50,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
errors = {}
|
||||
|
||||
if user_input is not None:
|
||||
name = user_input[CONF_NAME]
|
||||
longitude = user_input[CONF_LONGITUDE]
|
||||
latitude = user_input[CONF_LATITUDE]
|
||||
|
||||
@ -70,7 +69,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(
|
||||
title=f"Aurora - {name}", data=user_input
|
||||
title="Aurora visibility", data=user_input
|
||||
)
|
||||
|
||||
return self.async_show_form(
|
||||
@ -78,13 +77,11 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
data_schema=self.add_suggested_values_to_schema(
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_NAME): str,
|
||||
vol.Required(CONF_LONGITUDE): cv.longitude,
|
||||
vol.Required(CONF_LATITUDE): cv.latitude,
|
||||
}
|
||||
),
|
||||
{
|
||||
CONF_NAME: DEFAULT_NAME,
|
||||
CONF_LONGITUDE: self.hass.config.longitude,
|
||||
CONF_LATITUDE: self.hass.config.latitude,
|
||||
},
|
||||
|
@ -6,4 +6,3 @@ AURORA_API = "aurora_api"
|
||||
CONF_THRESHOLD = "forecast_threshold"
|
||||
DEFAULT_THRESHOLD = 75
|
||||
ATTRIBUTION = "Data provided by the National Oceanic and Atmospheric Administration"
|
||||
DEFAULT_NAME = "Aurora Visibility"
|
||||
|
@ -18,7 +18,6 @@ class AuroraDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
name: str,
|
||||
api: AuroraForecast,
|
||||
latitude: float,
|
||||
longitude: float,
|
||||
@ -29,12 +28,11 @@ class AuroraDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
super().__init__(
|
||||
hass=hass,
|
||||
logger=_LOGGER,
|
||||
name=name,
|
||||
name="Aurora",
|
||||
update_interval=timedelta(minutes=5),
|
||||
)
|
||||
|
||||
self.api = api
|
||||
self.name = name
|
||||
self.latitude = int(latitude)
|
||||
self.longitude = int(longitude)
|
||||
self.threshold = int(threshold)
|
||||
|
@ -29,14 +29,9 @@ class AuroraEntity(CoordinatorEntity[AuroraDataUpdateCoordinator]):
|
||||
self._attr_translation_key = translation_key
|
||||
self._attr_unique_id = f"{coordinator.latitude}_{coordinator.longitude}"
|
||||
self._attr_icon = icon
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Define the device based on name."""
|
||||
return DeviceInfo(
|
||||
self._attr_device_info = DeviceInfo(
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
identifiers={(DOMAIN, str(self.unique_id))},
|
||||
identifiers={(DOMAIN, self._attr_unique_id)},
|
||||
manufacturer="NOAA",
|
||||
model="Aurora Visibility Sensor",
|
||||
name=self.coordinator.name,
|
||||
)
|
||||
|
@ -10,7 +10,6 @@ from homeassistant.core import HomeAssistant
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
DATA = {
|
||||
"name": "Home",
|
||||
"latitude": -10,
|
||||
"longitude": 10.2,
|
||||
}
|
||||
@ -39,7 +38,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == "create_entry"
|
||||
assert result2["title"] == "Aurora - Home"
|
||||
assert result2["title"] == "Aurora visibility"
|
||||
assert result2["data"] == DATA
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user