Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
from http import HTTPStatus
from typing import Any, Optional, Union, cast

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.uplink_route import UplinkRoute
from ...types import Response


def _get_kwargs(
device_id: str,
) -> dict[str, Any]:
_kwargs: dict[str, Any] = {
"method": "get",
"url": f"/device/deviceId/{device_id}/lastRoute",
}

return _kwargs


def _parse_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Optional[Union[Any, UplinkRoute]]:
if response.status_code == 200:
response_200 = UplinkRoute.from_dict(response.json())

return response_200
if response.status_code == 404:
response_404 = cast(Any, None)
return response_404
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Response[Union[Any, UplinkRoute]]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
device_id: str,
*,
client: Union[AuthenticatedClient, Client],
) -> Response[Union[Any, UplinkRoute]]:
"""Get last route by DeviceID

Args:
device_id (str):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Union[Any, UplinkRoute]]
"""

kwargs = _get_kwargs(
device_id=device_id,
)

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
device_id: str,
*,
client: Union[AuthenticatedClient, Client],
) -> Optional[Union[Any, UplinkRoute]]:
"""Get last route by DeviceID

Args:
device_id (str):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Union[Any, UplinkRoute]
"""

return sync_detailed(
device_id=device_id,
client=client,
).parsed


async def asyncio_detailed(
device_id: str,
*,
client: Union[AuthenticatedClient, Client],
) -> Response[Union[Any, UplinkRoute]]:
"""Get last route by DeviceID

Args:
device_id (str):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Union[Any, UplinkRoute]]
"""

kwargs = _get_kwargs(
device_id=device_id,
)

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
device_id: str,
*,
client: Union[AuthenticatedClient, Client],
) -> Optional[Union[Any, UplinkRoute]]:
"""Get last route by DeviceID

Args:
device_id (str):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Union[Any, UplinkRoute]
"""

return (
await asyncio_detailed(
device_id=device_id,
client=client,
)
).parsed
165 changes: 165 additions & 0 deletions src/infuse_iot/api_client/api/device/get_last_routes_for_devices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
from http import HTTPStatus
from typing import Any, Optional, Union

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.get_last_routes_for_devices_body import GetLastRoutesForDevicesBody
from ...models.uplink_route_and_device_id import UplinkRouteAndDeviceId
from ...types import Response


def _get_kwargs(
*,
body: GetLastRoutesForDevicesBody,
) -> dict[str, Any]:
headers: dict[str, Any] = {}

_kwargs: dict[str, Any] = {
"method": "post",
"url": "/device/lastRoute",
}

_body = body.to_dict()

_kwargs["json"] = _body
headers["Content-Type"] = "application/json"

_kwargs["headers"] = headers
return _kwargs


def _parse_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Optional[list["UplinkRouteAndDeviceId"]]:
if response.status_code == 200:
response_200 = []
_response_200 = response.json()
for response_200_item_data in _response_200:
response_200_item = UplinkRouteAndDeviceId.from_dict(response_200_item_data)

response_200.append(response_200_item)

return response_200
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Response[list["UplinkRouteAndDeviceId"]]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
*,
client: Union[AuthenticatedClient, Client],
body: GetLastRoutesForDevicesBody,
) -> Response[list["UplinkRouteAndDeviceId"]]:
"""Get last routes for a group of devices

Args:
body (GetLastRoutesForDevicesBody): Body for getting last routes for devices

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[list['UplinkRouteAndDeviceId']]
"""

kwargs = _get_kwargs(
body=body,
)

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
*,
client: Union[AuthenticatedClient, Client],
body: GetLastRoutesForDevicesBody,
) -> Optional[list["UplinkRouteAndDeviceId"]]:
"""Get last routes for a group of devices

Args:
body (GetLastRoutesForDevicesBody): Body for getting last routes for devices

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
list['UplinkRouteAndDeviceId']
"""

return sync_detailed(
client=client,
body=body,
).parsed


async def asyncio_detailed(
*,
client: Union[AuthenticatedClient, Client],
body: GetLastRoutesForDevicesBody,
) -> Response[list["UplinkRouteAndDeviceId"]]:
"""Get last routes for a group of devices

Args:
body (GetLastRoutesForDevicesBody): Body for getting last routes for devices

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[list['UplinkRouteAndDeviceId']]
"""

kwargs = _get_kwargs(
body=body,
)

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
*,
client: Union[AuthenticatedClient, Client],
body: GetLastRoutesForDevicesBody,
) -> Optional[list["UplinkRouteAndDeviceId"]]:
"""Get last routes for a group of devices

Args:
body (GetLastRoutesForDevicesBody): Body for getting last routes for devices

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
list['UplinkRouteAndDeviceId']
"""

return (
await asyncio_detailed(
client=client,
body=body,
)
).parsed
4 changes: 4 additions & 0 deletions src/infuse_iot/api_client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from .error import Error
from .forwarded_downlink_route import ForwardedDownlinkRoute
from .forwarded_uplink_route import ForwardedUplinkRoute
from .get_last_routes_for_devices_body import GetLastRoutesForDevicesBody
from .health_check import HealthCheck
from .interface_data import InterfaceData
from .key import Key
Expand All @@ -74,6 +75,7 @@
from .udp_downlink_route import UdpDownlinkRoute
from .udp_uplink_route import UdpUplinkRoute
from .uplink_route import UplinkRoute
from .uplink_route_and_device_id import UplinkRouteAndDeviceId

__all__ = (
"Algorithm",
Expand Down Expand Up @@ -128,6 +130,7 @@
"Error",
"ForwardedDownlinkRoute",
"ForwardedUplinkRoute",
"GetLastRoutesForDevicesBody",
"HealthCheck",
"InterfaceData",
"Key",
Expand All @@ -150,4 +153,5 @@
"UdpDownlinkRoute",
"UdpUplinkRoute",
"UplinkRoute",
"UplinkRouteAndDeviceId",
)
Loading
Loading