Files
oxipy/oxi/interfaces/models/eltex.py
IluaAir 5fa56d46af Enhance BaseDevice initialization and error handling
- Updated the `BaseDevice` class constructor to accept an optional `name` parameter for better context in error messages.
- Improved the `_validate_contract` method to raise an `OxiAPIError` with a descriptive message if the node is not found.
- Modified the `_run_ttp` method to include a check for node existence, returning `None` if not found.
- Changed the test file name in the `Eltex` model to reflect a more descriptive context for testing node not found scenarios.
2026-04-18 19:21:25 +03:00

44 lines
1.3 KiB
Python

from oxi.interfaces import register_parser
from oxi.interfaces.base import BaseDevice
@register_parser("eltex")
class Eltex(BaseDevice):
template = "eltex.ttp"
def system(self) -> dict:
system = self.raw["system"]
serial_num = self.raw["serial"]
if serial_num:
if len(serial_num) > 1:
serial_num = serial_num[0]
system["serial_number"] = serial_num.get("serial_number")
return system
def vlans(self) -> list[dict]:
vlans_ttp = self.raw.get("vlans", [])
vlans = []
named_vlan = set()
for item in vlans_ttp:
if item.get("vlan_id"):
named_vlan.add(item.get("vlan_id"))
vlans.append(item)
else:
ids = item.get("vlan_ids", "")
tail = item.get("vlan_tail")
if tail:
ids = f"{ids},{tail}"
for vid in ids:
vid = vid.strip()
if vid in named_vlan:
continue
vlans.append({"vlan_id": vid})
return vlans
if __name__ == "__main__":
with open("./test_not_found.txt") as file:
data = file.read()
eltex = Eltex(data)
print(eltex.parse())