def test_extract_from_service_filter_out_non_existing_entities(self):
        """Test the extraction of non existing entities from service."""
        component = EntityComponent(_LOGGER, DOMAIN, self.hass)
        component.add_entities([EntityTest(name="test_1"), EntityTest(name="test_2")])

        call = ha.ServiceCall("test", "service", {"entity_id": ["test_domain.test_2", "test_domain.non_exist"]})

        assert ["test_domain.test_2"] == [ent.entity_id for ent in component.extract_from_service(call)]
    def test_extract_from_service_returns_all_if_no_entity_id(self):
        """Test the extraction of everything from service."""
        component = EntityComponent(_LOGGER, DOMAIN, self.hass)
        component.add_entities([EntityTest(name="test_1"), EntityTest(name="test_2")])

        call = ha.ServiceCall("test", "service")

        assert ["test_domain.test_1", "test_domain.test_2"] == sorted(
            ent.entity_id for ent in component.extract_from_service(call)
        )
    def test_extract_from_service_no_group_expand(self):
        """Test not expanding a group."""
        component = EntityComponent(_LOGGER, DOMAIN, self.hass)
        test_group = group.Group.create_group(
            self.hass, 'test_group', ['light.Ceiling', 'light.Kitchen'])
        component.add_entities([test_group])

        call = ha.ServiceCall('test', 'service',
                              {'entity_id': ['group.test_group']})

        extracted = component.extract_from_service(call, expand_group=False)
        self.assertEqual([test_group], extracted)
    def test_extract_from_service_returns_all_if_no_entity_id(self):
        component = EntityComponent(_LOGGER, DOMAIN, self.hass)
        component.add_entities([
            EntityTest(name='test_1'),
            EntityTest(name='test_2'),
        ])

        call = ha.ServiceCall('test', 'service')

        assert ['test_domain.test_1', 'test_domain.test_2'] == \
            sorted(ent.entity_id for ent in
                   component.extract_from_service(call))
    def test_extract_from_service_returns_all_if_no_entity_id(self):
        component = EntityComponent(_LOGGER, DOMAIN, self.hass)
        component.add_entities([
            EntityTest(name='test_1'),
            EntityTest(name='test_2'),
        ])

        call = ha.ServiceCall('test', 'service')

        assert ['test_domain.test_1', 'test_domain.test_2'] == \
            sorted(ent.entity_id for ent in
                   component.extract_from_service(call))
    def test_extract_from_service_no_group_expand(self):
        """Test not expanding a group."""
        component = EntityComponent(_LOGGER, DOMAIN, self.hass)
        test_group = group.Group.create_group(
            self.hass, 'test_group', ['light.Ceiling', 'light.Kitchen'])
        component.add_entities([test_group])

        call = ha.ServiceCall('test', 'service', {
            'entity_id': ['group.test_group']
        })

        extracted = component.extract_from_service(call, expand_group=False)
        self.assertEqual([test_group], extracted)
    def test_extract_from_service_filter_out_non_existing_entities(self):
        component = EntityComponent(_LOGGER, DOMAIN, self.hass)
        component.add_entities([
            EntityTest(name='test_1'),
            EntityTest(name='test_2'),
        ])

        call = ha.ServiceCall(
            'test', 'service',
            {'entity_id': ['test_domain.test_2', 'test_domain.non_exist']})

        assert ['test_domain.test_2'] == \
               [ent.entity_id for ent in component.extract_from_service(call)]
    def test_extract_from_service_filter_out_non_existing_entities(self):
        component = EntityComponent(_LOGGER, DOMAIN, self.hass)
        component.add_entities([
            EntityTest(name='test_1'),
            EntityTest(name='test_2'),
        ])

        call = ha.ServiceCall('test', 'service', {
            'entity_id': ['test_domain.test_2', 'test_domain.non_exist']
        })

        assert ['test_domain.test_2'] == \
               [ent.entity_id for ent in component.extract_from_service(call)]