pybragerone.models.api.common¶
Common models shared across API modules.
Classes
|
Standard API response wrapper with status and data. |
|
Single permission string model for type safety. |
- class pybragerone.models.api.common.ApiResponse(**data: Any)[source]¶
Bases:
BaseModel,GenericStandard API response wrapper with status and data.
This wrapper provides a consistent interface for all API responses, including HTTP status code, response data, and optional headers.
Examples
- Single object response:
>>> response: ApiResponse[User] = await client.get_user() >>> if response.is_success: ... user = response.data
- List response:
>>> response: ApiResponse[list[Module]] = await client.get_modules(obj_id) >>> modules = response.data if response.is_success else []
- Raw data response:
>>> response: ApiResponse[dict[str, Any]] = await client.get_parameters(...) >>> params = response.data
- Variables:
status – HTTP status code (e.g., 200, 404, 500).
data – Response data of type T.
headers – Optional HTTP response headers.
- Parameters:
- data: T¶
- property is_client_error: bool¶
Check if response was client error (4xx status).
- Returns:
True if status is in range 400-499, False otherwise.
- property is_error: bool¶
Check if response was any error (4xx or 5xx status).
- Returns:
True if status is 400 or higher, False otherwise.
- property is_server_error: bool¶
Check if response was server error (5xx status).
- Returns:
True if status is in range 500-599, False otherwise.
- property is_success: bool¶
Check if response was successful (2xx status).
- Returns:
True if status is in range 200-299, False otherwise.
- class pybragerone.models.api.common.Permission(**data: Any)[source]¶
Bases:
BaseModelSingle permission string model for type safety.
Permissions in BragerOne API are uppercase strings with underscores, such as ‘DISPLAY_MENU_OBJECTS’, ‘SUBMISSION_CREATE’, etc.
Automatically converts from string or dict format.
Examples
- From string:
>>> perm = Permission(name="DISPLAY_MENU_OBJECTS") >>> perm = Permission.model_validate("DISPLAY_MENU_DHW")
- From dict (API response):
>>> perm = Permission.model_validate({"name": "SUBMISSION_CREATE"})
- As list (from API):
>>> perms = ["DISPLAY_MENU_CIRCUITS", "DISPLAY_PARAMETER_LEVEL_1"] >>> permissions = [Permission.model_validate(p) for p in perms]
- String representation:
>>> perm = Permission(name="DISPLAY_MENU_ALERTS") >>> str(perm) 'DISPLAY_MENU_ALERTS'
- Parameters:
name (str)
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod model_validate(obj: Any, **kwargs: Any)[source]¶
Validate and convert value to Permission.
- Parameters:
- Returns:
Permission– Permission instance.- Raises:
ValueError – If obj cannot be converted to Permission.
- Return type: