Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define order on log messages and use in web UI #7

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2023-12-11

* Add a stable sort for event log items and use it in the web
index page.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
exclude MANIFEST.in
exclude poetry.lock
exclude CHANGELOG.md
exclude .pre-commit-config.yaml
exclude .flake8
exclude .dockerignore
Expand Down
5 changes: 1 addition & 4 deletions sagemcom_f3896_client/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import logging
import operator
import time
from contextlib import asynccontextmanager
from contextvars import ContextVar
Expand Down Expand Up @@ -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]:
Expand Down
8 changes: 7 additions & 1 deletion sagemcom_f3896_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down