0.7.0
This commit is contained in:
@@ -5,17 +5,26 @@ from dataclasses import dataclass
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.update import UpdateEntity, UpdateEntityFeature
|
from homeassistant.components.update import UpdateEntity, UpdateEntityFeature
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
|
|
||||||
from .core import DOMAIN, SIGNAL_UPDATED, BCSCore
|
from .const import DOMAIN
|
||||||
|
from .core import SIGNAL_UPDATED, BCSCore
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_core(hass: HomeAssistant) -> BCSCore | None:
|
||||||
|
data = hass.data.get(DOMAIN)
|
||||||
|
if isinstance(data, dict):
|
||||||
|
c = data.get("_core")
|
||||||
|
return c if isinstance(c, BCSCore) else None
|
||||||
|
# Backwards compatibility (older versions used hass.data[DOMAIN] = core)
|
||||||
|
return data if isinstance(data, BCSCore) else None
|
||||||
|
|
||||||
|
|
||||||
def _pretty_repo_name(core: BCSCore, repo_id: str) -> str:
|
def _pretty_repo_name(core: BCSCore, repo_id: str) -> str:
|
||||||
"""Return a human-friendly name for a repo update entity."""
|
"""Return a human-friendly name for a repo update entity."""
|
||||||
try:
|
try:
|
||||||
@@ -140,9 +149,14 @@ def _sync_entities(core: BCSCore, existing: dict[str, BCSRepoUpdateEntity], asyn
|
|||||||
ent.async_write_ha_state()
|
ent.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
async def _async_setup(hass: HomeAssistant, async_add_entities: AddEntitiesCallback) -> None:
|
async def async_setup_platform(
|
||||||
"""Common update entity setup for both config entries and legacy YAML."""
|
hass: HomeAssistant,
|
||||||
core: BCSCore | None = hass.data.get(DOMAIN)
|
config,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
discovery_info=None,
|
||||||
|
):
|
||||||
|
"""Set up BCS update entities."""
|
||||||
|
core: BCSCore | None = _get_core(hass)
|
||||||
if not core:
|
if not core:
|
||||||
_LOGGER.debug("BCS core not available, skipping update platform setup")
|
_LOGGER.debug("BCS core not available, skipping update platform setup")
|
||||||
return
|
return
|
||||||
@@ -160,18 +174,8 @@ async def _async_setup(hass: HomeAssistant, async_add_entities: AddEntitiesCallb
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up update entities from a config entry."""
|
"""Set up BCS update entities from a config entry."""
|
||||||
await _async_setup(hass, async_add_entities)
|
await async_setup_platform(hass, {}, async_add_entities, None)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
config,
|
|
||||||
async_add_entities: AddEntitiesCallback,
|
|
||||||
discovery_info=None,
|
|
||||||
):
|
|
||||||
"""Legacy YAML setup (not supported, kept for safety)."""
|
|
||||||
await _async_setup(hass, async_add_entities)
|
|
||||||
Reference in New Issue
Block a user