mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
class TowerInfo:
|
|
def __init__(
|
|
self,
|
|
netaddr,
|
|
available_slots,
|
|
status="reachable",
|
|
appointments=None,
|
|
pending_appointments=None,
|
|
invalid_appointments=None,
|
|
):
|
|
|
|
self.netaddr = netaddr
|
|
self.available_slots = available_slots
|
|
self.status = status
|
|
|
|
if not appointments:
|
|
self.appointments = {}
|
|
else:
|
|
self.appointments = appointments
|
|
|
|
if not pending_appointments:
|
|
self.pending_appointments = []
|
|
else:
|
|
self.pending_appointments = pending_appointments
|
|
|
|
if not invalid_appointments:
|
|
self.invalid_appointments = []
|
|
else:
|
|
self.invalid_appointments = invalid_appointments
|
|
|
|
@classmethod
|
|
def from_dict(cls, tower_data):
|
|
netaddr = tower_data.get("netaddr")
|
|
available_slots = tower_data.get("available_slots")
|
|
status = tower_data.get("status")
|
|
appointments = tower_data.get("appointments")
|
|
pending_appointments = tower_data.get("pending_appointments")
|
|
invalid_appointments = tower_data.get("invalid_appointments")
|
|
|
|
if any(
|
|
v is None
|
|
for v in [netaddr, available_slots, status, appointments, pending_appointments, invalid_appointments]
|
|
):
|
|
raise ValueError("Wrong appointment data, some fields are missing")
|
|
|
|
return cls(netaddr, available_slots, status, appointments, pending_appointments, invalid_appointments)
|
|
|
|
def to_dict(self):
|
|
return self.__dict__
|
|
|
|
def get_summary(self):
|
|
return TowerSummary(self)
|
|
|
|
|
|
class TowerSummary:
|
|
def __init__(self, tower_info):
|
|
self.netaddr = tower_info.netaddr
|
|
self.status = tower_info.status
|
|
self.available_slots = tower_info.available_slots
|
|
self.pending_appointments = tower_info.pending_appointments
|
|
self.invalid_appointments = tower_info.invalid_appointments
|
|
|
|
def to_dict(self):
|
|
return self.__dict__
|