From 5365b942cebde684617b2a1b114a23b6008e19b1 Mon Sep 17 00:00:00 2001 From: clerie Date: Sun, 1 May 2022 13:13:31 +0200 Subject: [PATCH] Add function to get all devices --- mitel_ommclient2/client.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mitel_ommclient2/client.py b/mitel_ommclient2/client.py index 9e68dbd..283e07a 100644 --- a/mitel_ommclient2/client.py +++ b/mitel_ommclient2/client.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from .connection import Connection +from . import exceptions from . import messages class OMMClient2: @@ -71,6 +72,27 @@ class OMMClient2: return None return r.pp[0] + def get_devices(self): + """ + Get all PP devices + """ + next_ppn = 0 + while True: + r = self.connection.request(messages.GetPPDev(next_ppn, maxRecords=20)) + try: + r.raise_on_error() + except exceptions.ENoEnt: + # No more devices to fetch + break + + # Output all found devices + for pp in r.pp: + yield pp + + # Determine next possible ppn + next_ppn = int(pp["ppn"]) + 1 + + def ping(self): """ Is OMM still there?