config_entry forwarded only to proper platform; DOMAIN imported from component
This commit is contained in:
@@ -75,10 +75,12 @@ async def async_setup(hass: HomeAssistant, config: dict):
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Set up LocalTuya integration from a config entry."""
|
"""Set up LocalTuya integration from a config entry."""
|
||||||
for component in PLATFORMS:
|
for platform in PLATFORMS:
|
||||||
hass.async_create_task(
|
# print("ASE*** [{}] [{}]".format(entry.data["entities"][0][CONF_PLATFORM], platform))
|
||||||
hass.config_entries.async_forward_entry_setup(entry, component)
|
if entry.data["entities"][0][CONF_PLATFORM] == platform:
|
||||||
)
|
hass.async_create_task(
|
||||||
|
hass.config_entries.async_forward_entry_setup(entry, platform)
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
|
DOMAIN,
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
SUPPORT_CLOSE,
|
SUPPORT_CLOSE,
|
||||||
SUPPORT_OPEN,
|
SUPPORT_OPEN,
|
||||||
@@ -44,8 +45,6 @@ from .pytuya import TuyaDevice
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORM = "cover"
|
|
||||||
|
|
||||||
DEFAULT_OPEN_CMD = "on"
|
DEFAULT_OPEN_CMD = "on"
|
||||||
DEFAULT_CLOSE_CMD = "off"
|
DEFAULT_CLOSE_CMD = "off"
|
||||||
DEFAULT_STOP_CMD = "stop"
|
DEFAULT_STOP_CMD = "stop"
|
||||||
@@ -72,7 +71,7 @@ def flow_schema(dps):
|
|||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Setup a Tuya cover based on a config entry."""
|
"""Setup a Tuya cover based on a config entry."""
|
||||||
device, entities_to_setup = prepare_setup_entities(
|
device, entities_to_setup = prepare_setup_entities(
|
||||||
config_entry, PLATFORM
|
config_entry, DOMAIN
|
||||||
)
|
)
|
||||||
if not entities_to_setup:
|
if not entities_to_setup:
|
||||||
return
|
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):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up of the Tuya cover."""
|
"""Set up of the Tuya cover."""
|
||||||
return import_from_yaml(hass, config, PLATFORM)
|
return import_from_yaml(hass, config, DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
class TuyaCache:
|
class TuyaCache:
|
||||||
|
@@ -20,6 +20,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.fan import (
|
from homeassistant.components.fan import (
|
||||||
FanEntity,
|
FanEntity,
|
||||||
|
DOMAIN,
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
SPEED_LOW,
|
SPEED_LOW,
|
||||||
SPEED_MEDIUM,
|
SPEED_MEDIUM,
|
||||||
@@ -36,8 +37,6 @@ from .pytuya import TuyaDevice
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORM = "fan"
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(BASE_PLATFORM_SCHEMA)
|
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):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Setup a Tuya fan based on a config entry."""
|
"""Setup a Tuya fan based on a config entry."""
|
||||||
device, entities_to_setup = prepare_setup_entities(
|
device, entities_to_setup = prepare_setup_entities(
|
||||||
config_entry, PLATFORM
|
config_entry, DOMAIN
|
||||||
)
|
)
|
||||||
if not entities_to_setup:
|
if not entities_to_setup:
|
||||||
return
|
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):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up of the Tuya fan."""
|
"""Set up of the Tuya fan."""
|
||||||
return import_from_yaml(hass, config, PLATFORM)
|
return import_from_yaml(hass, config, DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
class LocaltuyaFan(FanEntity):
|
class LocaltuyaFan(FanEntity):
|
||||||
|
@@ -23,6 +23,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
LightEntity,
|
LightEntity,
|
||||||
|
DOMAIN,
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP,
|
||||||
@@ -38,8 +39,6 @@ from .pytuya import TuyaDevice
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORM = "light"
|
|
||||||
|
|
||||||
MIN_MIRED = 153
|
MIN_MIRED = 153
|
||||||
MAX_MIRED = 370
|
MAX_MIRED = 370
|
||||||
UPDATE_RETRY_LIMIT = 3
|
UPDATE_RETRY_LIMIT = 3
|
||||||
@@ -55,7 +54,7 @@ def flow_schema(dps):
|
|||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Setup a Tuya switch based on a config entry."""
|
"""Setup a Tuya switch based on a config entry."""
|
||||||
device, entities_to_setup = prepare_setup_entities(
|
device, entities_to_setup = prepare_setup_entities(
|
||||||
config_entry, PLATFORM
|
config_entry, DOMAIN
|
||||||
)
|
)
|
||||||
if not entities_to_setup:
|
if not entities_to_setup:
|
||||||
return
|
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):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up of the Tuya switch."""
|
"""Set up of the Tuya switch."""
|
||||||
return import_from_yaml(hass, config, PLATFORM)
|
return import_from_yaml(hass, config, DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
class TuyaCache:
|
class TuyaCache:
|
||||||
|
@@ -32,6 +32,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.switch import (
|
from homeassistant.components.switch import (
|
||||||
SwitchEntity,
|
SwitchEntity,
|
||||||
|
DOMAIN,
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@@ -55,8 +56,6 @@ from .pytuya import TuyaDevice
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORM = "switch"
|
|
||||||
|
|
||||||
DEFAULT_ID = "1"
|
DEFAULT_ID = "1"
|
||||||
|
|
||||||
# TODO: This will eventully merge with flow_schema
|
# 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):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Setup a Tuya switch based on a config entry."""
|
"""Setup a Tuya switch based on a config entry."""
|
||||||
device, entities_to_setup = prepare_setup_entities(
|
device, entities_to_setup = prepare_setup_entities(
|
||||||
config_entry, PLATFORM
|
config_entry, DOMAIN
|
||||||
)
|
)
|
||||||
if not entities_to_setup:
|
if not entities_to_setup:
|
||||||
return
|
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):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up of the Tuya switch."""
|
"""Set up of the Tuya switch."""
|
||||||
return import_from_yaml(hass, config, PLATFORM)
|
return import_from_yaml(hass, config, DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
class TuyaCache:
|
class TuyaCache:
|
||||||
|
Reference in New Issue
Block a user