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