@asyncio.coroutine
def test_extract_from_service_available_device(hass):
    'Test the extraction of entity from service and device is available.'
    component = EntityComponent(_LOGGER, DOMAIN, hass)
    (yield from component.async_add_entities([MockEntity(name='test_1'), MockEntity(name='test_2', available=False), MockEntity(name='test_3'), MockEntity(name='test_4', available=False)]))
    call_1 = ha.ServiceCall('test', 'service')
    assert (['test_domain.test_1', 'test_domain.test_3'] == sorted((ent.entity_id for ent in (yield from component.async_extract_from_service(call_1)))))
    call_2 = ha.ServiceCall('test', 'service', data={'entity_id': ['test_domain.test_3', 'test_domain.test_4']})
    assert (['test_domain.test_3'] == sorted((ent.entity_id for ent in (yield from component.async_extract_from_service(call_2)))))
Test the extraction of entity from service and device is available.
@asyncio.coroutine
def test_extract_from_service_available_device(hass):
    
    component = EntityComponent(_LOGGER, DOMAIN, hass)
    (yield from component.async_add_entities([MockEntity(name='test_1'), MockEntity(name='test_2', available=False), MockEntity(name='test_3'), MockEntity(name='test_4', available=False)]))
    call_1 = ha.ServiceCall('test', 'service')
    assert (['test_domain.test_1', 'test_domain.test_3'] == sorted((ent.entity_id for ent in (yield from component.async_extract_from_service(call_1)))))
    call_2 = ha.ServiceCall('test', 'service', data={'entity_id': ['test_domain.test_3', 'test_domain.test_4']})
    assert (['test_domain.test_3'] == sorted((ent.entity_id for ent in (yield from component.async_extract_from_service(call_2)))))