Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions homeassistant/components/met/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -142,13 +137,10 @@ def untrack_home(self) -> None:
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] = []
Expand All @@ -165,14 +157,6 @@ def set_coordinates(self) -> bool:
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),
Expand Down
29 changes: 26 additions & 3 deletions homeassistant/components/met/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@
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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
)
),
}
)

Expand Down