powermon.protocols.abstractprotocol module¶
protocols / abstractprotocol.py
- class powermon.protocols.abstractprotocol.AbstractProtocol(model=None)¶
Bases:
object
base definition for all protocols protocol has: - protocol id - dict of command definitions and functions to: - add / remove / count / get command definitions - check validity / crc / trim / split response
- add_command_definition(new_config, result_type=None)¶
Add a command definition
- add_command_definitions(command_definitions_config: dict = None, command_definitions_list: list = None, result_type: ResultType = None)¶
Add command definitions from the configuration
- add_supported_ports(port_types: list)¶
Add to the supported port types list
- check_crc(response: str, command_definition: CommandDefinition) bool ¶
crc check, needs override in protocol
- check_definitions_count(expected=None)¶
check and report number of command definitions, error if 0
- check_valid(response: str, command_definition: CommandDefinition) bool ¶
check response is valid
- clear_supported_ports()¶
Remove all supported port types except the TEST port type
- get_command_definition(command: str) CommandDefinition ¶
Get the command definition for a given command string
- get_command_definition_dtos() dict[str, CommandDefinitionDTO] ¶
convert all associated command objects to data transfer objects
- get_full_command(command: bytes | str) bytes ¶
generate the full command including crc and as needed
- get_id_command() Command ¶
return the command that generates a unique id for this type of device
- list_commands() dict[str, CommandDefinition] ¶
list available commands for the protocol
- property protocol_id: str¶
return the protocol id
- remove_command_definitions(commands_to_remove: list)¶
Remove specified command definitions
- replace_command_definition(command_definition_key, new_config)¶
Replace a command definition with a new one
- split_response(response: bytes, command_definition: CommandDefinition) list ¶
split response into individual items, return as ordered list or list of tuples
- to_dto() AbstractProtocolDTO ¶
convert protocol object to data transfer object
- trim_response(response: str, command_definition: CommandDefinition) str ¶
Remove extra characters from response
- class powermon.protocols.abstractprotocol.AbstractProtocolDTO(*, protocol_id: str, command_definitions: dict[str, CommandDefinitionDTO], supported_ports: list[PortType], id_command: None | str)¶
Bases:
BaseModel
data transfer model for AbstractPort class
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}¶
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'command_definitions': FieldInfo(annotation=dict[str, CommandDefinitionDTO], required=True), 'id_command': FieldInfo(annotation=Union[NoneType, str], required=True), 'protocol_id': FieldInfo(annotation=str, required=True), 'supported_ports': FieldInfo(annotation=list[PortType], required=True)}¶
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.