def test_platform_setup(self):
        """Test platform setup."""
        config = {"name": "test", "platform": "universal"}
        bad_config = {"platform": "universal"}
        entities = []

        def add_entities(new_entities):
            """Add devices to list."""
            for dev in new_entities:
                entities.append(dev)

        setup_ok = True
        try:
            asyncio.run_coroutine_threadsafe(
                universal.async_setup_platform(self.hass,
                                               validate_config(bad_config),
                                               add_entities),
                self.hass.loop,
            ).result()
        except MultipleInvalid:
            setup_ok = False
        assert not setup_ok
        assert 0 == len(entities)

        asyncio.run_coroutine_threadsafe(
            universal.async_setup_platform(self.hass, validate_config(config),
                                           add_entities),
            self.hass.loop,
        ).result()
        assert 1 == len(entities)
        assert "test" == entities[0].name
Ejemplo n.º 2
0
    def test_platform_setup(self):
        """Test platform setup."""
        config = {'name': 'test', 'platform': 'universal'}
        bad_config = {'platform': 'universal'}
        entities = []

        def add_entities(new_entities):
            """Add devices to list."""
            for dev in new_entities:
                entities.append(dev)

        setup_ok = True
        try:
            run_coroutine_threadsafe(
                universal.async_setup_platform(
                    self.hass, validate_config(bad_config), add_entities),
                self.hass.loop).result()
        except MultipleInvalid:
            setup_ok = False
        assert not setup_ok
        assert 0 == len(entities)

        run_coroutine_threadsafe(
            universal.async_setup_platform(
                self.hass, validate_config(config), add_entities),
            self.hass.loop).result()
        assert 1 == len(entities)
        assert 'test' == entities[0].name