Use runtime data in version (#120363)
This commit is contained in:
parent
fb3059e6e6
commit
00621ad512
4 changed files with 17 additions and 22 deletions
|
@ -16,15 +16,16 @@ from .const import (
|
||||||
CONF_CHANNEL,
|
CONF_CHANNEL,
|
||||||
CONF_IMAGE,
|
CONF_IMAGE,
|
||||||
CONF_SOURCE,
|
CONF_SOURCE,
|
||||||
DOMAIN,
|
|
||||||
PLATFORMS,
|
PLATFORMS,
|
||||||
)
|
)
|
||||||
from .coordinator import VersionDataUpdateCoordinator
|
from .coordinator import VersionDataUpdateCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type VersionConfigEntry = ConfigEntry[VersionDataUpdateCoordinator]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
||||||
|
async def async_setup_entry(hass: HomeAssistant, entry: VersionConfigEntry) -> bool:
|
||||||
"""Set up the version integration from a config entry."""
|
"""Set up the version integration from a config entry."""
|
||||||
|
|
||||||
board = entry.data[CONF_BOARD]
|
board = entry.data[CONF_BOARD]
|
||||||
|
@ -50,14 +51,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
)
|
)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
entry.runtime_data = coordinator
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: VersionConfigEntry) -> bool:
|
||||||
"""Unload the config entry."""
|
"""Unload the config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
return unload_ok
|
|
||||||
|
|
|
@ -9,13 +9,12 @@ from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
BinarySensorEntityDescription,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_NAME, EntityCategory, __version__ as HA_VERSION
|
from homeassistant.const import CONF_NAME, EntityCategory, __version__ as HA_VERSION
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import CONF_SOURCE, DEFAULT_NAME, DOMAIN
|
from . import VersionConfigEntry
|
||||||
from .coordinator import VersionDataUpdateCoordinator
|
from .const import CONF_SOURCE, DEFAULT_NAME
|
||||||
from .entity import VersionEntity
|
from .entity import VersionEntity
|
||||||
|
|
||||||
HA_VERSION_OBJECT = AwesomeVersion(HA_VERSION)
|
HA_VERSION_OBJECT = AwesomeVersion(HA_VERSION)
|
||||||
|
@ -23,11 +22,11 @@ HA_VERSION_OBJECT = AwesomeVersion(HA_VERSION)
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: VersionConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up version binary_sensors."""
|
"""Set up version binary_sensors."""
|
||||||
coordinator: VersionDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
if (source := config_entry.data[CONF_SOURCE]) == "local":
|
if (source := config_entry.data[CONF_SOURCE]) == "local":
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -6,20 +6,18 @@ from typing import Any
|
||||||
|
|
||||||
from attr import asdict
|
from attr import asdict
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
|
|
||||||
from .const import DOMAIN
|
from . import VersionConfigEntry
|
||||||
from .coordinator import VersionDataUpdateCoordinator
|
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: VersionConfigEntry,
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Return diagnostics for a config entry."""
|
"""Return diagnostics for a config entry."""
|
||||||
coordinator: VersionDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
|
|
||||||
|
|
|
@ -5,24 +5,23 @@ from __future__ import annotations
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from .const import CONF_SOURCE, DEFAULT_NAME, DOMAIN
|
from . import VersionConfigEntry
|
||||||
from .coordinator import VersionDataUpdateCoordinator
|
from .const import CONF_SOURCE, DEFAULT_NAME
|
||||||
from .entity import VersionEntity
|
from .entity import VersionEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: VersionConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up version sensors."""
|
"""Set up version sensors."""
|
||||||
coordinator: VersionDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
if (entity_name := entry.data[CONF_NAME]) == DEFAULT_NAME:
|
if (entity_name := entry.data[CONF_NAME]) == DEFAULT_NAME:
|
||||||
entity_name = entry.title
|
entity_name = entry.title
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue