mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Explicitly pass in the config_entry in openweathermap coordinator (#138049)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
6cdc3acffb
commit
c3fae96bcf
@ -8,14 +8,7 @@ import logging
|
||||
from pyopenweathermap import create_owm_client
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_LANGUAGE,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_MODE,
|
||||
CONF_NAME,
|
||||
)
|
||||
from homeassistant.const import CONF_API_KEY, CONF_LANGUAGE, CONF_MODE, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import CONFIG_FLOW_VERSION, OWM_MODE_V25, PLATFORMS
|
||||
@ -43,8 +36,6 @@ async def async_setup_entry(
|
||||
"""Set up OpenWeatherMap as config entry."""
|
||||
name = entry.data[CONF_NAME]
|
||||
api_key = entry.data[CONF_API_KEY]
|
||||
latitude = entry.data.get(CONF_LATITUDE, hass.config.latitude)
|
||||
longitude = entry.data.get(CONF_LONGITUDE, hass.config.longitude)
|
||||
language = entry.options[CONF_LANGUAGE]
|
||||
mode = entry.options[CONF_MODE]
|
||||
|
||||
@ -54,9 +45,7 @@ async def async_setup_entry(
|
||||
async_delete_issue(hass, entry.entry_id)
|
||||
|
||||
owm_client = create_owm_client(api_key, mode, lang=language)
|
||||
weather_coordinator = WeatherUpdateCoordinator(
|
||||
owm_client, latitude, longitude, hass
|
||||
)
|
||||
weather_coordinator = WeatherUpdateCoordinator(hass, entry, owm_client)
|
||||
|
||||
await weather_coordinator.async_config_entry_first_refresh()
|
||||
|
||||
@ -69,7 +58,9 @@ async def async_setup_entry(
|
||||
return True
|
||||
|
||||
|
||||
async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_migrate_entry(
|
||||
hass: HomeAssistant, entry: OpenweathermapConfigEntry
|
||||
) -> bool:
|
||||
"""Migrate old entry."""
|
||||
config_entries = hass.config_entries
|
||||
data = entry.data
|
||||
@ -93,7 +84,9 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
async def async_update_options(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
async def async_update_options(
|
||||
hass: HomeAssistant, entry: OpenweathermapConfigEntry
|
||||
) -> None:
|
||||
"""Update options."""
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
"""Weather data coordinator for the OpenWeatherMap (OWM) service."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pyopenweathermap import (
|
||||
CurrentWeather,
|
||||
@ -17,11 +20,15 @@ from homeassistant.components.weather import (
|
||||
ATTR_CONDITION_SUNNY,
|
||||
Forecast,
|
||||
)
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import sun
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import OpenweathermapConfigEntry
|
||||
|
||||
from .const import (
|
||||
ATTR_API_CLOUDS,
|
||||
ATTR_API_CONDITION,
|
||||
@ -56,20 +63,25 @@ WEATHER_UPDATE_INTERVAL = timedelta(minutes=10)
|
||||
class WeatherUpdateCoordinator(DataUpdateCoordinator):
|
||||
"""Weather data update coordinator."""
|
||||
|
||||
config_entry: OpenweathermapConfigEntry
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
owm_client: OWMClient,
|
||||
latitude,
|
||||
longitude,
|
||||
hass: HomeAssistant,
|
||||
config_entry: OpenweathermapConfigEntry,
|
||||
owm_client: OWMClient,
|
||||
) -> None:
|
||||
"""Initialize coordinator."""
|
||||
self._owm_client = owm_client
|
||||
self._latitude = latitude
|
||||
self._longitude = longitude
|
||||
self._latitude = config_entry.data.get(CONF_LATITUDE, hass.config.latitude)
|
||||
self._longitude = config_entry.data.get(CONF_LONGITUDE, hass.config.longitude)
|
||||
|
||||
super().__init__(
|
||||
hass, _LOGGER, name=DOMAIN, update_interval=WEATHER_UPDATE_INTERVAL
|
||||
hass,
|
||||
_LOGGER,
|
||||
config_entry=config_entry,
|
||||
name=DOMAIN,
|
||||
update_interval=WEATHER_UPDATE_INTERVAL,
|
||||
)
|
||||
|
||||
async def _async_update_data(self):
|
||||
|
@ -1,14 +1,18 @@
|
||||
"""Issues for OpenWeatherMap."""
|
||||
|
||||
from typing import cast
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, cast
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.repairs import RepairsFlow
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_API_KEY, CONF_MODE
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import OpenweathermapConfigEntry
|
||||
|
||||
from .const import DOMAIN, OWM_MODE_V30
|
||||
from .utils import validate_api_key
|
||||
|
||||
@ -16,7 +20,7 @@ from .utils import validate_api_key
|
||||
class DeprecatedV25RepairFlow(RepairsFlow):
|
||||
"""Handler for an issue fixing flow."""
|
||||
|
||||
def __init__(self, entry: ConfigEntry) -> None:
|
||||
def __init__(self, entry: OpenweathermapConfigEntry) -> None:
|
||||
"""Create flow."""
|
||||
super().__init__()
|
||||
self.entry = entry
|
||||
|
Loading…
x
Reference in New Issue
Block a user