Compare commits

...

2 Commits

Author SHA1 Message Date
clerie bd68cbd7d8 Bootstrap child type casting 2022-05-01 23:55:18 +02:00
clerie 0e19927610 Restructuring api documentation 2022-05-01 22:43:52 +02:00
11 changed files with 166 additions and 74 deletions

7
docs/api/client.rst Normal file
View File

@ -0,0 +1,7 @@
mitel\_ommclient2.client module
===============================
.. automodule:: mitel_ommclient2.client
:members:
:undoc-members:
:show-inheritance:

7
docs/api/connection.rst Normal file
View File

@ -0,0 +1,7 @@
mitel\_ommclient2.connection module
===================================
.. automodule:: mitel_ommclient2.connection
:members:
:undoc-members:
:show-inheritance:

7
docs/api/exceptions.rst Normal file
View File

@ -0,0 +1,7 @@
mitel\_ommclient2.exceptions module
===================================
.. automodule:: mitel_ommclient2.exceptions
:members:
:undoc-members:
:show-inheritance:

View File

@ -6,4 +6,7 @@ API Documentation
.. toctree::
:maxdepth: 4
mitel_ommclient2
client
connection
exceptions
messages

View File

@ -1,53 +1,32 @@
mitel\_ommclient2.messages package
==================================
Submodules
----------
mitel\_ommclient2.messages.getaccount module
--------------------------------------------
.. automodule:: mitel_ommclient2.messages
:members:
:undoc-members:
:show-inheritance:
.. automodule:: mitel_ommclient2.messages.getaccount
:members:
:undoc-members:
:show-inheritance:
mitel\_ommclient2.messages.getppdev module
------------------------------------------
.. automodule:: mitel_ommclient2.messages.getppdev
:members:
:undoc-members:
:show-inheritance:
mitel\_ommclient2.messages.getppuser module
-------------------------------------------
.. automodule:: mitel_ommclient2.messages.getppuser
:members:
:undoc-members:
:show-inheritance:
mitel\_ommclient2.messages.open module
--------------------------------------
.. automodule:: mitel_ommclient2.messages.open
:members:
:undoc-members:
:show-inheritance:
mitel\_ommclient2.messages.ping module
--------------------------------------
.. automodule:: mitel_ommclient2.messages.ping
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: mitel_ommclient2.messages
:members:
:undoc-members:
:show-inheritance:

View File

@ -1,45 +0,0 @@
mitel\_ommclient2 package
=========================
Subpackages
-----------
.. toctree::
:maxdepth: 4
mitel_ommclient2.messages
Submodules
----------
mitel\_ommclient2.client module
-------------------------------
.. automodule:: mitel_ommclient2.client
:members:
:undoc-members:
:show-inheritance:
mitel\_ommclient2.connection module
-----------------------------------
.. automodule:: mitel_ommclient2.connection
:members:
:undoc-members:
:show-inheritance:
mitel\_ommclient2.exceptions module
-----------------------------------
.. automodule:: mitel_ommclient2.exceptions
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: mitel_ommclient2
:members:
:undoc-members:
:show-inheritance:

View File

@ -14,7 +14,7 @@ This is the documentation for mitel_ommclient2. To get started stick to the :doc
manual/client
manual/connection
manual/messages
api/modules
api/index
Indices and tables
==================

View File

@ -139,7 +139,7 @@ class OMMClient2:
yield user
# Determine next possible ppn
next_uid = int(user["uid"]) + 1
next_uid = int(user.uid) + 1
def ping(self):
"""

View File

@ -3,6 +3,7 @@
from xml.dom.minidom import getDOMImplementation, parseString
from ..exceptions import exception_classes, OMResponseException
from ..types import cast_dict_to_childtype
class Message:
@ -74,6 +75,9 @@ class Message:
else:
object.__setattr__(self, name, value)
def __repr__(self):
return "{}({}, {}, {})".format(self.__class__.__name__, self.name, repr(self._attrs), repr(self._childs))
class Request(Message):
"""
@ -179,6 +183,11 @@ def parse(message):
new_child[item.name] = item.value
childname = child.tagName
# cast dict into child type
if response_type.CHILDS.get(childname) is not None:
new_child = cast_dict_to_childtype(response_type.CHILDS[childname], new_child)
if childname in childs:
childs[childname].append(new_child)
else:

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3
from . import Request, Response, request_type, response_type
from ..types import PPUserType
@request_type
@ -14,5 +15,5 @@ class GetPPUser(Request):
@response_type
class GetPPUserResp(Response):
CHILDS = {
"user": None,
"user": PPUserType,
}

View File

@ -0,0 +1,124 @@
#!/usr/bin/env python3
class ChildType:
"""
Base type class
:param name: Name of the message
:param attrs: Message attributes
:param childs: Message children
"""
FIELDS = {}
def __init__(self, attrs={}):
self._attrs = {}
for k, v in attrs.items():
setattr(self, k, v)
def __getattr__(self, name):
if name in self.FIELDS.keys():
return self._attrs.get(name)
else:
raise AttributeError()
def __setattr__(self, name, value):
if name in self.FIELDS.keys():
if self.FIELDS[name] is not None and type(value) != self.FIELDS[name]:
raise TypeError()
self._attrs[name] = value
else:
object.__setattr__(self, name, value)
def __repr__(self):
return "{}({})".format(self.__class__.__name__, repr(self._attrs))
def cast_dict_to_childtype(t, d):
for k, v in d.items():
if k in t.FIELDS.keys():
if t.FIELDS[k] is not None and type(v) != t.FIELDS[k]:
d[k] = t.FIELDS[k](v)
else:
raise KeyError()
return t(d)
class PPUserType(ChildType):
FIELDS = {
"uid": int,
"timeStamp": int,
"relType": None, #PPRelTypeType,
"ppn": int,
"name": str,
"num": str,
"hierarchy1": str,
"hierarchy2": str,
"addId": str,
"pin": str,
"sipAuthId": str,
"sipPw": str,
"sosNum": str,
"voiceboxNum": str,
"manDownNum": str,
"forwardStateCall": None, #ForwardStateType,
"forwardTime": int,
"forwardDest": str,
"langPP": None, #LanguageType,
"holdRingBackTime": int,
"autoAnswer": str,
"microphoneMute": str,
"warningTone": str,
"allowBargeIn": str,
"callWaitingDisabled": bool,
"external": bool,
"trackingActive": bool,
"locatable": bool,
"BTlocatable": bool,
"BTsensitivity": str,
"locRight": bool,
"msgRight": bool,
"sendVcardRight": bool,
"recvVcardRight": bool,
"keepLocalPB": bool,
"vip": bool,
"sipRegisterCheck": bool,
"allowVideoStream": bool,
"conferenceServerType": str,
"conferenceServerURI": str,
"monitoringMode": str,
"CUS": None, #MonitoringStateType,
"HAS": None, #MonitoringStateType,
"HSS": None, #MonitoringStateType,
"HRS": None, #MonitoringStateType,
"HCS": None, #MonitoringStateType,
"SRS": None, #MonitoringStateType,
"SCS": None, #MonitoringStateType,
"CDS": None, #MonitoringStateType,
"HBS": None, #MonitoringStateType,
"BTS": None, #MonitoringStateType,
"SWS": None, #MonitoringStateType,
"credentialPw": str,
"configurationDataLoaded": bool,
"ppData": str,
"ppProfileId": int,
"fixedSipPort": int,
"calculatedSipPort": int,
# undocumented
"uidSec": int,
"permanent": bool,
"lang": None,
"forwardState": None,
"autoLogoutOnCharge": bool,
"hotDeskingSupport": bool,
"authenticateLogout": bool,
"useSIPUserName": None,
"useSIPUserAuthentication": None,
"serviceUserName": None,
"serviceAuthName": None,
"serviceAuthPassword": None,
"keyLockEnable": None,
"keyLockPin": None,
"keyLockTime": None,
}