Skip to content

Commit 18670dc

Browse files
committed
Add function etree_to_dict and implement
1 parent b93107d commit 18670dc

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

plugwise/helper.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@
7676
# from typing import cast
7777

7878

79+
def etree_to_dict(element):
80+
"""Helper-function translating xml Element to dict."""
81+
node: dict[str, str] = {}
82+
83+
if (text := getattr(element, "text", None)) is not None:
84+
node["text"] = text
85+
86+
if element is not None:
87+
node.update(element.items())
88+
89+
return node
90+
91+
7992
def update_helper(
8093
data: DeviceData,
8194
devices: dict[str, DeviceData],
@@ -1303,10 +1316,12 @@ def _preset(self, loc_id: str) -> str | None:
13031316

13041317
locator = "./rule[active='true']/directives/when/then"
13051318
if (
1306-
active_rule := self._domain_objects.find(locator)
1307-
) is None or "icon" not in active_rule.keys(): # noqa: SIM118
1319+
not (active_rule := etree_to_dict(self._domain_objects.find(locator)))
1320+
or "icon" not in active_rule
1321+
):
13081322
return None
1309-
return str(active_rule.attrib["icon"])
1323+
1324+
return active_rule["icon"]
13101325

13111326
def _schedules_legacy(
13121327
self, avail: list[str], sel: str

0 commit comments

Comments
 (0)