generated from pufereq/python-template
feat(message.py): add message uuid
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import uuid
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, override
|
from typing import Any, override
|
||||||
|
|
||||||
@@ -24,13 +25,14 @@ class Message:
|
|||||||
action (Enum): The action of the message.
|
action (Enum): The action of the message.
|
||||||
payload (dict[str, Any] | None): The payload of the message.
|
payload (dict[str, Any] | None): The payload of the message.
|
||||||
"""
|
"""
|
||||||
|
self.id: str = str(uuid.uuid4())
|
||||||
self.category: Category = category
|
self.category: Category = category
|
||||||
self.action: Enum = action
|
self.action: Enum = action
|
||||||
self.payload: dict[str, Any] = payload or {}
|
self.payload: dict[str, Any] = payload or {}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"Message [{self.category.name}] {self.action.name} - {self.payload}"
|
return f"Message ({self.id}) [{self.category.name}] {self.action.name} - {self.payload}"
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
@@ -43,6 +45,7 @@ class Message:
|
|||||||
dict[str, Any]: The message as a dictionary.
|
dict[str, Any]: The message as a dictionary.
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
|
"id": self.id,
|
||||||
"category": self.category,
|
"category": self.category,
|
||||||
"action": self.action,
|
"action": self.action,
|
||||||
"payload": self.payload,
|
"payload": self.payload,
|
||||||
|
|||||||
Reference in New Issue
Block a user