Debian Codegraph @

asusrouter/modules/endpoint/firmware_note.py

raw
1 """Firmware release notes endpoint module."""
2
3 from __future__ import annotations
4
5 from typing import Any
6
7 from asusrouter.modules.data import AsusData
8 from asusrouter.tools.converters import clean_string
9
10
11 def read(content: str, **kwargs: Any) -> dict[str, Any]:
12 """Read firmware release note data."""
13
14 raw_note = content.replace("\ufeff", "")
15 raw_note = raw_note.replace("\uff1a", ":") # Replace the full-width colon
16
17 # Empty release note -> fast return
18 if raw_note == "\n\n":
19 return {}
20
21 # Get only the changes
22 # 1. Split the data into lines
23 lines = raw_note.splitlines()
24 # 2. Clean the lines
25 clean_lines = []
26 for line in lines:
27 if "Firmware version" in line or "Release Note" in line:
28 continue
29 clean_line = clean_string(line)
30 if clean_line:
31 clean_lines.append(clean_line)
32 # 3. Combine the lines into a single string again
33 note = "\n".join(clean_lines)
34
35 release_note: dict[str, Any] = {
36 "release_note": note,
37 "release_note_raw": raw_note,
38 }
39
40 return release_note
41
42
43 def process(data: dict[str, Any]) -> dict[AsusData, Any]:
44 """Process firmware release note data."""
45
46 state: dict[AsusData, Any] = {
47 AsusData.FIRMWARE_NOTE: data,
48 }
49
50 return state