Python homeassistant.helpers.discovery.async_load_platform() Examples

The following are 9 code examples of homeassistant.helpers.discovery.async_load_platform(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module homeassistant.helpers.discovery , or try the search function .
Example #1
Source File: duofern.py    From pyduofern with GNU General Public License v2.0 6 votes vote down vote up
def async_setup(hass, config):
    """Setup the duofern platform."""

    serial_port = config.get('serial_port')
    code = config.get('code')
    configfile = config.get('config_file')

    hass.data['duofern'] = {
        'stick': DuofernStickAsync(serial_port=serial_port, system_code=code, config_file_json=configfile)}
    hass.loop.create_task(hass.data['duofern']['stick'].handshake())

    # wait for handshake done (via future)
    await hass.data['duofern']['stick'].available

    # wait for a bit to allow duofern devices to call in
    await asyncio.sleep(10)

    hass.async_add_job(discovery.async_load_platform(hass, 'cover', DOMAIN, {}, config))
#    hass.async_add_job(discovery.async_load_platform(hass, 'sensor', DOMAIN, {}, config)) 
Example #2
Source File: setup.py    From integration with MIT License 6 votes vote down vote up
def add_sensor():
    """Add sensor."""
    hacs = get_hacs()

    try:
        if hacs.configuration.config_type == "yaml":
            hacs.hass.async_create_task(
                discovery.async_load_platform(
                    hacs.hass, "sensor", DOMAIN, {}, hacs.configuration.config
                )
            )
        else:
            hacs.hass.async_add_job(
                hacs.hass.config_entries.async_forward_entry_setup(
                    hacs.configuration.config_entry, "sensor"
                )
            )
    except ValueError:
        pass 
Example #3
Source File: setup.py    From SmartHouse with MIT License 6 votes vote down vote up
def add_sensor():
    """Add sensor."""
    hacs = get_hacs()

    try:
        if hacs.configuration.config_type == "yaml":
            hacs.hass.async_create_task(
                discovery.async_load_platform(
                    hacs.hass, "sensor", DOMAIN, {}, hacs.configuration.config
                )
            )
        else:
            hacs.hass.async_add_job(
                hacs.hass.config_entries.async_forward_entry_setup(
                    hacs.configuration.config_entry, "sensor"
                )
            )
    except ValueError:
        pass 
Example #4
Source File: __init__.py    From xknx with MIT License 5 votes vote down vote up
def async_setup(hass, config):
    """Set up the KNX component."""
    try:
        hass.data[DATA_XKNX] = KNXModule(hass, config)
        hass.data[DATA_XKNX].async_create_exposures()
        await hass.data[DATA_XKNX].start()
    except XKNXException as ex:
        _LOGGER.warning("Can't connect to KNX interface: %s", ex)
        hass.components.persistent_notification.async_create(
            f"Can't connect to KNX interface: <br><b>{ex}</b>", title="KNX"
        )

    for component, discovery_type in (
        ("switch", "Switch"),
        ("climate", "Climate"),
        ("cover", "Cover"),
        ("light", "Light"),
        ("sensor", "Sensor"),
        ("binary_sensor", "BinarySensor"),
        ("scene", "Scene"),
        ("notify", "Notification"),
    ):
        found_devices = _get_devices(hass, discovery_type)
        hass.async_create_task(
            discovery.async_load_platform(
                hass, component, DOMAIN, {ATTR_DISCOVER_DEVICES: found_devices}, config
            )
        )

    hass.services.async_register(
        DOMAIN,
        SERVICE_XKNX_SEND,
        hass.data[DATA_XKNX].service_send_to_knx_bus,
        schema=SERVICE_XKNX_SEND_SCHEMA,
    )

    return True 
Example #5
Source File: __init__.py    From Anniversaries with MIT License 5 votes vote down vote up
def async_setup(hass, config):
    """Set up this component using YAML."""
    if config.get(DOMAIN) is None:
        # config flow setup
        return True

    # log startup message
    _LOGGER.info(
        CC_STARTUP_VERSION.format(name=DOMAIN, version=VERSION, issue_link=ISSUE_URL)
    )
    platform_config = config[DOMAIN].get(CONF_SENSORS, {})

    # If platform is not enabled, skip.
    if not platform_config:
        return False

    for entry in platform_config:
        hass.async_create_task(
            discovery.async_load_platform(hass, PLATFORM, DOMAIN, entry, config)
        )
    hass.async_create_task(
        hass.config_entries.flow.async_init(
            DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
        )
    )
    return True 
Example #6
Source File: __init__.py    From ha-wyzeapi with Apache License 2.0 4 votes vote down vote up
def async_setup(hass, config):
    """Set up the WyzeApi parent component."""
    _LOGGER.debug("""
-------------------------------------------------------------------
Wyze Bulb and Switch Home Assistant Integration

Version: v0.5.0
This is a custom integration
If you have any issues with this you need to open an issue here:
https://github.com/JoshuaMulliken/ha-wyzeapi/issues
-------------------------------------------------------------------""")
    _LOGGER.debug("""Creating new WyzeApi component""")

    wyzeapi_account = WyzeApi(config[DOMAIN].get(CONF_USERNAME),
                              config[DOMAIN].get(CONF_PASSWORD))
    await wyzeapi_account.async_init()

    sensor_support = config[DOMAIN].get(CONF_SENSORS)
    light_support = config[DOMAIN].get(CONF_LIGHT)
    switch_support = config[DOMAIN].get(CONF_SWITCH)
    lock_support = config[DOMAIN].get(CONF_LOCK)
    if not wyzeapi_account.is_valid_login():
        _LOGGER.error("Not connected to Wyze account. Unable to add devices. Check your configuration.")
        return False

    _LOGGER.debug("Connected to Wyze account")
    wyzeapi_devices = await wyzeapi_account.async_get_devices()

    # Store the logged in account object for the platforms to use.
    hass.data[DOMAIN] = {
        "wyzeapi_account": wyzeapi_account
    }

    # Start up lights and switch components
    if wyzeapi_devices:
        _LOGGER.debug("Starting WyzeApi components")
    if light_support == True:
        await discovery.async_load_platform(hass, "light", DOMAIN, {}, config)
        _LOGGER.debug("Starting WyzeApi Lights")
    if switch_support == True:
        await discovery.async_load_platform(hass, "switch", DOMAIN, {}, config)
        _LOGGER.debug("Starting WyzeApi switchs")
    if sensor_support == True:
        await discovery.async_load_platform(hass, "binary_sensor", DOMAIN, {}, config)
        _LOGGER.debug("Starting WyzeApi Sensors")
    if lock_support == True:
        await discovery.async_load_platform(hass, "lock", DOMAIN, {}, config)
        _LOGGER.debug("Starting WyzeApi lock")

    else:
        _LOGGER.error("WyzeApi authenticated but could not find any devices.")

    return True 
Example #7
Source File: __init__.py    From breaking_changes with MIT License 4 votes vote down vote up
def async_setup(hass, config):
    """Set up this component."""

    # Print startup message
    startup = STARTUP.format(name=DOMAIN, version=VERSION, issueurl=ISSUE_URL)
    _LOGGER.info(startup)

    throttle = Throttle()

    # Check that all required files are present
    file_check = await check_files(hass)
    if not file_check:
        return False

    # Create DATA dict
    hass.data[DOMAIN_DATA] = {}
    hass.data[DOMAIN_DATA]["throttle"] = throttle
    hass.data[DOMAIN_DATA]["components"] = ["homeassistant"]
    hass.data[DOMAIN_DATA]["potential"] = {}

    if config[DOMAIN].get("scan_interval") is not None:
        throttle.interval = timedelta(seconds=config[DOMAIN].get("scan_interval"))

    # Load platforms
    for platform in PLATFORMS:
        # Get platform specific configuration
        platform_config = config[DOMAIN]

        hass.async_create_task(
            discovery.async_load_platform(
                hass, platform, DOMAIN, platform_config, config
            )
        )

    async def loaded_platforms(hass):
        """Load platforms after HA startup."""
        for component in hass.config.components:
            hass.data[DOMAIN_DATA]["components"].append(component)

        _LOGGER.debug("Loaded components %s", hass.data[DOMAIN_DATA]["components"])
        await update_data(hass, throttle)  # pylint: disable=unexpected-keyword-arg

    hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, loaded_platforms(hass))

    return True 
Example #8
Source File: __init__.py    From mbapipy with MIT License 4 votes vote down vote up
def setup(hass, config):
    """Set up MercedesMe System."""

    conf = config[DOMAIN]

    scan_interval = conf.get(CONF_SCAN_INTERVAL)

    cache = hass.config.path(DEFAULT_CACHE_PATH)

    auth_handler = MercedesMeOAuth(
        conf.get(CONF_USERNAME),
        conf.get(CONF_PASSWORD),
        conf.get(CONF_ACCEPT_LANG),
        conf.get(CONF_COUNTRY_CODE),
        cache,
    )

    token_info = auth_handler.get_cached_token()

    if not token_info:
        _LOGGER.debug("no token; requesting authorization")
        token_info = auth_handler.request_initial_token()
    else:
        _LOGGER.debug("cached token found")

    if not token_info:
        _LOGGER.warning("no token; authorization failed; check debug log")
        return False

    mercedesme_api = Controller(
        auth_handler,
        scan_interval,
        conf.get(CONF_ACCEPT_LANG),
        conf.get(CONF_COUNTRY_CODE),
        conf.get(CONF_EXCLUDED_CARS),
        conf.get(CONF_SAVE_CAR_DETAILS),
        conf.get(CONF_PIN),
        hass.config.path(""),
    )

    hass.data[DOMAIN] = MercedesMeHub(mercedesme_api, conf)

    for component in MERCEDESME_COMPONENTS:
        hass.async_create_task(
            discovery.async_load_platform(hass, component, DOMAIN, {}, config)
        )

    def hub_refresh(event_time):
        """Call Mercedes me API to refresh information."""
        _LOGGER.info("Updating Mercedes me component.")
        hass.data[DOMAIN].data.update()
        dispatcher_send(hass, SIGNAL_UPDATE_MERCEDESME)

    track_time_interval(hass, hub_refresh, timedelta(seconds=scan_interval))

    return True 
Example #9
Source File: __init__.py    From lutron-caseta-pro with Apache License 2.0 4 votes vote down vote up
def async_setup_bridge(hass, config, fname, bridge):
    """Initialize a bridge by loading its integration report."""
    _LOGGER.debug("Setting up bridge using Integration Report %s", fname)

    devices = await casetify.async_load_integration_report(fname)

    # Patch up device types from configuration.
    # All other devices will be treated as lights.
    await _patch_device_types(bridge, devices)
    _LOGGER.debug("Patched device list %s", devices)

    # sort devices based on device types
    types = {
        "sensor": [],
        "switch": [],
        "light": [],
        "cover": [],
        "scene": [],
        "fan": [],
    }
    for device in devices:
        types[device["type"]].append(device)

    # load MAC address used for unique IDs
    mac_address = None
    if CONF_MAC in bridge:
        mac_address = bridge[CONF_MAC]

    # Load default transition time, if present.
    transition_time = None
    if CONF_TRANSITION_TIME in bridge:
        transition_time = bridge[CONF_TRANSITION_TIME]

    # load platform by type
    for device_type in types:
        component = device_type
        _LOGGER.debug("Loading platform %s", component)
        hass.async_add_job(
            discovery.async_load_platform(
                hass,
                component,
                DOMAIN,
                {
                    CONF_HOST: bridge[CONF_HOST],
                    CONF_MAC: mac_address,
                    CONF_DEVICES: types[device_type],
                    CONF_TRANSITION_TIME: transition_time,
                },
                config,
            )
        )