plugin - adds tower state to TowerInfo

The state flags whether the tower is reachable or not so the user can be aware of it
This commit is contained in:
Sergi Delgado Segura
2020-04-23 16:30:05 +02:00
parent 7b3bc6e6a8
commit bc5f09000a
2 changed files with 18 additions and 9 deletions

View File

@@ -1,7 +1,8 @@
class TowerInfo:
def __init__(self, netaddr, available_slots, appointments=None):
def __init__(self, netaddr, available_slots, status="active", appointments=None):
self.netaddr = netaddr
self.available_slots = available_slots
self.status = status
if not appointments:
self.appointments = {}
@@ -12,15 +13,16 @@ class TowerInfo:
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")
if any(v is None for v in [netaddr, available_slots, appointments]):
if any(v is None for v in [netaddr, available_slots, status, appointments]):
raise ValueError("Wrong appointment data, some fields are missing")
return cls(netaddr, available_slots, appointments)
return cls(netaddr, available_slots, status, appointments)
def to_dict(self):
return self.__dict__
def get_summary(self):
return {"netaddr": self.netaddr, "available_slots": self.available_slots}
return {"netaddr": self.netaddr, "status": self.status, "available_slots": self.available_slots}