mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
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:
parent
7bdf034b93
commit
6005b6d01c
@ -1,17 +1,14 @@
|
|||||||
"""Support for Elgato Lights."""
|
"""Support for Elgato Lights."""
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .coordinator import ElgatoDataUpdateCoordinator
|
from .coordinator import ElgatoConfigEntry, ElgatoDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS = [Platform.BUTTON, Platform.LIGHT, Platform.SENSOR, Platform.SWITCH]
|
PLATFORMS = [Platform.BUTTON, Platform.LIGHT, Platform.SENSOR, Platform.SWITCH]
|
||||||
|
|
||||||
type ElgatorConfigEntry = ConfigEntry[ElgatoDataUpdateCoordinator]
|
|
||||||
|
|
||||||
|
async def async_setup_entry(hass: HomeAssistant, entry: ElgatoConfigEntry) -> bool:
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ElgatorConfigEntry) -> bool:
|
|
||||||
"""Set up Elgato Light from a config entry."""
|
"""Set up Elgato Light from a config entry."""
|
||||||
coordinator = ElgatoDataUpdateCoordinator(hass, entry)
|
coordinator = ElgatoDataUpdateCoordinator(hass, entry)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
@ -22,6 +19,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ElgatorConfigEntry) -> b
|
|||||||
return True
|
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."""
|
"""Unload Elgato Light config entry."""
|
||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
@ -18,8 +18,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import ElgatorConfigEntry
|
from .coordinator import ElgatoConfigEntry, ElgatoDataUpdateCoordinator
|
||||||
from .coordinator import ElgatoDataUpdateCoordinator
|
|
||||||
from .entity import ElgatoEntity
|
from .entity import ElgatoEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
@ -50,7 +49,7 @@ BUTTONS = [
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ElgatorConfigEntry,
|
entry: ElgatoConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Elgato button based on a config entry."""
|
"""Set up Elgato button based on a config entry."""
|
||||||
|
@ -12,6 +12,8 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
|||||||
|
|
||||||
from .const import DOMAIN, LOGGER, SCAN_INTERVAL
|
from .const import DOMAIN, LOGGER, SCAN_INTERVAL
|
||||||
|
|
||||||
|
type ElgatoConfigEntry = ConfigEntry[ElgatoDataUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ElgatoData:
|
class ElgatoData:
|
||||||
@ -26,10 +28,10 @@ class ElgatoData:
|
|||||||
class ElgatoDataUpdateCoordinator(DataUpdateCoordinator[ElgatoData]):
|
class ElgatoDataUpdateCoordinator(DataUpdateCoordinator[ElgatoData]):
|
||||||
"""Class to manage fetching Elgato data."""
|
"""Class to manage fetching Elgato data."""
|
||||||
|
|
||||||
config_entry: ConfigEntry
|
config_entry: ElgatoConfigEntry
|
||||||
has_battery: bool | None = None
|
has_battery: bool | None = None
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
|
def __init__(self, hass: HomeAssistant, entry: ElgatoConfigEntry) -> None:
|
||||||
"""Initialize the coordinator."""
|
"""Initialize the coordinator."""
|
||||||
self.config_entry = entry
|
self.config_entry = entry
|
||||||
self.client = Elgato(
|
self.client = Elgato(
|
||||||
@ -39,6 +41,7 @@ class ElgatoDataUpdateCoordinator(DataUpdateCoordinator[ElgatoData]):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
|
config_entry=entry,
|
||||||
name=f"{DOMAIN}_{entry.data[CONF_HOST]}",
|
name=f"{DOMAIN}_{entry.data[CONF_HOST]}",
|
||||||
update_interval=SCAN_INTERVAL,
|
update_interval=SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
|
@ -6,11 +6,11 @@ from typing import Any
|
|||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import ElgatorConfigEntry
|
from .coordinator import ElgatoConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
hass: HomeAssistant, entry: ElgatorConfigEntry
|
hass: HomeAssistant, entry: ElgatoConfigEntry
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Return diagnostics for a config entry."""
|
"""Return diagnostics for a config entry."""
|
||||||
coordinator = entry.runtime_data
|
coordinator = entry.runtime_data
|
||||||
|
@ -21,9 +21,8 @@ from homeassistant.helpers.entity_platform import (
|
|||||||
)
|
)
|
||||||
from homeassistant.util import color as color_util
|
from homeassistant.util import color as color_util
|
||||||
|
|
||||||
from . import ElgatorConfigEntry
|
|
||||||
from .const import SERVICE_IDENTIFY
|
from .const import SERVICE_IDENTIFY
|
||||||
from .coordinator import ElgatoDataUpdateCoordinator
|
from .coordinator import ElgatoConfigEntry, ElgatoDataUpdateCoordinator
|
||||||
from .entity import ElgatoEntity
|
from .entity import ElgatoEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
@ -31,7 +30,7 @@ PARALLEL_UPDATES = 1
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ElgatorConfigEntry,
|
entry: ElgatoConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Elgato Light based on a config entry."""
|
"""Set up Elgato Light based on a config entry."""
|
||||||
|
@ -21,8 +21,7 @@ from homeassistant.const import (
|
|||||||
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 . import ElgatorConfigEntry
|
from .coordinator import ElgatoConfigEntry, ElgatoData, ElgatoDataUpdateCoordinator
|
||||||
from .coordinator import ElgatoData, ElgatoDataUpdateCoordinator
|
|
||||||
from .entity import ElgatoEntity
|
from .entity import ElgatoEntity
|
||||||
|
|
||||||
# Coordinator is used to centralize the data updates
|
# Coordinator is used to centralize the data updates
|
||||||
@ -104,7 +103,7 @@ SENSORS = [
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ElgatorConfigEntry,
|
entry: ElgatoConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Elgato sensor based on a config entry."""
|
"""Set up Elgato sensor based on a config entry."""
|
||||||
|
@ -14,8 +14,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import ElgatorConfigEntry
|
from .coordinator import ElgatoConfigEntry, ElgatoData, ElgatoDataUpdateCoordinator
|
||||||
from .coordinator import ElgatoData, ElgatoDataUpdateCoordinator
|
|
||||||
from .entity import ElgatoEntity
|
from .entity import ElgatoEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
@ -54,7 +53,7 @@ SWITCHES = [
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ElgatorConfigEntry,
|
entry: ElgatoConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Elgato switches based on a config entry."""
|
"""Set up Elgato switches based on a config entry."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user