diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6be94e5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +## 2023-12-11 + + * Add a stable sort for event log items and use it in the web + index page. diff --git a/MANIFEST.in b/MANIFEST.in index b6ee12e..7a4114d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,6 @@ exclude MANIFEST.in exclude poetry.lock +exclude CHANGELOG.md exclude .pre-commit-config.yaml exclude .flake8 exclude .dockerignore diff --git a/sagemcom_f3896_client/client.py b/sagemcom_f3896_client/client.py index 73c5899..ff4eaab 100644 --- a/sagemcom_f3896_client/client.py +++ b/sagemcom_f3896_client/client.py @@ -1,6 +1,5 @@ import asyncio import logging -import operator import time from contextlib import asynccontextmanager from contextvars import ContextVar @@ -173,9 +172,7 @@ async def modem_event_log(self) -> List[EventLogItem]: async with self.__request("GET", "/rest/v1/cablemodem/eventlog") as resp: res = await resp.json() return sorted( - [EventLogItem.build(e) for e in res["eventlog"]], - key=operator.attrgetter("time"), - reverse=True, + (EventLogItem.build(e) for e in res["eventlog"]), reverse=True ) async def modem_service_flows(self) -> List[ModemServiceFlowResult]: diff --git a/sagemcom_f3896_client/models.py b/sagemcom_f3896_client/models.py index 3f5872a..3ecba44 100644 --- a/sagemcom_f3896_client/models.py +++ b/sagemcom_f3896_client/models.py @@ -36,8 +36,14 @@ def build(body: Dict[str, str]) -> "UserTokenResult": ) -@dataclass +@dataclass(order=True, frozen=True) class EventLogItem: + """Event log elements. + + Sorted by time, priority, message (field order). + Is hashable because it's frozen. + """ + time: datetime.datetime priority: Literal["error", "notice", "critical", "warning"] message: str