コード例 #1
0
    def test_validate_platform_config_3(self, caplog):
        """Test fallback to component PLATFORM_SCHEMA."""
        component_schema = PLATFORM_SCHEMA_BASE.extend({
            'hello': str,
        })
        platform_schema = PLATFORM_SCHEMA.extend({
            'cheers': str,
            'hello': 'world',
        })
        mock_integration(
            self.hass,
            MockModule('platform_conf', platform_schema=component_schema))

        mock_entity_platform(
            self.hass, 'platform_conf.whatever',
            MockPlatform('whatever', platform_schema=platform_schema))

        with assert_setup_component(1):
            assert setup.setup_component(
                self.hass,
                'platform_conf',
                {
                    # pass
                    'platform_conf': {
                        'platform': 'whatever',
                        'hello': 'world',
                    },
                    # fail: key hello violates component platform_schema
                    'platform_conf 2': {
                        'platform': 'whatever',
                        'hello': 'there'
                    }
                })
コード例 #2
0
ファイル: test_setup.py プロジェクト: rikroe/core
async def test_validate_platform_config_3(hass, caplog):
    """Test fallback to component PLATFORM_SCHEMA."""
    component_schema = PLATFORM_SCHEMA_BASE.extend({"hello": str})
    platform_schema = PLATFORM_SCHEMA.extend({"cheers": str, "hello": "world"})
    mock_integration(
        hass, MockModule("platform_conf", platform_schema=component_schema))

    mock_entity_platform(
        hass,
        "platform_conf.whatever",
        MockPlatform("whatever", platform_schema=platform_schema),
    )

    with assert_setup_component(1):
        assert await setup.async_setup_component(
            hass,
            "platform_conf",
            {
                # pass
                "platform_conf": {
                    "platform": "whatever",
                    "hello": "world"
                },
                # fail: key hello violates component platform_schema
                "platform_conf 2": {
                    "platform": "whatever",
                    "hello": "there"
                },
            },
        )
コード例 #3
0
    def test_validate_platform_config_2(self, caplog):
        """Test component PLATFORM_SCHEMA_BASE prio over PLATFORM_SCHEMA."""
        platform_schema = PLATFORM_SCHEMA.extend({"hello": str})
        platform_schema_base = PLATFORM_SCHEMA_BASE.extend({"hello": "world"})
        mock_integration(
            self.hass,
            MockModule(
                "platform_conf",
                platform_schema=platform_schema,
                platform_schema_base=platform_schema_base,
            ),
        )

        mock_entity_platform(
            self.hass,
            "platform_conf.whatever",
            MockPlatform("whatever", platform_schema=platform_schema),
        )

        with assert_setup_component(1):
            assert setup.setup_component(
                self.hass,
                "platform_conf",
                {
                    # pass
                    "platform_conf": {"platform": "whatever", "hello": "world"},
                    # fail: key hello violates component platform_schema_base
                    "platform_conf 2": {"platform": "whatever", "hello": "there"},
                },
            )
コード例 #4
0
    def test_validate_platform_config(self, caplog):
        """Test validating platform configuration."""
        platform_schema = PLATFORM_SCHEMA.extend({
            'hello': str,
        })
        platform_schema_base = PLATFORM_SCHEMA_BASE.extend({})
        mock_integration(
            self.hass,
            MockModule('platform_conf',
                       platform_schema_base=platform_schema_base),
        )
        mock_entity_platform(self.hass, 'platform_conf.whatever',
                             MockPlatform(platform_schema=platform_schema))

        with assert_setup_component(0):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': {
                    'platform': 'not_existing',
                    'hello': 'world',
                }
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(1):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': {
                    'platform': 'whatever',
                    'hello': 'world',
                }
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(1):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': [{
                    'platform': 'whatever',
                    'hello': 'world',
                }]
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        # Any falsey platform config will be ignored (None, {}, etc)
        with assert_setup_component(0) as config:
            assert setup.setup_component(self.hass, 'platform_conf',
                                         {'platform_conf': None})
            assert 'platform_conf' in self.hass.config.components
            assert not config['platform_conf']  # empty

            assert setup.setup_component(self.hass, 'platform_conf',
                                         {'platform_conf': {}})
            assert 'platform_conf' in self.hass.config.components
            assert not config['platform_conf']  # empty
コード例 #5
0
    def test_validate_platform_config(self, caplog):
        """Test validating platform configuration."""
        platform_schema = PLATFORM_SCHEMA.extend({"hello": str})
        platform_schema_base = PLATFORM_SCHEMA_BASE.extend({})
        mock_integration(
            self.hass,
            MockModule("platform_conf", platform_schema_base=platform_schema_base),
        )
        mock_entity_platform(
            self.hass,
            "platform_conf.whatever",
            MockPlatform(platform_schema=platform_schema),
        )

        with assert_setup_component(0):
            assert setup.setup_component(
                self.hass,
                "platform_conf",
                {"platform_conf": {"platform": "not_existing", "hello": "world"}},
            )

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove("platform_conf")

        with assert_setup_component(1):
            assert setup.setup_component(
                self.hass,
                "platform_conf",
                {"platform_conf": {"platform": "whatever", "hello": "world"}},
            )

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove("platform_conf")

        with assert_setup_component(1):
            assert setup.setup_component(
                self.hass,
                "platform_conf",
                {"platform_conf": [{"platform": "whatever", "hello": "world"}]},
            )

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove("platform_conf")

        # Any falsey platform config will be ignored (None, {}, etc)
        with assert_setup_component(0) as config:
            assert setup.setup_component(
                self.hass, "platform_conf", {"platform_conf": None}
            )
            assert "platform_conf" in self.hass.config.components
            assert not config["platform_conf"]  # empty

            assert setup.setup_component(
                self.hass, "platform_conf", {"platform_conf": {}}
            )
            assert "platform_conf" in self.hass.config.components
            assert not config["platform_conf"]  # empty
コード例 #6
0
    def test_validate_platform_config_2(self, caplog):
        """Test component PLATFORM_SCHEMA_BASE prio over PLATFORM_SCHEMA."""
        platform_schema = PLATFORM_SCHEMA.extend({
            'hello': str,
        })
        platform_schema_base = PLATFORM_SCHEMA_BASE.extend({
            'hello': 'world',
        })
        loader.set_component(
            self.hass, 'platform_conf',
            MockModule('platform_conf',
                       platform_schema=platform_schema,
                       platform_schema_base=platform_schema_base))

        loader.set_component(
            self.hass, 'platform_conf.whatever',
            MockPlatform('whatever', platform_schema=platform_schema))

        with assert_setup_component(1):
            assert setup.setup_component(
                self.hass,
                'platform_conf',
                {
                    # fail: no extra keys allowed in platform schema
                    'platform_conf': {
                        'platform': 'whatever',
                        'hello': 'world',
                        'invalid': 'extra',
                    }
                })
            assert caplog.text.count('Your configuration contains '
                                     'extra keys') == 1

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(1):
            assert setup.setup_component(
                self.hass,
                'platform_conf',
                {
                    # pass
                    'platform_conf': {
                        'platform': 'whatever',
                        'hello': 'world',
                    },
                    # fail: key hello violates component platform_schema_base
                    'platform_conf 2': {
                        'platform': 'whatever',
                        'hello': 'there'
                    }
                })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')
コード例 #7
0
ファイル: test_setup.py プロジェクト: arsaboo/home-assistant
    def test_validate_platform_config_2(self, caplog):
        """Test component PLATFORM_SCHEMA_BASE prio over PLATFORM_SCHEMA."""
        platform_schema = PLATFORM_SCHEMA.extend({
            'hello': str,
        })
        platform_schema_base = PLATFORM_SCHEMA_BASE.extend({
            'hello': 'world',
        })
        loader.set_component(
            self.hass,
            'platform_conf',
            MockModule('platform_conf',
                       platform_schema=platform_schema,
                       platform_schema_base=platform_schema_base))

        loader.set_component(
            self.hass,
            'platform_conf.whatever',
            MockPlatform('whatever',
                         platform_schema=platform_schema))

        with assert_setup_component(1):
            assert setup.setup_component(self.hass, 'platform_conf', {
                # fail: no extra keys allowed in platform schema
                'platform_conf': {
                    'platform': 'whatever',
                    'hello': 'world',
                    'invalid': 'extra',
                }
            })
            assert caplog.text.count('Your configuration contains '
                                     'extra keys') == 1

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(1):
            assert setup.setup_component(self.hass, 'platform_conf', {
                # pass
                'platform_conf': {
                    'platform': 'whatever',
                    'hello': 'world',
                },
                # fail: key hello violates component platform_schema_base
                'platform_conf 2': {
                    'platform': 'whatever',
                    'hello': 'there'
                }
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')
コード例 #8
0
    def test_validate_platform_config_3(self):
        """Test fallback to component PLATFORM_SCHEMA."""
        component_schema = PLATFORM_SCHEMA_BASE.extend({
            'hello': str,
        })
        platform_schema = PLATFORM_SCHEMA.extend({
            'cheers': str,
            'hello': 'world',
        })
        loader.set_component(
            self.hass, 'platform_conf',
            MockModule('platform_conf', platform_schema=component_schema))

        loader.set_component(
            self.hass, 'platform_conf.whatever',
            MockPlatform('whatever', platform_schema=platform_schema))

        with assert_setup_component(0):
            assert setup.setup_component(
                self.hass,
                'platform_conf',
                {
                    'platform_conf': {
                        # fail: no extra keys allowed
                        'platform': 'whatever',
                        'hello': 'world',
                        'invalid': 'extra',
                    }
                })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(1):
            assert setup.setup_component(
                self.hass,
                'platform_conf',
                {
                    # pass
                    'platform_conf': {
                        'platform': 'whatever',
                        'hello': 'world',
                    },
                    # fail: key hello violates component platform_schema
                    'platform_conf 2': {
                        'platform': 'whatever',
                        'hello': 'there'
                    }
                })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')
コード例 #9
0
ファイル: test_setup.py プロジェクト: fabiandevia/home
    def test_validate_platform_config_3(self, caplog):
        """Test fallback to component PLATFORM_SCHEMA."""
        component_schema = PLATFORM_SCHEMA_BASE.extend({
            'hello': str,
        })
        platform_schema = PLATFORM_SCHEMA.extend({
            'cheers': str,
            'hello': 'world',
        })
        mock_integration(
            self.hass,
            MockModule('platform_conf',
                       platform_schema=component_schema))

        mock_entity_platform(
            self.hass,
            'platform_conf.whatever',
            MockPlatform('whatever',
                         platform_schema=platform_schema))

        with assert_setup_component(1):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': {
                    'platform': 'whatever',
                    'hello': 'world',
                    'invalid': 'extra',
                }
            })
            assert caplog.text.count('Your configuration contains '
                                     'extra keys') == 1

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(1):
            assert setup.setup_component(self.hass, 'platform_conf', {
                # pass
                'platform_conf': {
                    'platform': 'whatever',
                    'hello': 'world',
                },
                # fail: key hello violates component platform_schema
                'platform_conf 2': {
                    'platform': 'whatever',
                    'hello': 'there'
                }
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')
コード例 #10
0
ファイル: test_setup.py プロジェクト: Martwall/home-assistant
    def test_validate_platform_config_3(self):
        """Test fallback to component PLATFORM_SCHEMA."""
        component_schema = PLATFORM_SCHEMA_BASE.extend({
            'hello': str,
        })
        platform_schema = PLATFORM_SCHEMA.extend({
            'cheers': str,
            'hello': 'world',
        })
        loader.set_component(
            self.hass,
            'platform_conf',
            MockModule('platform_conf',
                       platform_schema=component_schema))

        loader.set_component(
            self.hass,
            'platform_conf.whatever',
            MockPlatform('whatever',
                         platform_schema=platform_schema))

        with assert_setup_component(0):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': {
                    # fail: no extra keys allowed
                    'platform': 'whatever',
                    'hello': 'world',
                    'invalid': 'extra',
                }
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(1):
            assert setup.setup_component(self.hass, 'platform_conf', {
                # pass
                'platform_conf': {
                    'platform': 'whatever',
                    'hello': 'world',
                },
                # fail: key hello violates component platform_schema
                'platform_conf 2': {
                    'platform': 'whatever',
                    'hello': 'there'
                }
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')
コード例 #11
0
from .const import (
    CONF_AUTO_SHUFFLE,
    DOMAIN,
    SERVICE_REFRESH_PLAYLISTS,
    SERVICE_SHUFFLE,
    DEFAULT_NAME,
)

from mopidy_client import Client

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PLATFORM_SCHEMA_BASE.extend(
    {
        vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
        vol.Required(CONF_URL): cv.string,
    }
)

SUPPORT_MOPIDY = (
    SUPPORT_PAUSE
    | SUPPORT_PREVIOUS_TRACK
    | SUPPORT_NEXT_TRACK
    | SUPPORT_PLAY_MEDIA
    | SUPPORT_PLAY
    | SUPPORT_CLEAR_PLAYLIST
    | SUPPORT_SHUFFLE_SET
    | SUPPORT_SEEK
    | SUPPORT_STOP
    | SUPPORT_SELECT_SOURCE
)
コード例 #12
0
ファイル: test_setup.py プロジェクト: Martwall/home-assistant
    def test_validate_platform_config(self):
        """Test validating platform configuration."""
        platform_schema = PLATFORM_SCHEMA.extend({
            'hello': str,
        })
        platform_schema_base = PLATFORM_SCHEMA_BASE.extend({
        })
        loader.set_component(
            self.hass,
            'platform_conf',
            MockModule('platform_conf',
                       platform_schema_base=platform_schema_base))

        loader.set_component(
            self.hass,
            'platform_conf.whatever',
            MockPlatform('whatever',
                         platform_schema=platform_schema))

        with assert_setup_component(0):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': {
                    'platform': 'whatever',
                    'hello': 'world',
                    'invalid': 'extra',
                }
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(1):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': {
                    'platform': 'whatever',
                    'hello': 'world',
                },
                'platform_conf 2': {
                    'platform': 'whatever',
                    'invalid': True
                }
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(0):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': {
                    'platform': 'not_existing',
                    'hello': 'world',
                }
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(1):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': {
                    'platform': 'whatever',
                    'hello': 'world',
                }
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(1):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': [{
                    'platform': 'whatever',
                    'hello': 'world',
                }]
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        # Any falsey platform config will be ignored (None, {}, etc)
        with assert_setup_component(0) as config:
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': None
            })
            assert 'platform_conf' in self.hass.config.components
            assert not config['platform_conf']  # empty

            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': {}
            })
            assert 'platform_conf' in self.hass.config.components
            assert not config['platform_conf']  # empty
コード例 #13
0
    def test_validate_platform_config(self, caplog):
        """Test validating platform configuration."""
        platform_schema = PLATFORM_SCHEMA.extend({
            'hello': str,
        })
        platform_schema_base = PLATFORM_SCHEMA_BASE.extend({})
        loader.set_component(
            self.hass, 'platform_conf',
            MockModule('platform_conf',
                       platform_schema_base=platform_schema_base))

        loader.set_component(
            self.hass, 'platform_conf.whatever',
            MockPlatform('whatever', platform_schema=platform_schema))

        with assert_setup_component(1):
            assert setup.setup_component(
                self.hass, 'platform_conf', {
                    'platform_conf': {
                        'platform': 'whatever',
                        'hello': 'world',
                        'invalid': 'extra',
                    }
                })
            assert caplog.text.count('Your configuration contains '
                                     'extra keys') == 1

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(2):
            assert setup.setup_component(
                self.hass, 'platform_conf', {
                    'platform_conf': {
                        'platform': 'whatever',
                        'hello': 'world',
                    },
                    'platform_conf 2': {
                        'platform': 'whatever',
                        'invalid': True
                    }
                })
            assert caplog.text.count('Your configuration contains '
                                     'extra keys') == 2

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(0):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': {
                    'platform': 'not_existing',
                    'hello': 'world',
                }
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(1):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': {
                    'platform': 'whatever',
                    'hello': 'world',
                }
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        with assert_setup_component(1):
            assert setup.setup_component(self.hass, 'platform_conf', {
                'platform_conf': [{
                    'platform': 'whatever',
                    'hello': 'world',
                }]
            })

        self.hass.data.pop(setup.DATA_SETUP)
        self.hass.config.components.remove('platform_conf')

        # Any falsey platform config will be ignored (None, {}, etc)
        with assert_setup_component(0) as config:
            assert setup.setup_component(self.hass, 'platform_conf',
                                         {'platform_conf': None})
            assert 'platform_conf' in self.hass.config.components
            assert not config['platform_conf']  # empty

            assert setup.setup_component(self.hass, 'platform_conf',
                                         {'platform_conf': {}})
            assert 'platform_conf' in self.hass.config.components
            assert not config['platform_conf']  # empty