From 762532a30ede2fbfc31ea37d7a84c281519ca4dd Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Wed, 1 Mar 2023 16:59:17 +0100 Subject: [PATCH] do not add empty branches --- slic/core/device/filtered.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/slic/core/device/filtered.py b/slic/core/device/filtered.py index 2fae0912..4e8d30e4 100644 --- a/slic/core/device/filtered.py +++ b/slic/core/device/filtered.py @@ -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