powermon.device module

device.py

class powermon.device.Device(name: str, serial_number: str = '', model: str = '', manufacturer: str = '', port: AbstractPort = None)

Bases: object

A device is a port with a protocol also contains the name, model and id of the device

add_command(command: Command) None

add a command to the devices’ list of commands

Parameters:

command (Command) – Command object to add to list

adhoc_command_cb(client, userdata, msg)

callback for adhoc command messages

async finalize()

Device finalization activities

async classmethod from_config(config=None)

build the object from a config dict

async initialize()

Device initialization activities

property mqtt_broker: MqttBroker

the mqtt_broker object

property port: AbstractPort

the port associated with this device

async run(force=False)

checks for commands to run and runs them

async run_adhoc_commands()

check for any adhoc commands in the queue and run them

to_dto() DeviceDTO

convert the Device to a Data Transfer Object

class powermon.device.DeviceDTO(*, device_info: DeviceInfoDTO, port: _AbstractPortDTO, commands: list[CommandDTO])

Bases: BaseModel

data transfer model for Device 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]] = {'commands': FieldInfo(annotation=list[CommandDTO], required=True), 'device_info': FieldInfo(annotation=DeviceInfoDTO, required=True), 'port': FieldInfo(annotation=_AbstractPortDTO, 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.

class powermon.device.DeviceInfo(name, serial_number, model=None, manufacturer=None)

Bases: object

struct like class to contain info about the device

to_dto()

convert the DeviceInfo to a Data Transfer Object

class powermon.device.DeviceInfoDTO(*, name: str | int, serial_number: str | int, model: str | int | None, manufacturer: str | int | None)

Bases: BaseModel

data transfer model for DeviceInfo 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]] = {'manufacturer': FieldInfo(annotation=Union[str, int, NoneType], required=True), 'model': FieldInfo(annotation=Union[str, int, NoneType], required=True), 'name': FieldInfo(annotation=Union[str, int], required=True), 'serial_number': FieldInfo(annotation=Union[str, int], 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.