'Get the location from the entity state or attributes.'

def _get_location_from_entity(self, entity_id):

    entity = self._hass.states.get(entity_id)
    if (entity is None):
        _LOGGER.error('Unable    to    find    entity    %s', entity_id)
        self.valid_api_connection = False
        return None
    if location.has_location(entity):
        return self._get_location_from_attributes(entity)
    zone_entity = self._hass.states.get(('zone.%s' % entity.state))
    if location.has_location(zone_entity):
        _LOGGER.debug('%s    is    in    %s,    getting    zone    location', entity_id, zone_entity.entity_id)
        return self._get_location_from_attributes(zone_entity)
    if entity_id.startswith('sensor.'):
        return entity.state
    return None
