Get a list of currently linked devices from the hub

def get_linked(self):
        """Get a list of currently linked devices from the hub"""
        linked_devices = {}
        self.logger.info("\nget_linked")

        #todo instead of sleep, create loop to keep checking buffer
        self.direct_command_hub('0269')
        sleep(1)
        self.get_buffer_status()
        msgs = self.buffer_status.get('msgs', [])
        for entry in msgs:
            im_code = entry.get('im_code', '')
            #self.logger.info("get_linked entry {}".format(pprint.pformat(entry)))

            if im_code == '57':
                device_id = entry.get('id_high', '') + entry.get('id_mid', '') \
                            + entry.get('id_low', '')
                group = entry.get('group', '')
                if device_id not in linked_devices:
                    dev_info = self.id_request(device_id)
                    dev_cat = dev_info.get('id_high', '')
                    dev_sub_cat = dev_info.get('id_mid', '')
                    dev_cat_record = self.get_device_category(dev_cat)
                    if dev_cat_record and 'name' in dev_cat_record:
                        dev_cat_name = dev_cat_record['name']
                        dev_cat_type = dev_cat_record['type']
                    else:
                        dev_cat_name = 'unknown'
                        dev_cat_type = 'unknown'

                    linked_dev_model = self.get_device_model(dev_cat, dev_sub_cat)
                    if 'name' in linked_dev_model:
                        dev_model_name = linked_dev_model['name']
                    else:
                        dev_model_name = 'unknown'

                    if 'sku' in linked_dev_model:
                        dev_sku = linked_dev_model['sku']
                    else:
                        dev_sku = 'unknown'

                    self.logger.info("get_linked: Got first device: %s group %s "
                                     "cat type %s cat name %s dev model name %s",
                                     device_id, group, dev_cat_type,
                                     dev_cat_name, dev_model_name)
                    linked_devices[device_id] = {
                        'cat_name': dev_cat_name,
                        'cat_type': dev_cat_type,
                        'model_name' : dev_model_name,
                        'cat': dev_cat,
                        'sub_cat': dev_sub_cat,
                        'sku': dev_sku,
                        'group': []
                    }

                linked_devices[device_id]['group'].append(group)

        while self.buffer_status['success']:
            self.direct_command_hub('026A')
            sleep(1)
            self.get_buffer_status()
            msgs = self.buffer_status.get('msgs', [])
            for entry in msgs:
                im_code = entry.get('im_code', '')
                if im_code == '57':
                    device_id = entry.get('id_high', '') + entry.get('id_mid', '') \
                                + entry.get('id_low', '')
                    group = entry.get('group', '')

                    if device_id not in linked_devices:
                        dev_info = self.id_request(device_id)
                        dev_cat = dev_info.get('id_high', '')
                        dev_sub_cat = dev_info.get('id_mid', '')
                        dev_cat_record = self.get_device_category(dev_cat)
                        if dev_cat_record and 'name' in dev_cat_record:
                            dev_cat_name = dev_cat_record['name']
                            dev_cat_type = dev_cat_record['type']
                        else:
                            dev_cat_name = 'unknown'
                            dev_cat_type = 'unknown'

                        linked_dev_model = self.get_device_model(dev_cat, dev_sub_cat)
                        if 'name' in linked_dev_model:
                            dev_model_name = linked_dev_model['name']
                        else:
                            dev_model_name = 'unknown'

                        if 'sku' in linked_dev_model:
                            dev_sku = linked_dev_model['sku']
                        else:
                            dev_sku = 'unknown'

                        self.logger.info("get_linked: Got device: %s group %s "
                                         + "cat type %s cat name %s dev model name %s",
                                         device_id, group, dev_cat_type,
                                         dev_cat_name, dev_model_name)
                        linked_devices[device_id] = {
                            'cat_name': dev_cat_name,
                            'cat_type': dev_cat_type,
                            'model_name' : dev_model_name,
                            'cat': dev_cat,
                            'sub_cat': dev_sub_cat,
                            'sku': dev_sku,
                            'group': []
                        }

                    linked_devices[device_id]['group'].append(group)

        self.logger.info("get_linked: Final device list: %s", pprint.pformat(linked_devices))
        return linked_devices