def devices(self):
        """Create a dictionary of devices known to the user account."""
        params = {'access_token': self.access_token}
        r = self.spark_api.GET(params=params, timeout=self.timeout)
        self._check_error(r)
        json_list = r.json()

        devices_dict = {}
        if json_list:
            # it is possible the keys in json responses varies from one device to another: compute the set of all keys
            allKeys = {'functions', 'variables', 'api', 'requires_deep_update', 'status'} # added by device_info
            for device_json in json_list:
                allKeys.update(device_json.keys())

            Device = _BaseDevice.make_device_class(self, allKeys, timeout = self.timeout)
                    
            for d in json_list:
                if d["connected"]:
                    info = self._get_device_info(d['id'])
                    d['functions'] = info.get('functions')
                    d['variables'] = info.get('variables')
                    d['api'] = self.spark_api(d['id'])
                    d['requires_deep_update'] = d.get('requires_deep_update', False)
                    d['status'] = info.get('status')
                # ensure the set of all keys is present in the dictionnary (Device constructor requires all keys present)
                [d.setdefault(key, None) for key in allKeys]

                devices_dict[d['name']] = Device(**d)
                
        return devices_dict
def devices ( self ) : params = { 'access_token' : self . access_token } r = self . spark_api . GET ( params = params , timeout = self . timeout ) self . _check_error ( r ) json_list = r . json ( ) devices_dict = { } if json_list : allKeys = { 'functions' , 'variables' , 'api' , 'requires_deep_update' , 'status' } for device_json in json_list : allKeys . update ( device_json . keys ( ) ) Device = _BaseDevice . make_device_class ( self , allKeys , timeout = self . timeout ) for d in json_list : if d [ "connected" ] : info = self . _get_device_info ( d [ 'id' ] ) d [ 'functions' ] = info . get ( 'functions' ) d [ 'variables' ] = info . get ( 'variables' ) d [ 'api' ] = self . spark_api ( d [ 'id' ] ) d [ 'requires_deep_update' ] = d . get ( 'requires_deep_update' , False ) d [ 'status' ] = info . get ( 'status' ) [ d . setdefault ( key , None ) for key in allKeys ] devices_dict [ d [ 'name' ] ] = Device ( ** d ) return devices_dict
Create a dictionary of devices known to the user account.