'Find closest entity.
Closest to home:
closest(states)
closest(states.device_tracker)
closest(\'group.children\')
closest(states.group.children)
Closest to a point:
closest(23.456, 23.456, \'group.children\')
closest(\'zone.school\', \'group.children\')
closest(states.zone.school, \'group.children\')'

def closest(self, *args):

    if (len(args) == 1):
        latitude = self._hass.config.latitude
        longitude = self._hass.config.longitude
        entities = args[0]
    elif (len(args) == 2):
        point_state = self._resolve_state(args[0])
        if (point_state is None):
            _LOGGER.warning('Closest:Unable    to    find    state    %s', args[0])
            return None
        elif (not loc_helper.has_location(point_state)):
            _LOGGER.warning('Closest:State    does    not    contain    valid    location:    %s', point_state)
            return None
        latitude = point_state.attributes.get(ATTR_LATITUDE)
        longitude = point_state.attributes.get(ATTR_LONGITUDE)
        entities = args[1]
    else:
        latitude = convert(args[0], float)
        longitude = convert(args[1], float)
        if ((latitude is None) or (longitude is None)):
            _LOGGER.warning('Closest:Received    invalid    coordinates:    %s,    %s', args[0], args[1])
            return None
        entities = args[2]
    if isinstance(entities, (AllStates, DomainStates)):
        states = list(entities)
    else:
        if isinstance(entities, State):
            gr_entity_id = entities.entity_id
        else:
            gr_entity_id = str(entities)
        group = get_component('group')
        states = [self._hass.states.get(entity_id) for entity_id in group.expand_entity_ids(self._hass, [gr_entity_id])]
    return loc_helper.closest(latitude, longitude, states)
