- 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.
26 lines
695 B
Python
26 lines
695 B
Python
from typing import TYPE_CHECKING
|
|
|
|
from .view import NodeView
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
from requests import Session
|
|
|
|
|
|
class Node:
|
|
def __init__(self, session: "Session", base_url: str):
|
|
self._session = session
|
|
self._base_url = base_url
|
|
self._data = None
|
|
|
|
def __call__(self, name: str) -> NodeView:
|
|
url = f"{self._base_url}/node/show/{name}"
|
|
if not url.endswith(".json"):
|
|
url += ".json"
|
|
response = self._session.get(url)
|
|
if response.status_code == 500:
|
|
raise ValueError(f"page {url} not found")
|
|
return NodeView(
|
|
session=self._session, base_url=self._base_url, data=response.json()
|
|
)
|