Ejemplo n.º 1
0
async def test_get_supported_features_prioritize_state(opp):
    """Test get_supported_features gives priority to state."""
    entity_reg = mock_registry(opp)
    entity_id = entity_reg.async_get_or_create(
        "hello", "world", "5678", supported_features=456).entity_id
    assert entity.get_supported_features(opp, entity_id) == 456

    opp.states.async_set(entity_id, None, {"supported_features": 123})

    assert entity.get_supported_features(opp, entity_id) == 123
Ejemplo n.º 2
0
async def async_get_action_capabilities(opp: OpenPeerPower,
                                        config: dict) -> dict:
    """List action capabilities."""
    if config[CONF_TYPE] != toggle_entity.CONF_TURN_ON:
        return {}

    try:
        supported_color_modes = get_supported_color_modes(
            opp, config[ATTR_ENTITY_ID])
    except OpenPeerPowerError:
        supported_color_modes = None

    try:
        supported_features = get_supported_features(opp,
                                                    config[ATTR_ENTITY_ID])
    except OpenPeerPowerError:
        supported_features = 0

    extra_fields = {}

    if brightness_supported(supported_color_modes):
        extra_fields[vol.Optional(ATTR_BRIGHTNESS_PCT)] = VALID_BRIGHTNESS_PCT

    if supported_features & SUPPORT_FLASH:
        extra_fields[vol.Optional(ATTR_FLASH)] = VALID_FLASH

    return {"extra_fields": vol.Schema(extra_fields)} if extra_fields else {}
Ejemplo n.º 3
0
async def async_get_actions(opp: OpenPeerPower, device_id: str) -> list[dict]:
    """List device actions."""
    actions = await toggle_entity.async_get_actions(opp, device_id, DOMAIN)

    entity_registry = er.async_get(opp)

    for entry in er.async_entries_for_device(entity_registry, device_id):
        if entry.domain != DOMAIN:
            continue

        supported_color_modes = get_supported_color_modes(opp, entry.entity_id)
        supported_features = get_supported_features(opp, entry.entity_id)

        if brightness_supported(supported_color_modes):
            actions.extend((
                {
                    CONF_TYPE: TYPE_BRIGHTNESS_INCREASE,
                    "device_id": device_id,
                    "entity_id": entry.entity_id,
                    "domain": DOMAIN,
                },
                {
                    CONF_TYPE: TYPE_BRIGHTNESS_DECREASE,
                    "device_id": device_id,
                    "entity_id": entry.entity_id,
                    "domain": DOMAIN,
                },
            ))

        if supported_features & SUPPORT_FLASH:
            actions.extend(({
                CONF_TYPE: TYPE_FLASH,
                "device_id": device_id,
                "entity_id": entry.entity_id,
                "domain": DOMAIN,
            }, ))

    return actions
Ejemplo n.º 4
0
async def test_get_supported_features_raises_on_unknown(opp):
    """Test get_supported_features raises on unknown entity_id."""
    with pytest.raises(OpenPeerPowerError):
        entity.get_supported_features(opp, "hello.world")
Ejemplo n.º 5
0
async def test_get_supported_features_entity_registry(opp):
    """Test get_supported_features falls back to entity registry."""
    entity_reg = mock_registry(opp)
    entity_id = entity_reg.async_get_or_create(
        "hello", "world", "5678", supported_features=456).entity_id
    assert entity.get_supported_features(opp, entity_id) == 456