Implement EnumType
This commit is contained in:
parent
80eec844bf
commit
bb8dd03299
@ -11,12 +11,15 @@ class ChildType:
|
|||||||
|
|
||||||
FIELDS = {}
|
FIELDS = {}
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, attrs={}):
|
def __init__(self, attrs={}):
|
||||||
self._attrs = {}
|
self._attrs = {}
|
||||||
|
|
||||||
for k, v in attrs.items():
|
if self.FIELDS is not None:
|
||||||
setattr(self, k, v)
|
for k, v in attrs.items():
|
||||||
|
setattr(self, k, v)
|
||||||
|
else:
|
||||||
|
# don't check attrs for types we do have any information
|
||||||
|
self._attrs = attrs
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if name in self.FIELDS.keys():
|
if name in self.FIELDS.keys():
|
||||||
@ -45,11 +48,54 @@ def cast_dict_to_childtype(t, d):
|
|||||||
|
|
||||||
return t(d)
|
return t(d)
|
||||||
|
|
||||||
|
|
||||||
|
class EnumType:
|
||||||
|
|
||||||
|
VALUES = [] # Allowed values
|
||||||
|
|
||||||
|
def __init__(self, s):
|
||||||
|
if self.VALUES is not None:
|
||||||
|
if s in self.VALUES:
|
||||||
|
self.value = s
|
||||||
|
else:
|
||||||
|
raise ValueError()
|
||||||
|
else:
|
||||||
|
self.value = s
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.value)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "{}({})".format(self.__class__.__name__, repr(self.value))
|
||||||
|
|
||||||
|
|
||||||
|
class CallForwardStateType(EnumType):
|
||||||
|
VALUES = [
|
||||||
|
"Off",
|
||||||
|
"Busy",
|
||||||
|
"NoAnswer",
|
||||||
|
"BusyNoAnswer",
|
||||||
|
"All",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class LanguageType(EnumType):
|
||||||
|
VALUES = None
|
||||||
|
|
||||||
|
|
||||||
|
class MonitoringStateType(EnumType):
|
||||||
|
VALUES = None
|
||||||
|
|
||||||
|
|
||||||
|
class PPRelTypeType(EnumType):
|
||||||
|
VALUES = None
|
||||||
|
|
||||||
|
|
||||||
class PPUserType(ChildType):
|
class PPUserType(ChildType):
|
||||||
FIELDS = {
|
FIELDS = {
|
||||||
"uid": int,
|
"uid": int,
|
||||||
"timeStamp": int,
|
"timeStamp": int,
|
||||||
"relType": None, #PPRelTypeType,
|
"relType": PPRelTypeType,
|
||||||
"ppn": int,
|
"ppn": int,
|
||||||
"name": str,
|
"name": str,
|
||||||
"num": str,
|
"num": str,
|
||||||
@ -62,10 +108,10 @@ class PPUserType(ChildType):
|
|||||||
"sosNum": str,
|
"sosNum": str,
|
||||||
"voiceboxNum": str,
|
"voiceboxNum": str,
|
||||||
"manDownNum": str,
|
"manDownNum": str,
|
||||||
"forwardStateCall": None, #ForwardStateType,
|
"forwardState": CallForwardStateType,
|
||||||
"forwardTime": int,
|
"forwardTime": int,
|
||||||
"forwardDest": str,
|
"forwardDest": str,
|
||||||
"langPP": None, #LanguageType,
|
"langPP": LanguageType,
|
||||||
"holdRingBackTime": int,
|
"holdRingBackTime": int,
|
||||||
"autoAnswer": str,
|
"autoAnswer": str,
|
||||||
"microphoneMute": str,
|
"microphoneMute": str,
|
||||||
@ -88,17 +134,17 @@ class PPUserType(ChildType):
|
|||||||
"conferenceServerType": str,
|
"conferenceServerType": str,
|
||||||
"conferenceServerURI": str,
|
"conferenceServerURI": str,
|
||||||
"monitoringMode": str,
|
"monitoringMode": str,
|
||||||
"CUS": None, #MonitoringStateType,
|
"CUS": MonitoringStateType,
|
||||||
"HAS": None, #MonitoringStateType,
|
"HAS": MonitoringStateType,
|
||||||
"HSS": None, #MonitoringStateType,
|
"HSS": MonitoringStateType,
|
||||||
"HRS": None, #MonitoringStateType,
|
"HRS": MonitoringStateType,
|
||||||
"HCS": None, #MonitoringStateType,
|
"HCS": MonitoringStateType,
|
||||||
"SRS": None, #MonitoringStateType,
|
"SRS": MonitoringStateType,
|
||||||
"SCS": None, #MonitoringStateType,
|
"SCS": MonitoringStateType,
|
||||||
"CDS": None, #MonitoringStateType,
|
"CDS": MonitoringStateType,
|
||||||
"HBS": None, #MonitoringStateType,
|
"HBS": MonitoringStateType,
|
||||||
"BTS": None, #MonitoringStateType,
|
"BTS": MonitoringStateType,
|
||||||
"SWS": None, #MonitoringStateType,
|
"SWS": MonitoringStateType,
|
||||||
"credentialPw": str,
|
"credentialPw": str,
|
||||||
"configurationDataLoaded": bool,
|
"configurationDataLoaded": bool,
|
||||||
"ppData": str,
|
"ppData": str,
|
||||||
@ -109,7 +155,6 @@ class PPUserType(ChildType):
|
|||||||
"uidSec": int,
|
"uidSec": int,
|
||||||
"permanent": bool,
|
"permanent": bool,
|
||||||
"lang": None,
|
"lang": None,
|
||||||
"forwardState": None,
|
|
||||||
"autoLogoutOnCharge": bool,
|
"autoLogoutOnCharge": bool,
|
||||||
"hotDeskingSupport": bool,
|
"hotDeskingSupport": bool,
|
||||||
"authenticateLogout": bool,
|
"authenticateLogout": bool,
|
||||||
|
Loading…
Reference in New Issue
Block a user