Cleanup extra dict from hass data in Elgato (#59587)

This commit is contained in:
Franck Nijhof 2021-11-12 18:03:57 +01:00 committed by GitHub
parent 8249959eac
commit 2841e402b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 8 deletions

View File

@ -10,7 +10,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import DATA_ELGATO_CLIENT, DOMAIN from .const import DOMAIN
PLATFORMS = [LIGHT_DOMAIN] PLATFORMS = [LIGHT_DOMAIN]
@ -31,8 +31,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
logging.getLogger(__name__).debug("Unable to connect: %s", exception) logging.getLogger(__name__).debug("Unable to connect: %s", exception)
raise ConfigEntryNotReady from exception raise ConfigEntryNotReady from exception
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})[entry.entry_id] = elgato
hass.data[DOMAIN][entry.entry_id] = {DATA_ELGATO_CLIENT: elgato}
hass.config_entries.async_setup_platforms(entry, PLATFORMS) hass.config_entries.async_setup_platforms(entry, PLATFORMS)
return True return True

View File

@ -3,9 +3,6 @@
# Integration domain # Integration domain
DOMAIN = "elgato" DOMAIN = "elgato"
# Home Assistant data keys
DATA_ELGATO_CLIENT = "elgato_client"
# Attributes # Attributes
ATTR_ON = "on" ATTR_ON = "on"

View File

@ -23,7 +23,7 @@ from homeassistant.helpers.entity_platform import (
async_get_current_platform, async_get_current_platform,
) )
from .const import DATA_ELGATO_CLIENT, DOMAIN, SERVICE_IDENTIFY from .const import DOMAIN, SERVICE_IDENTIFY
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -37,7 +37,7 @@ async def async_setup_entry(
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."""
elgato: Elgato = hass.data[DOMAIN][entry.entry_id][DATA_ELGATO_CLIENT] elgato: Elgato = hass.data[DOMAIN][entry.entry_id]
info = await elgato.info() info = await elgato.info()
settings = await elgato.settings() settings = await elgato.settings()
async_add_entities([ElgatoLight(elgato, info, settings)], True) async_add_entities([ElgatoLight(elgato, info, settings)], True)