Skip to content

Powertrain Asset API Client

Bases: BasePowertrainAPIClient

Powertrain Asset API Client.

Swagger Documentation

Source code in reportconnectors/api_client/powertrain/asset/__init__.py
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
class PowertrainAssetAPIClient(BasePowertrainAPIClient):
    """
    Powertrain Asset API Client.

    [Swagger Documentation](https://motion-pt-dev-we-asset-api.azurewebsites.net/swagger/index.html)
    """

    _status_prefix = "/asset"

    def get_asset_details(self, asset_id: int) -> AssetDetailsResponse:
        """
        Gets the details of the asset with the given asset_id.

        Args:
            asset_id: Asset identifier

        Returns:
            Asset details.
        """
        endpoint = f"api/asset/{asset_id}"
        response = self._make_request(method="GET", endpoint=endpoint)
        response_model = self._decode_response_to_model(response, AssetDetailsResponse)
        return response_model

    def get_assets_details(self, asset_ids: Sequence[int]) -> AssetsDetailsResponse:
        """
        Gets the asset details for provided list of asset ids.

        Args:
            asset_ids: Asset identifiers

        Returns:
            List of asset details.
        """
        endpoint = "api/asset/List/GetDetails"
        data = {"assetIds": list(asset_ids)}
        response = self._make_request(method="POST", endpoint=endpoint, json_data=data)
        response_model = self._decode_response_to_model(response, AssetsDetailsResponse)
        return response_model

    def get_report_assets_details(self, asset_ids: Sequence[int]) -> ReportAssetsDetailsResponse:
        """
        Gets the list of asset details for provided list of asset ids. This endpoint is dedicated for
        the report usage.

        Args:
            asset_ids: Asset identifiers

        Returns:
            List of asset details.
        """
        endpoint = "api/report/asset/Report/Asset/Details"
        data = {"assetIds": list(asset_ids)}
        response = self._make_request(method="POST", endpoint=endpoint, json_data=data)
        response_model = self._decode_response_to_model(response, ReportAssetsDetailsResponse)
        return response_model

    def get_asset_properties(self, asset_id: int) -> AssetPropertiesResponse:
        """
        Gets the properties of the asset with the given asset_id.

        Args:
            asset_id: Asset identifier

        Returns:
            Asset properties.
        """
        endpoint = f"/asset/Assets/{asset_id}/Properties"
        response = self._make_request(method="GET", endpoint=endpoint)
        response_model = self._decode_response_to_model(response, AssetPropertiesResponse)
        return response_model

    def get_asset_pictures(self, asset_id: int) -> AssetPicturesResponse:
        """
        Gets the pictures of the asset with the given asset_id.

        Args:
            asset_id: Asset identifier

        Returns:
            Asset pictures.
        """
        endpoint = f"asset/Assets/{asset_id}/Pictures"
        response = self._make_request(method="GET", endpoint=endpoint)
        response_model = self._decode_response_to_model(response, AssetPicturesResponse)
        return response_model

    def search_for_assets(
        self,
        organization_id: Union[int, List[int], None] = None,
        site_id: Union[int, List[int], None] = None,
        asset_group_id: Union[int, List[int], None] = None,
        **kwargs,
    ) -> AssetSearchResponse:
        """
        Returns a list of asset details that meets the search criteria.

        You can search by organization ids, site ids, and asset group ids.
        At least one search criteria has to be provided.

        Each search criteria can be provided as a single integer or a list of integers.

        You can control number of output results and the result offset with `page_number` and `page_size` arguments.

        Args:
            organization_id: Organization identifier(s)
            site_id: Site identifier(s)
            asset_group_id: Asset group identifier(s)

        Keyword Args:
            page_number (int): Results page number. Default: `0`
            page_size (int): Results page size. Default: `1000`

        Returns:
            List of asset details that meets the search criteria.

        Raises:
            ValueError: If none of the search criteria is provided.

        """
        if organization_id is None and site_id is None and asset_group_id is None:
            raise ValueError("At least one of the search parameters has to be provided.")

        page_number = kwargs.get("page_number", 1)
        page_size = kwargs.get("page_size", 100)

        data = {
            "pageNumber": page_number,
            "pageSize": page_size,
        }
        for key, param in [
            ("organizationIds", organization_id),
            ("siteIds", site_id),
            ("assetGroupIds", asset_group_id),
        ]:
            if param is None:
                data[key] = []
            elif isinstance(param, list):
                data[key] = param
            else:
                data[key] = [param]

        endpoint = "api/asset/Search"
        response = self._make_request(method="POST", endpoint=endpoint, json_data=data)
        response_model = self._decode_response_to_model(response, AssetSearchResponse)
        return response_model

get_asset_details(asset_id)

Gets the details of the asset with the given asset_id.

Parameters:

Name Type Description Default
asset_id int

Asset identifier

required

Returns:

Type Description
AssetDetailsResponse

Asset details.

Source code in reportconnectors/api_client/powertrain/asset/__init__.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def get_asset_details(self, asset_id: int) -> AssetDetailsResponse:
    """
    Gets the details of the asset with the given asset_id.

    Args:
        asset_id: Asset identifier

    Returns:
        Asset details.
    """
    endpoint = f"api/asset/{asset_id}"
    response = self._make_request(method="GET", endpoint=endpoint)
    response_model = self._decode_response_to_model(response, AssetDetailsResponse)
    return response_model

get_asset_pictures(asset_id)

Gets the pictures of the asset with the given asset_id.

Parameters:

Name Type Description Default
asset_id int

Asset identifier

required

Returns:

Type Description
AssetPicturesResponse

Asset pictures.

Source code in reportconnectors/api_client/powertrain/asset/__init__.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def get_asset_pictures(self, asset_id: int) -> AssetPicturesResponse:
    """
    Gets the pictures of the asset with the given asset_id.

    Args:
        asset_id: Asset identifier

    Returns:
        Asset pictures.
    """
    endpoint = f"asset/Assets/{asset_id}/Pictures"
    response = self._make_request(method="GET", endpoint=endpoint)
    response_model = self._decode_response_to_model(response, AssetPicturesResponse)
    return response_model

get_asset_properties(asset_id)

Gets the properties of the asset with the given asset_id.

Parameters:

Name Type Description Default
asset_id int

Asset identifier

required

Returns:

Type Description
AssetPropertiesResponse

Asset properties.

Source code in reportconnectors/api_client/powertrain/asset/__init__.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def get_asset_properties(self, asset_id: int) -> AssetPropertiesResponse:
    """
    Gets the properties of the asset with the given asset_id.

    Args:
        asset_id: Asset identifier

    Returns:
        Asset properties.
    """
    endpoint = f"/asset/Assets/{asset_id}/Properties"
    response = self._make_request(method="GET", endpoint=endpoint)
    response_model = self._decode_response_to_model(response, AssetPropertiesResponse)
    return response_model

get_assets_details(asset_ids)

Gets the asset details for provided list of asset ids.

Parameters:

Name Type Description Default
asset_ids Sequence[int]

Asset identifiers

required

Returns:

Type Description
AssetsDetailsResponse

List of asset details.

Source code in reportconnectors/api_client/powertrain/asset/__init__.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def get_assets_details(self, asset_ids: Sequence[int]) -> AssetsDetailsResponse:
    """
    Gets the asset details for provided list of asset ids.

    Args:
        asset_ids: Asset identifiers

    Returns:
        List of asset details.
    """
    endpoint = "api/asset/List/GetDetails"
    data = {"assetIds": list(asset_ids)}
    response = self._make_request(method="POST", endpoint=endpoint, json_data=data)
    response_model = self._decode_response_to_model(response, AssetsDetailsResponse)
    return response_model

get_report_assets_details(asset_ids)

Gets the list of asset details for provided list of asset ids. This endpoint is dedicated for the report usage.

Parameters:

Name Type Description Default
asset_ids Sequence[int]

Asset identifiers

required

Returns:

Type Description
ReportAssetsDetailsResponse

List of asset details.

Source code in reportconnectors/api_client/powertrain/asset/__init__.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def get_report_assets_details(self, asset_ids: Sequence[int]) -> ReportAssetsDetailsResponse:
    """
    Gets the list of asset details for provided list of asset ids. This endpoint is dedicated for
    the report usage.

    Args:
        asset_ids: Asset identifiers

    Returns:
        List of asset details.
    """
    endpoint = "api/report/asset/Report/Asset/Details"
    data = {"assetIds": list(asset_ids)}
    response = self._make_request(method="POST", endpoint=endpoint, json_data=data)
    response_model = self._decode_response_to_model(response, ReportAssetsDetailsResponse)
    return response_model

search_for_assets(organization_id=None, site_id=None, asset_group_id=None, **kwargs)

Returns a list of asset details that meets the search criteria.

You can search by organization ids, site ids, and asset group ids. At least one search criteria has to be provided.

Each search criteria can be provided as a single integer or a list of integers.

You can control number of output results and the result offset with page_number and page_size arguments.

Parameters:

Name Type Description Default
organization_id Union[int, List[int], None]

Organization identifier(s)

None
site_id Union[int, List[int], None]

Site identifier(s)

None
asset_group_id Union[int, List[int], None]

Asset group identifier(s)

None

Other Parameters:

Name Type Description
page_number int

Results page number. Default: 0

page_size int

Results page size. Default: 1000

Returns:

Type Description
AssetSearchResponse

List of asset details that meets the search criteria.

Raises:

Type Description
ValueError

If none of the search criteria is provided.

Source code in reportconnectors/api_client/powertrain/asset/__init__.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def search_for_assets(
    self,
    organization_id: Union[int, List[int], None] = None,
    site_id: Union[int, List[int], None] = None,
    asset_group_id: Union[int, List[int], None] = None,
    **kwargs,
) -> AssetSearchResponse:
    """
    Returns a list of asset details that meets the search criteria.

    You can search by organization ids, site ids, and asset group ids.
    At least one search criteria has to be provided.

    Each search criteria can be provided as a single integer or a list of integers.

    You can control number of output results and the result offset with `page_number` and `page_size` arguments.

    Args:
        organization_id: Organization identifier(s)
        site_id: Site identifier(s)
        asset_group_id: Asset group identifier(s)

    Keyword Args:
        page_number (int): Results page number. Default: `0`
        page_size (int): Results page size. Default: `1000`

    Returns:
        List of asset details that meets the search criteria.

    Raises:
        ValueError: If none of the search criteria is provided.

    """
    if organization_id is None and site_id is None and asset_group_id is None:
        raise ValueError("At least one of the search parameters has to be provided.")

    page_number = kwargs.get("page_number", 1)
    page_size = kwargs.get("page_size", 100)

    data = {
        "pageNumber": page_number,
        "pageSize": page_size,
    }
    for key, param in [
        ("organizationIds", organization_id),
        ("siteIds", site_id),
        ("assetGroupIds", asset_group_id),
    ]:
        if param is None:
            data[key] = []
        elif isinstance(param, list):
            data[key] = param
        else:
            data[key] = [param]

    endpoint = "api/asset/Search"
    response = self._make_request(method="POST", endpoint=endpoint, json_data=data)
    response_model = self._decode_response_to_model(response, AssetSearchResponse)
    return response_model