Use typed ConfigEntry throughout HEOS (#136569)

This commit is contained in:
Andrew Sayre 2025-01-26 09:41:04 -06:00 committed by GitHub
parent c9218b91c1
commit b467bb2813
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 13 additions and 11 deletions

View File

@ -4,7 +4,6 @@ from __future__ import annotations
from datetime import timedelta
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
@ -13,7 +12,7 @@ from homeassistant.helpers.typing import ConfigType
from . import services
from .const import DOMAIN
from .coordinator import HeosCoordinator
from .coordinator import HeosConfigEntry, HeosCoordinator
PLATFORMS = [Platform.MEDIA_PLAYER]
@ -21,8 +20,6 @@ MIN_UPDATE_SOURCES = timedelta(seconds=1)
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
type HeosConfigEntry = ConfigEntry[HeosCoordinator]
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the HEOS component."""

View File

@ -9,7 +9,6 @@ from pyheos import CommandAuthenticationError, Heos, HeosError, HeosOptions
import voluptuous as vol
from homeassistant.config_entries import (
ConfigEntry,
ConfigEntryState,
ConfigFlow,
ConfigFlowResult,
@ -23,8 +22,8 @@ from homeassistant.helpers.service_info.ssdp import (
SsdpServiceInfo,
)
from . import HeosConfigEntry
from .const import DOMAIN
from .coordinator import HeosConfigEntry
_LOGGER = logging.getLogger(__name__)
@ -107,7 +106,7 @@ class HeosFlowHandler(ConfigFlow, domain=DOMAIN):
@staticmethod
@callback
def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow:
def async_get_options_flow(config_entry: HeosConfigEntry) -> OptionsFlow:
"""Create the options flow."""
return HeosOptionsFlowHandler()

View File

@ -33,11 +33,13 @@ from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
type HeosConfigEntry = ConfigEntry[HeosCoordinator]
class HeosCoordinator(DataUpdateCoordinator[None]):
"""Define the HEOS integration coordinator."""
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
def __init__(self, hass: HomeAssistant, config_entry: HeosConfigEntry) -> None:
"""Set up the coordinator and set in config_entry."""
self.host: str = config_entry.data[CONF_HOST]
credentials: Credentials | None = None

View File

@ -38,9 +38,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util.dt import utcnow
from . import HeosConfigEntry
from .const import DOMAIN as HEOS_DOMAIN
from .coordinator import HeosCoordinator
from .coordinator import HeosConfigEntry, HeosCoordinator
PARALLEL_UPDATES = 0

View File

@ -1,6 +1,7 @@
"""Services for the HEOS integration."""
import logging
from typing import cast
from pyheos import CommandAuthenticationError, Heos, HeosError
import voluptuous as vol
@ -17,6 +18,7 @@ from .const import (
SERVICE_SIGN_IN,
SERVICE_SIGN_OUT,
)
from .coordinator import HeosConfigEntry
_LOGGER = logging.getLogger(__name__)
@ -59,7 +61,10 @@ def _get_controller(hass: HomeAssistant) -> Heos:
translation_key="sign_in_out_deprecated",
)
entry = hass.config_entries.async_entry_for_domain_unique_id(DOMAIN, DOMAIN)
entry = cast(
HeosConfigEntry,
hass.config_entries.async_entry_for_domain_unique_id(DOMAIN, DOMAIN),
)
if not entry or not entry.state == ConfigEntryState.LOADED:
raise HomeAssistantError(
translation_domain=DOMAIN, translation_key="integration_not_loaded"