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' } })
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" }, }, )
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"}, }, )
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
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
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')
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')
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')
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')
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')
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 )
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
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