Use device registry

This commit is contained in:
2020-11-07 00:41:19 +01:00
parent a384b48331
commit 6d72011bed
9 changed files with 169 additions and 9 deletions

View File

@@ -1,5 +1,7 @@
import logging
from homeassistant import config_entries
from .mod_view import setup_view
from .connection import setup_connection
from .service import setup_service
@@ -13,11 +15,32 @@ from .const import (
DATA_SETUP_COMPLETE,
)
COMPONENTS = [
"media_player",
"sensor",
"binary_sensor",
"light",
"camera",
]
_LOGGER = logging.getLogger(__name__)
async def async_setup(hass, config):
_LOGGER.error(hass.config_entries)
if not hass.config_entries.async_entries(DOMAIN):
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_IMPORT
},
data={}
)
)
aliases = {}
for d in config[DOMAIN].get(CONFIG_DEVICES, {}):
name = config[DOMAIN][CONFIG_DEVICES][d].get("name", None)
@@ -35,12 +58,15 @@ async def async_setup(hass, config):
await setup_connection(hass, config)
setup_view(hass)
async_load_platform = hass.helpers.discovery.async_load_platform
await async_load_platform("media_player", DOMAIN, {}, config)
await async_load_platform("sensor", DOMAIN, {}, config)
await async_load_platform("binary_sensor", DOMAIN, {}, config)
await async_load_platform("light", DOMAIN, {}, config)
await async_load_platform("camera", DOMAIN, {}, config)
for component in COMPONENTS:
hass.async_create_task(
hass.helpers.discovery.async_load_platform(
component,
DOMAIN,
{},
config
)
)
await setup_service(hass)
@@ -50,3 +76,14 @@ async def async_setup(hass, config):
device.trigger_update()
return True
async def async_setup_entry(hass, config_entry):
for component in COMPONENTS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(
config_entry,
component
)
)
return True