Minor EWW script cleanup
This commit is contained in:
parent
287df92d65
commit
abbd3df78b
5 changed files with 23 additions and 35 deletions
|
@ -9,14 +9,14 @@ from typing import Literal, NoReturn
|
|||
|
||||
|
||||
def get_interfaces() -> list[Path]:
|
||||
return list(Path("/sys/class/net/").glob("*"))
|
||||
return list(Path("/sys/class/net/").iterdir())
|
||||
|
||||
|
||||
class TransferredBytes:
|
||||
def __init__(self, interface: Path, statistic: Literal["tx"] | Literal["rx"]) -> None:
|
||||
self._statistic = interface / f"statistics/{statistic}_bytes"
|
||||
self._current = int(self._statistic.read_text())
|
||||
self._previous = self._current
|
||||
self._statistic: Path = interface / f"statistics/{statistic}_bytes"
|
||||
self._current: int = int(self._statistic.read_text())
|
||||
self._previous: int = self._current
|
||||
|
||||
def update(self) -> None:
|
||||
self._previous = self._current
|
||||
|
@ -28,7 +28,7 @@ class TransferredBytes:
|
|||
|
||||
class Status:
|
||||
def __init__(self, interface: Path) -> None:
|
||||
self._statistic = interface / "operstate"
|
||||
self._statistic: Path = interface / "operstate"
|
||||
|
||||
def up(self) -> bool:
|
||||
return self._statistic.read_text().strip() == "up"
|
||||
|
@ -56,10 +56,10 @@ def format_bytes(num: float) -> str:
|
|||
|
||||
class Interface:
|
||||
def __init__(self, location: Path) -> None:
|
||||
self._location = location
|
||||
self._tx = TransferredBytes(location, "tx")
|
||||
self._rx = TransferredBytes(location, "rx")
|
||||
self._status = Status(location)
|
||||
self._location: Path = location
|
||||
self._tx: TransferredBytes = TransferredBytes(location, "tx")
|
||||
self._rx: TransferredBytes = TransferredBytes(location, "rx")
|
||||
self._status: Status = Status(location)
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
|
@ -84,7 +84,7 @@ class Interface:
|
|||
|
||||
class Statistics:
|
||||
def __init__(self) -> None:
|
||||
self._interfaces = [Interface(location) for location in get_interfaces()]
|
||||
self._interfaces: list[Interface] = [Interface(location) for location in get_interfaces()]
|
||||
|
||||
def update(self) -> None:
|
||||
for interface in self._interfaces:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue