config_entry forwarded only to proper platform; DOMAIN imported from component

This commit is contained in:
rospogrigio
2020-09-15 10:59:06 +02:00
parent 97ada3de4f
commit 386d59b497
5 changed files with 18 additions and 20 deletions

View File

@@ -75,10 +75,12 @@ async def async_setup(hass: HomeAssistant, config: dict):
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up LocalTuya integration from a config entry."""
for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
)
for platform in PLATFORMS:
# print("ASE*** [{}] [{}]".format(entry.data["entities"][0][CONF_PLATFORM], platform))
if entry.data["entities"][0][CONF_PLATFORM] == platform:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, platform)
)
return True

View File

@@ -26,6 +26,7 @@ import voluptuous as vol
from homeassistant.components.cover import (
CoverEntity,
DOMAIN,
PLATFORM_SCHEMA,
SUPPORT_CLOSE,
SUPPORT_OPEN,
@@ -44,8 +45,6 @@ from .pytuya import TuyaDevice
_LOGGER = logging.getLogger(__name__)
PLATFORM = "cover"
DEFAULT_OPEN_CMD = "on"
DEFAULT_CLOSE_CMD = "off"
DEFAULT_STOP_CMD = "stop"
@@ -72,7 +71,7 @@ def flow_schema(dps):
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Setup a Tuya cover based on a config entry."""
device, entities_to_setup = prepare_setup_entities(
config_entry, PLATFORM
config_entry, DOMAIN
)
if not entities_to_setup:
return
@@ -102,7 +101,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up of the Tuya cover."""
return import_from_yaml(hass, config, PLATFORM)
return import_from_yaml(hass, config, DOMAIN)
class TuyaCache:

View File

@@ -20,6 +20,7 @@ import voluptuous as vol
from homeassistant.components.fan import (
FanEntity,
DOMAIN,
PLATFORM_SCHEMA,
SPEED_LOW,
SPEED_MEDIUM,
@@ -36,8 +37,6 @@ from .pytuya import TuyaDevice
_LOGGER = logging.getLogger(__name__)
PLATFORM = "fan"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(BASE_PLATFORM_SCHEMA)
@@ -49,7 +48,7 @@ def flow_schema(dps):
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Setup a Tuya fan based on a config entry."""
device, entities_to_setup = prepare_setup_entities(
config_entry, PLATFORM
config_entry, DOMAIN
)
if not entities_to_setup:
return
@@ -69,7 +68,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up of the Tuya fan."""
return import_from_yaml(hass, config, PLATFORM)
return import_from_yaml(hass, config, DOMAIN)
class LocaltuyaFan(FanEntity):

View File

@@ -23,6 +23,7 @@ from homeassistant.const import (
)
from homeassistant.components.light import (
LightEntity,
DOMAIN,
PLATFORM_SCHEMA,
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
@@ -38,8 +39,6 @@ from .pytuya import TuyaDevice
_LOGGER = logging.getLogger(__name__)
PLATFORM = "light"
MIN_MIRED = 153
MAX_MIRED = 370
UPDATE_RETRY_LIMIT = 3
@@ -55,7 +54,7 @@ def flow_schema(dps):
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Setup a Tuya switch based on a config entry."""
device, entities_to_setup = prepare_setup_entities(
config_entry, PLATFORM
config_entry, DOMAIN
)
if not entities_to_setup:
return
@@ -75,7 +74,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up of the Tuya switch."""
return import_from_yaml(hass, config, PLATFORM)
return import_from_yaml(hass, config, DOMAIN)
class TuyaCache:

View File

@@ -32,6 +32,7 @@ import voluptuous as vol
from homeassistant.components.switch import (
SwitchEntity,
DOMAIN,
PLATFORM_SCHEMA,
)
from homeassistant.const import (
@@ -55,8 +56,6 @@ from .pytuya import TuyaDevice
_LOGGER = logging.getLogger(__name__)
PLATFORM = "switch"
DEFAULT_ID = "1"
# TODO: This will eventully merge with flow_schema
@@ -93,7 +92,7 @@ def flow_schema(dps):
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Setup a Tuya switch based on a config entry."""
device, entities_to_setup = prepare_setup_entities(
config_entry, PLATFORM
config_entry, DOMAIN
)
if not entities_to_setup:
return
@@ -116,7 +115,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up of the Tuya switch."""
return import_from_yaml(hass, config, PLATFORM)
return import_from_yaml(hass, config, DOMAIN)
class TuyaCache: