Beispiel #1
0
def get_all_diagnostics(org_id):
    '''
    Returns the obd data for all assets.

    Note that this function can take a long time to execute, due
    to the fact that each asset requires its own call and response
    from the MAP server. This code is not used in these applications.

    '''
    asset_response = fms_client.search_asset()
    asset_dev_serials = {asset.deviceSerial: asset.assetId
                         for asset in asset_response.assetVOs}

    device_response = device_client.get_devices(org_id)

    # This is slightly backward, but it makes sure that only devices
    # currently connected to assets become part of the response
    asset_dev_ids = {asset_dev_serials[device.serial]: device.deviceId
                     for device in device_response.deviceVOs
                     if device.serial in asset_dev_serials}

    diagnostics = [
        {'asset': asset,
         'obd': fms_client.get_diagnostic_data(
             device_id=asset_dev_ids[asset]).diagnosticDataVOs}
        for asset in asset_dev_ids]

    return diagnostics
Beispiel #2
0
def get_unused_device_serials(org_id):

    '''
    The aim of this function is to find the serials of all currently
    unused devices.

    To do this, we first retrieve a list of all devices and place
    their serials into a set.

    We then retrieve the list of all assets, extract their associated
    devices' serial numbers and place them into a second set.

    We then obtain the desired result by subtrating the second set from
    the first.

    '''

    devices = device_client.get_devices(org_id)
    assets = fms_client.search_asset()

    all_serials = set()
    taken_serials = set()

    for asset in assets.assetVOs:
        taken_serials.add(asset.deviceSerial)

    for device in devices.deviceVOs:
        all_serials.add(device.serial)

    untaken_serials = all_serials - taken_serials

    return sorted(list(untaken_serials))