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