generated from pufereq/python-template
feat(message.py): add __str__ and __repr__ methods
This commit is contained in:
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
from typing import Any, override
|
||||
|
||||
from judas_protocol.types import Category, ControlAction
|
||||
|
||||
@@ -28,6 +28,14 @@ class Message:
|
||||
self.action: Enum = action
|
||||
self.payload: dict[str, Any] = payload or {}
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f"Message [{self.category.name}] {self.action.name} - {self.payload}"
|
||||
|
||||
@override
|
||||
def __repr__(self) -> str:
|
||||
return f"Message(category={self.category}, action={self.action}, payload={self.payload})"
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
"""Convert the message to a dictionary.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user