您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

111 行
2.7 KiB

  1. from http import HTTPStatus
  2. from typing import Any, Optional, Union
  3. import httpx
  4. from ... import errors
  5. from ...client import AuthenticatedClient, Client
  6. from ...models.zone_item import ZoneItem
  7. from ...types import Response
  8. def _get_kwargs(
  9. *,
  10. body: ZoneItem,
  11. ) -> dict[str, Any]:
  12. headers: dict[str, Any] = {}
  13. _kwargs: dict[str, Any] = {
  14. "method": "post",
  15. "url": "/postZone",
  16. }
  17. _kwargs["json"] = body.to_dict()
  18. headers["Content-Type"] = "application/json"
  19. _kwargs["headers"] = headers
  20. return _kwargs
  21. def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]:
  22. if response.status_code == 201:
  23. return None
  24. if response.status_code == 400:
  25. return None
  26. if response.status_code == 409:
  27. return None
  28. if client.raise_on_unexpected_status:
  29. raise errors.UnexpectedStatus(response.status_code, response.content)
  30. else:
  31. return None
  32. def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]:
  33. return Response(
  34. status_code=HTTPStatus(response.status_code),
  35. content=response.content,
  36. headers=response.headers,
  37. parsed=_parse_response(client=client, response=response),
  38. )
  39. def sync_detailed(
  40. *,
  41. client: Union[AuthenticatedClient, Client],
  42. body: ZoneItem,
  43. ) -> Response[Any]:
  44. """Post a zone item
  45. Post a zone item
  46. Args:
  47. body (ZoneItem): A zone is a room or a sub-area of a plan
  48. Raises:
  49. errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
  50. httpx.TimeoutException: If the request takes longer than Client.timeout.
  51. Returns:
  52. Response[Any]
  53. """
  54. kwargs = _get_kwargs(
  55. body=body,
  56. )
  57. response = client.get_httpx_client().request(
  58. **kwargs,
  59. )
  60. return _build_response(client=client, response=response)
  61. async def asyncio_detailed(
  62. *,
  63. client: Union[AuthenticatedClient, Client],
  64. body: ZoneItem,
  65. ) -> Response[Any]:
  66. """Post a zone item
  67. Post a zone item
  68. Args:
  69. body (ZoneItem): A zone is a room or a sub-area of a plan
  70. Raises:
  71. errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
  72. httpx.TimeoutException: If the request takes longer than Client.timeout.
  73. Returns:
  74. Response[Any]
  75. """
  76. kwargs = _get_kwargs(
  77. body=body,
  78. )
  79. response = await client.get_async_httpx_client().request(**kwargs)
  80. return _build_response(client=client, response=response)