From 405f71f621ba887aa8747902e79c70abb75394c1 Mon Sep 17 00:00:00 2001 From: clerie Date: Sun, 19 Jun 2022 14:45:26 +0200 Subject: [PATCH] Add method to filter devices --- mitel_ommclient2/client.py | 14 ++++++++++++++ mitel_ommclient2/types/__init__.py | 3 +++ 2 files changed, 17 insertions(+) diff --git a/mitel_ommclient2/client.py b/mitel_ommclient2/client.py index 7e54f12..a63417f 100644 --- a/mitel_ommclient2/client.py +++ b/mitel_ommclient2/client.py @@ -147,6 +147,20 @@ class OMMClient2: d = self.get_device(ppn) return self.detach_user_device(d.uid, ppn) + def find_devices(self, filter): + """ + Get all devices matching a filter + + :param filter: function taking one parameter which is a device, returns True to keep, False to discard + + Usage:: + + >>> c.find_devices(lambda d: d.relType == mitel_ommclient2.types.PPRelTypeType("Unbound")) + """ + + for d in self.get_devices(): + if filter(d): + yield d def get_account(self, id): """ diff --git a/mitel_ommclient2/types/__init__.py b/mitel_ommclient2/types/__init__.py index b57d445..ec456c9 100644 --- a/mitel_ommclient2/types/__init__.py +++ b/mitel_ommclient2/types/__init__.py @@ -72,6 +72,9 @@ class EnumType: def __repr__(self): return "{}({})".format(self.__class__.__name__, repr(self.value)) + def __eq__(self, other): + return isinstance(other, type(self)) and self.value == other.value + class CallForwardStateType(EnumType): VALUES = [