do not add empty branches
This commit is contained in:
@@ -3,17 +3,20 @@ from .simpledevice import SimpleDevice
|
||||
|
||||
|
||||
def by_type(dev, typ):
|
||||
#TODO: adjust ID, name, description
|
||||
res = SimpleDevice(dev.ID, name=dev.name, description=dev.description)
|
||||
res = {}
|
||||
for k, v in dev.__dict__.items():
|
||||
if isinstance(v, typ):
|
||||
new = v
|
||||
res[k] = v
|
||||
elif isinstance(v, Device):
|
||||
new = by_type(v, typ)
|
||||
else:
|
||||
continue # ignore not matching
|
||||
res.__dict__[k] = new
|
||||
return res
|
||||
if new:
|
||||
res[k] = new
|
||||
|
||||
if res:
|
||||
#TODO: adjust ID, name, description
|
||||
return SimpleDevice(dev.ID, name=dev.name, description=dev.description, **res)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user