diff --git a/custom_components/localtuya/__init__.py b/custom_components/localtuya/__init__.py index 67f36f9..b642078 100644 --- a/custom_components/localtuya/__init__.py +++ b/custom_components/localtuya/__init__.py @@ -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 diff --git a/custom_components/localtuya/cover.py b/custom_components/localtuya/cover.py index 940f119..0138432 100644 --- a/custom_components/localtuya/cover.py +++ b/custom_components/localtuya/cover.py @@ -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: diff --git a/custom_components/localtuya/fan.py b/custom_components/localtuya/fan.py index 82dde59..906a158 100644 --- a/custom_components/localtuya/fan.py +++ b/custom_components/localtuya/fan.py @@ -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): diff --git a/custom_components/localtuya/light.py b/custom_components/localtuya/light.py index dd024d6..765261c 100644 --- a/custom_components/localtuya/light.py +++ b/custom_components/localtuya/light.py @@ -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: diff --git a/custom_components/localtuya/switch.py b/custom_components/localtuya/switch.py index dc683fa..6e14eab 100644 --- a/custom_components/localtuya/switch.py +++ b/custom_components/localtuya/switch.py @@ -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: