Explicitly pass config entry to coordinator in Elgato (#133014)

* Explicitly pass config entry to coordinator in Elgato

* Make it noice!

* Apply suggestions from code review

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* Adjustment from review comment

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
Franck Nijhof 2024-12-12 13:55:57 +01:00 committed by GitHub
parent 7bdf034b93
commit 6005b6d01c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 18 additions and 22 deletions

View File

@ -1,17 +1,14 @@
"""Support for Elgato Lights."""
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from .coordinator import ElgatoDataUpdateCoordinator
from .coordinator import ElgatoConfigEntry, ElgatoDataUpdateCoordinator
PLATFORMS = [Platform.BUTTON, Platform.LIGHT, Platform.SENSOR, Platform.SWITCH]
type ElgatorConfigEntry = ConfigEntry[ElgatoDataUpdateCoordinator]
async def async_setup_entry(hass: HomeAssistant, entry: ElgatorConfigEntry) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ElgatoConfigEntry) -> bool:
"""Set up Elgato Light from a config entry."""
coordinator = ElgatoDataUpdateCoordinator(hass, entry)
await coordinator.async_config_entry_first_refresh()
@ -22,6 +19,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ElgatorConfigEntry) -> b
return True
async def async_unload_entry(hass: HomeAssistant, entry: ElgatorConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: ElgatoConfigEntry) -> bool:
"""Unload Elgato Light config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

View File

@ -18,8 +18,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import ElgatorConfigEntry
from .coordinator import ElgatoDataUpdateCoordinator
from .coordinator import ElgatoConfigEntry, ElgatoDataUpdateCoordinator
from .entity import ElgatoEntity
PARALLEL_UPDATES = 1
@ -50,7 +49,7 @@ BUTTONS = [
async def async_setup_entry(
hass: HomeAssistant,
entry: ElgatorConfigEntry,
entry: ElgatoConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Elgato button based on a config entry."""

View File

@ -12,6 +12,8 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
from .const import DOMAIN, LOGGER, SCAN_INTERVAL
type ElgatoConfigEntry = ConfigEntry[ElgatoDataUpdateCoordinator]
@dataclass
class ElgatoData:
@ -26,10 +28,10 @@ class ElgatoData:
class ElgatoDataUpdateCoordinator(DataUpdateCoordinator[ElgatoData]):
"""Class to manage fetching Elgato data."""
config_entry: ConfigEntry
config_entry: ElgatoConfigEntry
has_battery: bool | None = None
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
def __init__(self, hass: HomeAssistant, entry: ElgatoConfigEntry) -> None:
"""Initialize the coordinator."""
self.config_entry = entry
self.client = Elgato(
@ -39,6 +41,7 @@ class ElgatoDataUpdateCoordinator(DataUpdateCoordinator[ElgatoData]):
super().__init__(
hass,
LOGGER,
config_entry=entry,
name=f"{DOMAIN}_{entry.data[CONF_HOST]}",
update_interval=SCAN_INTERVAL,
)

View File

@ -6,11 +6,11 @@ from typing import Any
from homeassistant.core import HomeAssistant
from . import ElgatorConfigEntry
from .coordinator import ElgatoConfigEntry
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ElgatorConfigEntry
hass: HomeAssistant, entry: ElgatoConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinator = entry.runtime_data

View File

@ -21,9 +21,8 @@ from homeassistant.helpers.entity_platform import (
)
from homeassistant.util import color as color_util
from . import ElgatorConfigEntry
from .const import SERVICE_IDENTIFY
from .coordinator import ElgatoDataUpdateCoordinator
from .coordinator import ElgatoConfigEntry, ElgatoDataUpdateCoordinator
from .entity import ElgatoEntity
PARALLEL_UPDATES = 1
@ -31,7 +30,7 @@ PARALLEL_UPDATES = 1
async def async_setup_entry(
hass: HomeAssistant,
entry: ElgatorConfigEntry,
entry: ElgatoConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Elgato Light based on a config entry."""

View File

@ -21,8 +21,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import ElgatorConfigEntry
from .coordinator import ElgatoData, ElgatoDataUpdateCoordinator
from .coordinator import ElgatoConfigEntry, ElgatoData, ElgatoDataUpdateCoordinator
from .entity import ElgatoEntity
# Coordinator is used to centralize the data updates
@ -104,7 +103,7 @@ SENSORS = [
async def async_setup_entry(
hass: HomeAssistant,
entry: ElgatorConfigEntry,
entry: ElgatoConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Elgato sensor based on a config entry."""

View File

@ -14,8 +14,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import ElgatorConfigEntry
from .coordinator import ElgatoData, ElgatoDataUpdateCoordinator
from .coordinator import ElgatoConfigEntry, ElgatoData, ElgatoDataUpdateCoordinator
from .entity import ElgatoEntity
PARALLEL_UPDATES = 1
@ -54,7 +53,7 @@ SWITCHES = [
async def async_setup_entry(
hass: HomeAssistant,
entry: ElgatorConfigEntry,
entry: ElgatoConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Elgato switches based on a config entry."""