21 Commits

Author SHA1 Message Date
github-actions[bot]
085c34f232 chore(release): 0.9.1 2026-03-05 21:29:13 +00:00
e8ef578141 fix(message.py): fix error on TELEMETRY msg 2026-03-05 22:28:42 +01:00
github-actions[bot]
3d5a1e95da chore(release): 0.9.0 2026-03-05 20:25:40 +00:00
4bba344e8a feat(message.py): add Message.Telemetry factory class 2026-03-05 21:25:11 +01:00
29bf802356 feat(types.py): add TELEMETRY category 2026-03-05 21:24:45 +01:00
github-actions[bot]
a805ccf38e chore(release): 0.8.0 2026-03-03 18:25:35 +00:00
1e9077c3a8 refactor(message.py): use ActionType instead of Enum 2026-03-03 18:09:53 +01:00
89f95004c1 chore(__init__.py): add ActionType to __all__ 2026-03-03 17:52:49 +01:00
795410047e feat(types.py): add ActionType type 2026-03-03 17:51:32 +01:00
github-actions[bot]
48a848bb60 chore(release): 0.7.0 2026-03-01 19:12:41 +00:00
0c0595b5f6 feat(message.py): move CONTROL-specific methods into Message.Control inner class 2026-03-01 20:11:49 +01:00
github-actions[bot]
d16c1914ba chore(release): 0.6.0 2026-02-28 19:54:47 +00:00
fbcce017a0 refactor(message.py): rename mac -> id 2026-02-28 20:52:58 +01:00
github-actions[bot]
c48b69ecee chore(release): 0.5.0 2025-11-19 20:28:01 +00:00
2ef4adaaa1 feat(message.py): add CLOSE msg constructor 2025-11-19 21:24:08 +01:00
aa0703fcde feat(types.py): add CLOSE msg ControlAction 2025-11-19 21:23:41 +01:00
332ce3ffa1 feat(message.py): add acknowledged and ack_required properties 2025-10-05 14:36:51 +02:00
github-actions[bot]
5ef300ff93 chore(release): 0.4.3 2025-10-05 11:43:19 +00:00
1ab577ebd5 fix(message.py): provide id_ in ack() and hello() 2025-10-05 13:42:23 +02:00
github-actions[bot]
6ce742667a chore(release): 0.4.2 2025-10-05 11:35:11 +00:00
37eec56afe fix(message.py): allow providing ID via argument 2025-10-05 13:34:28 +02:00
6 changed files with 234 additions and 44 deletions

View File

@@ -2,6 +2,65 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [0.9.1] - 2026-03-05
### Bug Fixes
- [`e8ef578`](https://gitea.pufereq.pl/judas/judas_protocol/commit/e8ef578141c7f7ea5ee1ee5fb9e9a22a73fd1cc2) **message.py**: fix error on TELEMETRY msg
## [0.9.0] - 2026-03-05
### Features
- [`4bba344`](https://gitea.pufereq.pl/judas/judas_protocol/commit/4bba344e8abcd64947c06b371ae84ca8f0591a9c) **message.py**: add `Message.Telemetry` factory class
- [`29bf802`](https://gitea.pufereq.pl/judas/judas_protocol/commit/29bf80235631f069be519e3e3ac0772c9a9d44db) **types.py**: add `TELEMETRY` category
## [0.8.0] - 2026-03-03
### Features
- [`7954100`](https://gitea.pufereq.pl/judas/judas_protocol/commit/795410047ef20ebb39503c09a5359e53475f2274) **types.py**: add `ActionType` type
### Miscellaneous Tasks
- [`89f9500`](https://gitea.pufereq.pl/judas/judas_protocol/commit/89f95004c1877263fbd1047fc09fe9196d8494f5) **__init__.py**: add `ActionType` to `__all__`
### Refactor
- [`1e9077c`](https://gitea.pufereq.pl/judas/judas_protocol/commit/1e9077c3a837d00c793ee50c5cbd754d5f0ec58a) **message.py**: use `ActionType` instead of `Enum`
## [0.7.0] - 2026-03-01
### Features
- [`0c0595b`](https://gitea.pufereq.pl/judas/judas_protocol/commit/0c0595b5f67526f1caa4f3650c04ae36180045c3) **message.py**: move CONTROL-specific methods into `Message.Control` inner class
## [0.6.0] - 2026-02-28
### Refactor
- [`fbcce01`](https://gitea.pufereq.pl/judas/judas_protocol/commit/fbcce017a0fb4e3e11916479413dc81fd313a52c) **message.py**: rename `mac` -> `id`
## [0.5.0] - 2025-11-19
### Features
- [`2ef4ada`](https://gitea.pufereq.pl/judas/judas_protocol/commit/2ef4adaaa1e872c3c622ec6c37966dda1c7665d3) **message.py**: add `CLOSE` msg constructor
- [`aa0703f`](https://gitea.pufereq.pl/judas/judas_protocol/commit/aa0703fcde9d531fc5eaf8d9c93b160422692387) **types.py**: add `CLOSE` msg ControlAction
- [`332ce3f`](https://gitea.pufereq.pl/judas/judas_protocol/commit/332ce3ffa16ba43d6af1ba71bce1bc633e1661a9) **message.py**: add `acknowledged` and `ack_required` properties
## [0.4.3] - 2025-10-05
### Bug Fixes
- [`1ab577e`](https://gitea.pufereq.pl/judas/judas_protocol/commit/1ab577ebd583ed17f813d37745b5dc195855d9c3) **message.py**: provide `id_` in `ack()` and `hello()`
## [0.4.2] - 2025-10-05
### Bug Fixes
- [`37eec56`](https://gitea.pufereq.pl/judas/judas_protocol/commit/37eec56afeb2697955702aba04476ccdde7435e4) **message.py**: allow providing ID via argument
## [0.4.1] - 2025-10-05 ## [0.4.1] - 2025-10-05
### Miscellaneous Tasks ### Miscellaneous Tasks

View File

@@ -4,7 +4,7 @@ build-backend = "uv_build"
[project] [project]
name = "judas_protocol" name = "judas_protocol"
version = "0.4.1" version = "0.9.1"
description = "The judas protocol" description = "The judas protocol"
readme = "README.md" readme = "README.md"
authors = [] authors = []

View File

@@ -1,6 +1,6 @@
__version__: str = "0.1.0" __version__: str = "0.1.0"
from .message import Message from .message import Message
from .types import Category, ControlAction from .types import ActionType, Category, ControlAction
__all__ = ["__version__", "Message", "Category", "ControlAction"] __all__ = ["__version__", "Message", "ActionType", "Category", "ControlAction"]

View File

@@ -3,10 +3,14 @@ from __future__ import annotations
import json import json
import uuid import uuid
from enum import Enum
from typing import Any, override from typing import Any, override
from judas_protocol.types import Category, ControlAction from judas_protocol.types import (
ActionType,
Category,
ControlAction,
TelemetryAction,
)
class Message: class Message:
@@ -14,29 +18,160 @@ class Message:
def __init__( def __init__(
self, self,
id_: str | None,
category: Category, category: Category,
action: Enum, action: ActionType,
payload: dict[str, Any] | None = None, payload: dict[str, Any] | None = None,
*,
acknowledged: bool = False,
ack_required: bool = False,
) -> None: ) -> None:
"""Initialize a Message. """Initialize a Message.
Args: Args:
id_ (str | None): The ID of the message. If None, a new UUID will be generated.
category (Category): The category of the message. category (Category): The category of the message.
action (Enum): The action of the message. action (ActionType): 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.
acknowledged (bool): Whether the message has been acknowledged. Defaults to False.
ack_required (bool): Whether the message requires an acknowledgment. Defaults to False.
""" """
self.id: str = str(uuid.uuid4()) self.id: str = id_ or str(uuid.uuid4())
self.category: Category = category self.category: Category = category
self.action: Enum = action self.action: ActionType = action
self.payload: dict[str, Any] = payload or {} self.payload: dict[str, Any] = payload or {}
self.acknowledged: bool = acknowledged
self.ack_required: bool = ack_required
@override @override
def __str__(self) -> str: def __str__(self) -> str:
return f"Message ({self.id}) [{self.category.name}] {self.action.name} - {self.payload}" return f"Message ({self.id}) ack'd: {self.acknowledged}, req: {self.ack_required} [{self.category.name}] {self.action.name} - {self.payload}"
@override @override
def __repr__(self) -> str: def __repr__(self) -> str:
return f"Message(category={self.category}, action={self.action}, payload={self.payload})" return (
f"Message(id_={self.id}, category={self.category}, action={self.action}"
f", payload={self.payload}, acknowledged={self.acknowledged}"
f", ack_required={self.ack_required})"
)
class Control:
"""CONTROL category message factory methods."""
@staticmethod
def ack(target_id: str) -> Message:
"""Create an ACK message.
Args:
target_id (str): The ID of the message to acknowledge.
Returns:
Message: The created ACK message.
"""
return Message(
id_=None,
category=Category.CONTROL,
action=ControlAction.ACK,
payload={"target_id": target_id},
acknowledged=False,
ack_required=False,
)
@staticmethod
def hello(id_: str) -> Message:
"""Create a HELLO message.
Args:
id_ (str): The ID to include in the HELLO message.
Returns:
Message: The created HELLO message.
"""
return Message(
id_=None,
category=Category.CONTROL,
action=ControlAction.HELLO,
payload={"id": id_},
acknowledged=False,
ack_required=True,
)
@staticmethod
def close() -> Message:
"""Create a CLOSE message.
Prompts the recipient to close the connection and not reconnect.
Returns:
Message: The created CLOSE message.
"""
return Message(
id_=None,
category=Category.CONTROL,
action=ControlAction.CLOSE,
payload={},
acknowledged=False,
ack_required=True,
)
class Telemetry:
"""TELEMETRY category message factory methods."""
@staticmethod
def initial(payload: dict[str, Any]) -> Message:
"""Create an INITIAL telemetry message.
Args:
payload (dict[str, Any]): The payload of the message.
Returns:
Message: The created INITIAL telemetry message.
"""
return Message(
id_=None,
category=Category.TELEMETRY,
action=TelemetryAction.INITIAL,
payload=payload,
acknowledged=False,
ack_required=True,
)
@staticmethod
def update(payload: dict[str, Any]) -> Message:
"""Create an UPDATE telemetry message.
Args:
payload (dict[str, Any]): The payload of the message.
Returns:
Message: The created UPDATE telemetry message.
"""
return Message(
id_=None,
category=Category.TELEMETRY,
action=TelemetryAction.UPDATE,
payload=payload,
acknowledged=False,
ack_required=False,
)
@staticmethod
def on_demand(payload: dict[str, Any]) -> Message:
"""Create an ON_DEMAND telemetry message.
Args:
payload (dict[str, Any]): The payload of the message.
Returns:
Message: The created ON_DEMAND telemetry message.
"""
return Message(
id_=None,
category=Category.TELEMETRY,
action=TelemetryAction.ON_DEMAND,
payload=payload,
acknowledged=False,
ack_required=True,
)
def to_dict(self) -> dict[str, Any]: def to_dict(self) -> dict[str, Any]:
"""Convert the message to a dictionary. """Convert the message to a dictionary.
@@ -49,6 +184,8 @@ class Message:
"category": self.category, "category": self.category,
"action": self.action, "action": self.action,
"payload": self.payload, "payload": self.payload,
"acknowledged": self.acknowledged,
"ack_required": self.ack_required,
} }
def to_json(self) -> str: def to_json(self) -> str:
@@ -77,17 +214,32 @@ class Message:
Returns: Returns:
Message: The created message. Message: The created message.
""" """
if "id" not in data:
data["id"] = None
id_: str | None = data["id"]
category = Category(data["category"]) category = Category(data["category"])
action_str = data["action"] action_str = data["action"]
acknowledged = data["acknowledged"]
ack_required = data["ack_required"]
match category: match category:
case Category.CONTROL: case Category.CONTROL:
action = ControlAction(action_str) action = ControlAction(action_str)
case Category.TELEMETRY:
action = TelemetryAction(action_str)
case _: case _:
raise ValueError(f"Unknown category: {category}") raise ValueError(f"Unknown category: {category}")
payload = data.get("payload", {}) payload = data.get("payload", {})
return cls(category=category, action=action, payload=payload) return cls(
id_=id_,
category=category,
action=action,
payload=payload,
acknowledged=acknowledged,
ack_required=ack_required,
)
@classmethod @classmethod
def from_json(cls, data: str) -> Message: def from_json(cls, data: str) -> Message:
@@ -115,34 +267,3 @@ class Message:
Message: The created message. Message: The created message.
""" """
return cls.from_json(data.decode("utf-8")) return cls.from_json(data.decode("utf-8"))
@classmethod
def ack(cls, target_id: str) -> Message:
"""Create an ACK message.
Args:
target_id (str): The ID of the message to acknowledge.
Returns:
Message: The created ACK message.
"""
return cls(
category=Category.CONTROL,
action=ControlAction.ACK,
payload={"target_id": target_id},
)
@classmethod
def hello(cls, mac: str) -> Message:
"""Create a HELLO message.
Args:
mac (str): The MAC address to include in the HELLO message.
Returns:
Message: The created HELLO message.
"""
return cls(
category=Category.CONTROL,
action=ControlAction.HELLO,
payload={"mac": mac},
)

View File

@@ -5,11 +5,21 @@ from __future__ import annotations
from enum import Enum from enum import Enum
type ActionType = ControlAction | TelemetryAction
class Category(str, Enum): class Category(str, Enum):
CONTROL = "control" CONTROL = "control"
TELEMETRY = "telemetry"
class ControlAction(str, Enum): class ControlAction(str, Enum):
HELLO = "hello" HELLO = "hello"
ACK = "ack" ACK = "ack"
CLOSE = "close"
class TelemetryAction(str, Enum):
INITIAL = "initial"
UPDATE = "update"
ON_DEMAND = "on_demand"

2
uv.lock generated
View File

@@ -240,7 +240,7 @@ wheels = [
[[package]] [[package]]
name = "judas-protocol" name = "judas-protocol"
version = "0.4.1" version = "0.9.1"
source = { editable = "." } source = { editable = "." }
[package.dev-dependencies] [package.dev-dependencies]