Ejemplo n.º 1
0
async def test_lights_all_dimmable(hass, aiohttp_client):
    """Test CONF_LIGHTS_ALL_DIMMABLE."""
    # create a lamp without brightness support
    hass.states.async_set("light.no_brightness", "on", {})
    await setup.async_setup_component(
        hass, http.DOMAIN, {http.DOMAIN: {http.CONF_SERVER_PORT: HTTP_SERVER_PORT}}
    )
    await hass.async_block_till_done()
    hue_config = {
        emulated_hue.CONF_LISTEN_PORT: BRIDGE_SERVER_PORT,
        emulated_hue.CONF_EXPOSE_BY_DEFAULT: True,
        emulated_hue.CONF_LIGHTS_ALL_DIMMABLE: True,
    }
    with patch("homeassistant.components.emulated_hue.create_upnp_datagram_endpoint"):
        await setup.async_setup_component(
            hass,
            emulated_hue.DOMAIN,
            {emulated_hue.DOMAIN: hue_config},
        )
        await hass.async_block_till_done()
    config = Config(None, hue_config)
    config.numbers = ENTITY_IDS_BY_NUMBER
    web_app = hass.http.app
    HueOneLightStateView(config).register(web_app, web_app.router)
    client = await aiohttp_client(web_app)
    light_without_brightness_json = await perform_get_light_state(
        client, "light.no_brightness", HTTP_OK
    )
    assert light_without_brightness_json["state"][HUE_API_STATE_ON] is True
    assert light_without_brightness_json["type"] == "Dimmable light"
    assert (
        light_without_brightness_json["state"][HUE_API_STATE_BRI]
        == HUE_API_STATE_BRI_MAX
    )
Ejemplo n.º 2
0
def hue_client(loop, hass_hue, aiohttp_client):
    """Create web client for emulated hue api."""
    web_app = hass_hue.http.app
    config = Config(
        None,
        {
            emulated_hue.CONF_ENTITIES: {
                "light.bed_light": {
                    emulated_hue.CONF_ENTITY_HIDDEN: True
                },
                # Kitchen light is explicitly excluded from being exposed
                "light.kitchen_lights": {
                    emulated_hue.CONF_ENTITY_HIDDEN: True
                },
                # Ceiling Fan is explicitly excluded from being exposed
                "fan.ceiling_fan": {
                    emulated_hue.CONF_ENTITY_HIDDEN: True
                },
                # Expose the script
                "script.set_kitchen_light": {
                    emulated_hue.CONF_ENTITY_HIDDEN: False
                },
                # Expose cover
                "cover.living_room_window": {
                    emulated_hue.CONF_ENTITY_HIDDEN: False
                },
                # Expose Hvac
                "climate.hvac": {
                    emulated_hue.CONF_ENTITY_HIDDEN: False
                },
                # Expose HeatPump
                "climate.heatpump": {
                    emulated_hue.CONF_ENTITY_HIDDEN: False
                },
                # No expose setting (use default of not exposed)
                "climate.nosetting": {},
            },
        },
    )
    config.numbers = ENTITY_IDS_BY_NUMBER

    HueUsernameView().register(web_app, web_app.router)
    HueAllLightsStateView(config).register(web_app, web_app.router)
    HueOneLightStateView(config).register(web_app, web_app.router)
    HueOneLightChangeView(config).register(web_app, web_app.router)
    HueAllGroupsStateView(config).register(web_app, web_app.router)
    HueFullStateView(config).register(web_app, web_app.router)
    HueConfigView(config).register(web_app, web_app.router)

    return loop.run_until_complete(aiohttp_client(web_app))