mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Display unit of elevation in met config flow (#88283)
* display unit of elevation in met config flow Co-authored-by: lijake8 <lijake8@users.noreply.github.com> Signed-off-by: Chris Xiao <30990835+chrisx8@users.noreply.github.com> * use NumberSelector for met config flow * met remove unused is_metric param --------- Signed-off-by: Chris Xiao <30990835+chrisx8@users.noreply.github.com> Co-authored-by: lijake8 <lijake8@users.noreply.github.com>
This commit is contained in:
parent
23a1a8075c
commit
e617bfb1bb
@ -18,15 +18,12 @@ from homeassistant.const import (
|
||||
CONF_LONGITUDE,
|
||||
EVENT_CORE_CONFIG_UPDATE,
|
||||
Platform,
|
||||
UnitOfLength,
|
||||
)
|
||||
from homeassistant.core import Event, HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from .const import (
|
||||
CONF_TRACK_HOME,
|
||||
@ -102,9 +99,7 @@ class MetDataUpdateCoordinator(DataUpdateCoordinator["MetWeatherData"]):
|
||||
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||
"""Initialize global Met data updater."""
|
||||
self._unsub_track_home: Callable[[], None] | None = None
|
||||
self.weather = MetWeatherData(
|
||||
hass, config_entry.data, hass.config.units is METRIC_SYSTEM
|
||||
)
|
||||
self.weather = MetWeatherData(hass, config_entry.data)
|
||||
self.weather.set_coordinates()
|
||||
|
||||
update_interval = timedelta(minutes=randrange(55, 65))
|
||||
@ -142,13 +137,10 @@ class MetDataUpdateCoordinator(DataUpdateCoordinator["MetWeatherData"]):
|
||||
class MetWeatherData:
|
||||
"""Keep data for Met.no weather entities."""
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, config: MappingProxyType[str, Any], is_metric: bool
|
||||
) -> None:
|
||||
def __init__(self, hass: HomeAssistant, config: MappingProxyType[str, Any]) -> None:
|
||||
"""Initialise the weather entity data."""
|
||||
self.hass = hass
|
||||
self._config = config
|
||||
self._is_metric = is_metric
|
||||
self._weather_data: metno.MetWeatherData
|
||||
self.current_weather_data: dict = {}
|
||||
self.daily_forecast: list[dict] = []
|
||||
@ -165,14 +157,6 @@ class MetWeatherData:
|
||||
latitude = self._config[CONF_LATITUDE]
|
||||
longitude = self._config[CONF_LONGITUDE]
|
||||
elevation = self._config[CONF_ELEVATION]
|
||||
if not self._is_metric:
|
||||
elevation = int(
|
||||
round(
|
||||
DistanceConverter.convert(
|
||||
elevation, UnitOfLength.FEET, UnitOfLength.METERS
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
coordinates = {
|
||||
"lat": str(latitude),
|
||||
|
@ -6,10 +6,21 @@ from typing import Any
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_ELEVATION, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
||||
from homeassistant.const import (
|
||||
CONF_ELEVATION,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_NAME,
|
||||
UnitOfLength,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.selector import (
|
||||
NumberSelector,
|
||||
NumberSelectorConfig,
|
||||
NumberSelectorMode,
|
||||
)
|
||||
|
||||
from .const import (
|
||||
CONF_TRACK_HOME,
|
||||
@ -47,7 +58,14 @@ def _get_data_schema(
|
||||
vol.Required(
|
||||
CONF_LONGITUDE, default=hass.config.longitude
|
||||
): cv.longitude,
|
||||
vol.Required(CONF_ELEVATION, default=hass.config.elevation): int,
|
||||
vol.Required(
|
||||
CONF_ELEVATION, default=hass.config.elevation
|
||||
): NumberSelector(
|
||||
NumberSelectorConfig(
|
||||
mode=NumberSelectorMode.BOX,
|
||||
unit_of_measurement=UnitOfLength.METERS,
|
||||
)
|
||||
),
|
||||
}
|
||||
)
|
||||
# Not tracking home, default values come from config entry
|
||||
@ -62,7 +80,12 @@ def _get_data_schema(
|
||||
): cv.longitude,
|
||||
vol.Required(
|
||||
CONF_ELEVATION, default=config_entry.data.get(CONF_ELEVATION)
|
||||
): int,
|
||||
): NumberSelector(
|
||||
NumberSelectorConfig(
|
||||
mode=NumberSelectorMode.BOX,
|
||||
unit_of_measurement=UnitOfLength.METERS,
|
||||
)
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user