Skip to content

Commit

Permalink
Add walrus as suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
bouwew committed Aug 13, 2024
1 parent b88d1ac commit 696649c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions plugwise/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ def _detect_low_batteries(self) -> list[str]:
for msg_id, notification in list(self._notifications.items()):
mac_address: str | None = None
message: str | None = notification.get("message")
if message is not None and all(x in message for x in matches):
mac_addresses = re.findall(mac_pattern, message)
if mac_addresses:
mac_address = mac_addresses[0] # re.findall() outputs a list
if (
message is not None
and all(x in message for x in matches)
and (mac_addresses := re.findall(mac_pattern, message)
):
mac_address = mac_addresses[0] # re.findall() outputs a list

if mac_address is not None:
self._notifications.pop(msg_id)
Expand Down

0 comments on commit 696649c

Please sign in to comment.