Esempio n. 1
0
def test_platform_validator():
    """Test platform validation."""
    # Prepares loading
    get_test_home_assistant()

    schema = vol.Schema(cv.platform_validator('light'))

    with pytest.raises(vol.MultipleInvalid):
        schema('platform_that_does_not_exist')

    schema('hue')
def test_platform_validator():
    """Test platform validation."""
    # Prepares loading
    get_test_home_assistant()

    schema = vol.Schema(cv.platform_validator('light'))

    with pytest.raises(vol.MultipleInvalid):
        schema('platform_that_does_not_exist')

    schema('hue')
def test_platform_validator():
    """Test platform validation."""
    hass = None

    try:
        hass = get_test_home_assistant()

        schema = vol.Schema(cv.platform_validator('light'))

        with pytest.raises(vol.MultipleInvalid):
            schema('platform_that_does_not_exist')

        schema('hue')
    finally:
        if hass is not None:
            hass.stop()
def test_platform_validator():
    """Test platform validation."""
    hass = None

    try:
        hass = get_test_home_assistant()

        schema = vol.Schema(cv.platform_validator('light'))

        with pytest.raises(vol.MultipleInvalid):
            schema('platform_that_does_not_exist')

        schema('hue')
    finally:
        if hass is not None:
            hass.stop()
Esempio n. 5
0

def _platform_validator(config):
    """Validate it is a valid  platform."""
    platform = get_platform(DOMAIN, config[CONF_PLATFORM])

    if not hasattr(platform, 'TRIGGER_SCHEMA'):
        return config

    return getattr(platform, 'TRIGGER_SCHEMA')(config)


_TRIGGER_SCHEMA = vol.All(cv.ensure_list, [
    vol.All(
        vol.Schema(
            {vol.Required(CONF_PLATFORM): cv.platform_validator(DOMAIN)},
            extra=vol.ALLOW_EXTRA), _platform_validator),
])

_CONDITION_SCHEMA = vol.All(cv.ensure_list, [cv.CONDITION_SCHEMA])

PLATFORM_SCHEMA = vol.Schema({
    CONF_ALIAS:
    cv.string,
    vol.Optional(CONF_INITIAL_STATE, default=DEFAULT_INITIAL_STATE):
    cv.boolean,
    vol.Optional(CONF_HIDE_ENTITY, default=DEFAULT_HIDE_ENTITY):
    cv.boolean,
    vol.Required(CONF_TRIGGER):
    _TRIGGER_SCHEMA,
    vol.Optional(CONF_CONDITION):
Esempio n. 6
0
        if not hasattr(platform, method):
            raise vol.Invalid('invalid method platform')

        if not hasattr(platform, schema):
            return config

        return getattr(platform, schema)(config)

    return validator

_TRIGGER_SCHEMA = vol.All(
    cv.ensure_list,
    [
        vol.All(
            vol.Schema({
                vol.Required(CONF_PLATFORM): cv.platform_validator(DOMAIN)
            }, extra=vol.ALLOW_EXTRA),
            _platform_validator(METHOD_TRIGGER, 'TRIGGER_SCHEMA')
        ),
    ]
)

_CONDITION_SCHEMA = vol.Any(
    CONDITION_USE_TRIGGER_VALUES,
    vol.All(
        cv.ensure_list,
        [
            vol.All(
                vol.Schema({
                    CONF_PLATFORM: str,
                    CONF_CONDITION: str,