Create array of available devices from response.
344683
function addDevices(deviceArr) {
      deviceArr.forEach(function(el, i) {
        self.devices.push({
          name: deviceArr[i]['name'],
          deviceId: deviceArr[i]['id']
        });
      });
    }
418635
function listDevices() {
    return getDevice()
    .then(device => {
        console.log(`Device: ${device.id}`);
        return device.listResources();
    })
    .then(resources => {
        resources.forEach(resource => {
            resource.getValue()
            .then(value => {
                console.log(`\t└\x1b[1m${resource.path}\x1b[0m: ${value}`);
            })
            .catch(error => {
                console.log(`\t└\x1b[1m${resource.path}\x1b[0m: Error: ${error.message}`);
            });
        });
    });
}
1353914
def batch(items, size):
    """"""
    return [items[x:x + size] for x in xrange(0, len(items), size)]
1308000
def _get_setup(self, result):
        """"""
        self.__devices = {}

        if ('setup' not in result.keys() or
                'devices' not in result['setup'].keys()):
            raise Exception(
                "Did not find device definition.")

        for device_data in result['setup']['devices']:
            device = Device(self, device_data)
            self.__devices[device.url] = device

        self.__location = result['setup']['location']
        self.__gateway = result['setup']['gateways']
1150308
def from_array(array):
        
        if array is None or not array:
            return None
        # end if
        assert_type_or_raise(array, dict, parameter_name="array")

        data = {}
        data['location'] = Location.from_array(array.get('location'))
        data['title'] = u(array.get('title'))
        data['address'] = u(array.get('address'))
        data['foursquare_id'] = u(array.get('foursquare_id')) if array.get('foursquare_id') is not None else None
        data['foursquare_type'] = u(array.get('foursquare_type')) if array.get('foursquare_type') is not None else None
        data['_raw'] = array
        return Venue(**data)
655085
def decode_response(content: bytes) -> set:
    
    content = content[4:].decode(config.ENCODING)
    if '\t' not in content and '\n' not in content:
        return set()

    connected_devices = set()
    device_list = [i for i in content.split('\n') if i]
    for each_device in device_list:
        device_id, device_status = each_device.split('\t')
        if device_status == 'device':
            connected_devices.add(device_id)
    return connected_devices
472314
function parseDevicesResult(result: string): Array<string> {
  if (!result) {
    return [];
  }

  const devices = [];
  const lines = result.trim().split(/\r?\n/);

  for (let i = 0; i < lines.length; i++) {
    const words = lines[i].split(/[ ,\t]+/).filter(w => w !== '');

    if (words[1] === 'device') {
      devices.push(words[0]);
    }
  }
  return devices;
}
981190
def ListDevices(self):
    '''
    '''
    devices = []

    for obj in mockobject.objects.keys():
        if obj.startswith('/org/bluez/') and 'dev_' in obj:
            devices.append(dbus.ObjectPath(obj, variant_level=1))

    return dbus.Array(devices, variant_level=1)
601039
def devices
      response = get('/listDevices')
      devices = []
      response.body['devices'].each do |d|
        devices << Device.from_json(d, @token, @logger)
      end
      devices
    end
519368
def use_device(cls, device):
        """"""
        if device == cls.ops.device:
            yield
        else:
            curr_Ops, curr_ops = (cls.Ops, cls.ops)
            cls.Ops = get_ops(device)
            cls.ops = cls.Ops()
            yield
            cls.Ops = curr_Ops
            cls.ops = curr_ops
236199
def _get_states(self, result):
        """"""
        if 'devices' not in result.keys():
            return

        for device_states in result['devices']:
            device = self.__devices[device_states['deviceURL']]
            try:
                device.set_active_states(device_states['states'])
            except KeyError:
                pass
575655
def _get_events(self, result):
        """""""
        events = []

        for event_data in result:
            event = Event.factory(event_data)

            if event is not None:
                events.append(event)

                if isinstance(event, DeviceStateChangedEvent):
                    # change device state
                    if self.__devices[event.device_url] is None:
                        raise Exception(
                            "Received device change " +
                            "state for unknown device '" +
                            event.device_url + "'")

                    self.__devices[event.device_url].set_active_states(
                        event.states)

        return events
927172
def services(device_id=nil, shared=false)
      params = { shared: shared }
      params[:deviceid] = device_id unless device_id.nil?

      response = get('/listServices', params)
      services = []
      response.body['services'].each do |s|
        services << Service.from_json(s, @token, @logger)
      end
      services
    end
998425
def _build_jss_object_list(self, response, obj_class):
        """"""
        response_objects = [item for item in response
                            if item is not None and
                            item.tag != "size"]
        objects = [
            JSSListData(obj_class, {i.tag: i.text for i in response_object},
                        self) for response_object in response_objects]

        return JSSObjectList(self, obj_class, objects)
137729
def get_devices(self, refresh=False, generic_type=None):
        """"""
        _LOGGER.info("Updating all devices...")
        if refresh or self._devices is None:
            if self._devices is None:
                self._devices = {}

            responseObject = self.get_sensors()
            if (responseObject and
                    not isinstance(responseObject, (tuple, list))):
                responseObject = responseObject

            for deviceJson in responseObject:
                # Attempt to reuse an existing device
                device = self._devices.get(deviceJson['name'])

                # No existing device, create a new one
                if device:
                    device.update(deviceJson)
                else:
                    device = newDevice(deviceJson, self)

                    if not device:
                        _LOGGER.info('Device is unknown')
                        continue

                    self._devices[device.device_id] = device

            # We will be treating the Lupusec panel itself as an armable device.
            panelJson = self.get_panel()
            _LOGGER.debug("Get the panel in get_devices: %s", panelJson)

            self._panel.update(panelJson)

            alarmDevice = self._devices.get('0')

            if alarmDevice:
                alarmDevice.update(panelJson)
            else:
                alarmDevice = ALARM.create_alarm(panelJson, self)
                self._devices['0'] = alarmDevice

            # Now we will handle the power switches
            switches = self.get_power_switches()
            _LOGGER.debug(
                'Get active the power switches in get_devices: %s', switches)

            for deviceJson in switches:
                # Attempt to reuse an existing device
                device = self._devices.get(deviceJson['name'])

                # No existing device, create a new one
                if device:
                    device.update(deviceJson)
                else:
                    device = newDevice(deviceJson, self)
                    if not device:
                        _LOGGER.info('Device is unknown')
                        continue
                    self._devices[device.device_id] = device

        if generic_type:
            devices = []
            for device in self._devices.values():
                if (device.type is not None and
                        device.type in generic_type[0]):
                    devices.append(device)
            return devices

        return list(self._devices.values())
387805
def get_devices(self):
        """"""
        utils.pending_message('Fetching device list...')

        get_devices_task = self.client.devices(
            account=self.account
        )

        # We wait for device list info as this sample relies on it next.
        get_devices_task.wait_for_result(timeout=self.timeout)

        get_devices_result = json.loads(get_devices_task.result)
        self.devices = get_devices_result['devices']

        utils.info_message('Get devices successful')
124617
function buildResponse(data) {
    var response = {};
    response.totalItems = data.length;
    response.itemsPerPage = itemsPerPage;
    response.totalPages = itemsPerPage === null ? 1 : Math.ceil(data.length / itemsPerPage);
    response.currentPage = itemsPerPage === null ? 1 : currentPage;
    response.data = itemsPerPage === null ? data : data.slice(itemsPerPage * (currentPage - 1), itemsPerPage);

    return response;
}