File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 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+
7992def 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
You can’t perform that action at this time.
0 commit comments