Skip to content

Commit 3c616f3

Browse files
authored
Merge pull request #367 from plugwise/fix-ruff-noqa
Fix issue introduced by ruff: replace using .keys() in xml-find result
2 parents b93107d + 6355f29 commit 3c616f3

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Ongoing
4+
5+
- Fix issue introduced by ruff: replace using .keys() in xml-find result
6+
37
## v0.31.9: Further typing improvements
48

59
- Add NumberType, SelectType and SelectOptionsType constants to improve typing further

plugwise/helper.py

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

7878

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

13041314
locator = "./rule[active='true']/directives/when/then"
13051315
if (
1306-
active_rule := self._domain_objects.find(locator)
1307-
) is None or "icon" not in active_rule.keys(): # noqa: SIM118
1316+
not (active_rule := etree_to_dict(self._domain_objects.find(locator)))
1317+
or "icon" not in active_rule
1318+
):
13081319
return None
1309-
return str(active_rule.attrib["icon"])
1320+
1321+
return active_rule["icon"]
13101322

13111323
def _schedules_legacy(
13121324
self, avail: list[str], sel: str

0 commit comments

Comments
 (0)