File: firmware_note.py

package info (click to toggle)
python-asusrouter 1.21.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,856 kB
  • sloc: python: 20,497; makefile: 3
file content (50 lines) | stat: -rw-r--r-- 1,305 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Firmware release notes endpoint module."""

from __future__ import annotations

from typing import Any

from asusrouter.modules.data import AsusData
from asusrouter.tools.converters import clean_string


def read(content: str, **kwargs: Any) -> dict[str, Any]:
    """Read firmware release note data."""

    raw_note = content.replace("\ufeff", "")
    raw_note = raw_note.replace("\uff1a", ":")  # Replace the full-width colon

    # Empty release note -> fast return
    if raw_note == "\n\n":
        return {}

    # Get only the changes
    # 1. Split the data into lines
    lines = raw_note.splitlines()
    # 2. Clean the lines
    clean_lines = []
    for line in lines:
        if "Firmware version" in line or "Release Note" in line:
            continue
        clean_line = clean_string(line)
        if clean_line:
            clean_lines.append(clean_line)
    # 3. Combine the lines into a single string again
    note = "\n".join(clean_lines)

    release_note: dict[str, Any] = {
        "release_note": note,
        "release_note_raw": raw_note,
    }

    return release_note


def process(data: dict[str, Any]) -> dict[AsusData, Any]:
    """Process firmware release note data."""

    state: dict[AsusData, Any] = {
        AsusData.FIRMWARE_NOTE: data,
    }

    return state