Add support for PP user

This commit is contained in:
clerie 2022-05-01 13:27:56 +02:00
parent 5365b942ce
commit 1752a9151d
3 changed files with 60 additions and 0 deletions

View File

@ -92,6 +92,37 @@ class OMMClient2:
# Determine next possible ppn
next_ppn = int(pp["ppn"]) + 1
def get_user(self, uid):
"""
Get PP user
:param uid: User id
"""
r = self.connection.request(messages.GetPPUser(uid))
r.raise_on_error()
if r.user is None:
return None
return r.user[0]
def get_users(self):
"""
Get all PP users
"""
next_uid = 0
while True:
r = self.connection.request(messages.GetPPUser(next_uid, maxRecords=20))
try:
r.raise_on_error()
except exceptions.ENoEnt:
# No more devices to fetch
break
# Output all found devices
for user in r.user:
yield user
# Determine next possible ppn
next_uid = int(user["uid"]) + 1
def ping(self):
"""

View File

@ -84,6 +84,7 @@ class Response:
from .getaccount import GetAccount, GetAccountResp
from .getppdev import GetPPDev, GetPPDevResp
from .getppuser import GetPPUser, GetPPUserResp
from .open import Open, OpenResp
from .ping import Ping, PingResp
@ -111,6 +112,7 @@ def _response_type_by_name(name):
response_types = [
GetAccountResp,
GetPPDevResp,
GetPPUserResp,
PingResp,
]

View File

@ -0,0 +1,27 @@
#!/usr/bin/env python3
from . import Request, Response
class GetPPUser(Request):
def __init__(self, uid, maxRecords=None, **kwargs):
super().__init__("GetPPUser", **kwargs)
self.attrs["uid"] = uid
if maxRecords is not None:
self.attrs["maxRecords"] = maxRecords
@property
def ppn(self):
return self.attrs.get("ppn")
@property
def maxRecords(self):
return self.attrs.get("maxRecords")
class GetPPUserResp(Response):
@property
def user(self):
return self.childs.get("user")