Requests Helpers¶
Refer to the smp documentation for a complete description of each SMP Request and Response.
Generics and TypeGuards for SMP Requests and Responses.
TEr1 = TypeVar('TEr1', bound=smperror.ErrorV1)
module-attribute
¶
Type of SMP Error V1.
TEr2 = TypeVar('TEr2', bound=smperror.ErrorV2)
module-attribute
¶
Type of SMP Error V2.
TRep = TypeVar('TRep', bound=Union[smpmessage.ReadResponse, smpmessage.WriteResponse])
module-attribute
¶
Type of successful SMP Response (ReadResponse or WriteResponse).
SMPRequest
¶
Bases: Protocol[TRep, TEr1, TEr2]
A Protocol
that groups the expected response and errors with a request.
To use, inherit from an SMP Read or Write Request
and define its expected
Response
, ErrorV1
, and ErrorV2
.
Example:
class ImageStatesRead(smpimg.ImageStatesReadRequest):
_Response = smpimg.ImageStatesReadResponse
_ErrorV1 = smpimg.ImageManagementErrorV1
_ErrorV2 = smpimg.ImageManagementErrorV2
Source code in smpclient/generics.py
error_v1(response: smperror.ErrorV1 | TEr2 | TRep) -> TypeGuard[smperror.ErrorV1]
¶
TypeGuard
that returns True
if the response
is an ErrorV1
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response |
ErrorV1 | TEr2 | TRep
|
The response to check. |
required |
Returns:
Type | Description |
---|---|
TypeGuard[ErrorV1]
|
|
Source code in smpclient/generics.py
error_v2(response: smperror.ErrorV1 | TEr2 | TRep) -> TypeGuard[TEr2]
¶
TypeGuard
that returns True
if the response
is an ErrorV2
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response |
ErrorV1 | TEr2 | TRep
|
The response to check. |
required |
Returns:
Type | Description |
---|---|
TypeGuard[TEr2]
|
|
Source code in smpclient/generics.py
error(response: smperror.ErrorV1 | TEr2 | TRep) -> TypeGuard[smperror.ErrorV1 | TEr2]
¶
TypeGuard
that returns True
if the response
is an ErrorV1
or ErrorV2
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response |
ErrorV1 | TEr2 | TRep
|
The response to check. |
required |
Returns:
Type | Description |
---|---|
TypeGuard[ErrorV1 | TEr2]
|
|
Source code in smpclient/generics.py
success(response: smperror.ErrorV1 | TEr2 | TRep) -> TypeGuard[TRep]
¶
TypeGuard
that returns True
if the response
is a successful Response
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response |
ErrorV1 | TEr2 | TRep
|
The response to check. |
required |
Returns:
Type | Description |
---|---|
TypeGuard[TRep]
|
|