Add function to get all devices

This commit is contained in:
clerie 2022-05-01 13:13:31 +02:00
parent 7064d6f615
commit 5365b942ce
1 changed files with 22 additions and 0 deletions

View File

@ -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?