Skip to content

Commit 951b25c

Browse files
committed
Implement CR suggestion
1 parent 27bef49 commit 951b25c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

plugwise_usb/network/cache.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@ async def restore_cache(self) -> None:
4545
self._nodetypes = {}
4646
for mac, node_value in data.items():
4747
node_type: NodeType | None = None
48-
try:
49-
node_type = NodeType(int(node_value)) # e.g. "2"
50-
except ValueError:
51-
tmp_node_value = node_value
52-
if len(node_value) >= 12: # e.g. "NodeType.CIRCLE"
53-
tmp_node_value = node_value[9:]
48+
# Backward-compatible parsing: support full enums, enum names, or numeric values
49+
val = node_value.strip()
50+
key = val.split(".", 1)[1] if val.startswith("NodeType.") else val
51+
node_type = NodeType.__members__.get(key) # e.g., "CIRCLE"
52+
if node_type is None and val.isdigit(): # e.g., "2"
5453
try:
55-
# node_value is e.g. "CIRCLE"
56-
node_type = NodeType.__members__.get(tmp_node_value)
57-
except KeyError:
54+
node_type = NodeType(int(val))
55+
except ValueError:
5856
node_type = None
5957

6058
if node_type is None:

0 commit comments

Comments
 (0)