Add ttp dependency and refactor OxiAPI and NodeConfig classes

- Added `ttp` as a dependency in `pyproject.toml` and `uv.lock`.
- Updated `NodeConfig` to store model names in lowercase.
- Refactored `OxiAPI` to always create a new session and added a `close` method.
- Removed unnecessary logging in `Node` class.
- Introduced interfaces for device registration with a new `BaseDevice` class and a `register_parser` function.
- Created initial structure for device models, including a `Mikrotik` parser.
This commit is contained in:
IluaAir
2026-02-14 21:31:02 +03:00
parent 8e85086d98
commit b60182ef3c
9 changed files with 57 additions and 19 deletions

View File

@@ -7,13 +7,12 @@ class OxiAPI:
def __init__(
self,
url: str,
session: Optional[Session] = None,
username: Optional[str] = None,
password: Optional[str] = None,
verify: bool = True,
):
self.base_url = url.rstrip("/")
self._session = session or Session()
self._session = Session()
self._session.verify = verify
if username and password:
self._session.auth = (username, password)
@@ -23,13 +22,7 @@ class OxiAPI:
return self
def __exit__(self, *args):
self._session.close()
self.close()
def get(self, endpoint: str, **kwargs) -> dict:
url = f"{self.base_url}/{endpoint.lstrip('/')}"
if not url.endswith(".json"):
url += ".json"
result = self._session.get(url, **kwargs)
if result.status_code == 500:
raise ValueError(f"page {url} not found")
return result.json()
def close(self):
return self._session.close()