async def async_setup(hass, yaml_config):
    'Activate the emulated_hue component.'
    config = Config(hass, yaml_config.get(DOMAIN, {}))
    app = web.Application()
    app['hass'] = hass
    real_ip.setup_real_ip(app, False, [])
    app._on_startup.freeze()
    (await app.startup())
    runner = None
    site = None
    DescriptionXmlView(config).register(app, app.router)
    HueUsernameView().register(app, app.router)
    HueAllLightsStateView(config).register(app, app.router)
    HueOneLightStateView(config).register(app, app.router)
    HueOneLightChangeView(config).register(app, app.router)
    HueAllGroupsStateView(config).register(app, app.router)
    HueGroupView(config).register(app, app.router)
    upnp_listener = UPNPResponderThread(config.host_ip_addr, config.listen_port, config.upnp_bind_multicast, config.advertise_ip, config.advertise_port)

    async def stop_emulated_hue_bridge(event):
        'Stop the emulated hue bridge.'
        upnp_listener.stop()
        if site:
            (await site.stop())
        if runner:
            (await runner.cleanup())

    async def start_emulated_hue_bridge(event):
        'Start the emulated hue bridge.'
        upnp_listener.start()
        nonlocal site
        nonlocal runner
        runner = web.AppRunner(app)
        (await runner.setup())
        site = web.TCPSite(runner, config.host_ip_addr, config.listen_port)
        try:
            (await site.start())
        except OSError as error:
            _LOGGER.error('Failed to create HTTP server at port %d: %s', config.listen_port, error)
        else:
            hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_emulated_hue_bridge)
    hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, start_emulated_hue_bridge)
    return True
Activate the emulated_hue component.
async def async_setup(hass, yaml_config):
    
    config = Config(hass, yaml_config.get(DOMAIN, {}))
    app = web.Application()
    app['hass'] = hass
    real_ip.setup_real_ip(app, False, [])
    app._on_startup.freeze()
    (await app.startup())
    runner = None
    site = None
    DescriptionXmlView(config).register(app, app.router)
    HueUsernameView().register(app, app.router)
    HueAllLightsStateView(config).register(app, app.router)
    HueOneLightStateView(config).register(app, app.router)
    HueOneLightChangeView(config).register(app, app.router)
    HueAllGroupsStateView(config).register(app, app.router)
    HueGroupView(config).register(app, app.router)
    upnp_listener = UPNPResponderThread(config.host_ip_addr, config.listen_port, config.upnp_bind_multicast, config.advertise_ip, config.advertise_port)

    async def stop_emulated_hue_bridge(event):
        'Stop the emulated hue bridge.'
        upnp_listener.stop()
        if site:
            (await site.stop())
        if runner:
            (await runner.cleanup())

    async def start_emulated_hue_bridge(event):
        'Start the emulated hue bridge.'
        upnp_listener.start()
        nonlocal site
        nonlocal runner
        runner = web.AppRunner(app)
        (await runner.setup())
        site = web.TCPSite(runner, config.host_ip_addr, config.listen_port)
        try:
            (await site.start())
        except OSError as error:
            _LOGGER.error('Failed to create HTTP server at port %d: %s', config.listen_port, error)
        else:
            hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_emulated_hue_bridge)
    hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, start_emulated_hue_bridge)
    return True