Reduce config entry setup/unload boilerplate D-F (#49733)

This commit is contained in:
J. Nick Koston 2021-04-26 20:46:49 -10:00 committed by GitHub
parent 58ad3b61f7
commit a67b9eff17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 157 additions and 464 deletions

View file

@ -18,10 +18,11 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
PLATFORMS = ["sensor"]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Azure DevOps from a config entry."""
@ -43,18 +44,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data.setdefault(instance_key, {})[DATA_AZURE_DEVOPS_CLIENT] = client
# Setup components
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "sensor")
)
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigType) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload Azure DevOps config entry."""
del hass.data[f"{DOMAIN}_{entry.data[CONF_ORG]}_{entry.data[CONF_PROJECT]}"]
return await hass.config_entries.async_forward_entry_unload(entry, "sensor")
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
class AzureDevOpsEntity(Entity):