Skip to content

Commit

Permalink
fix: anel.py declare result in front of exception
Browse files Browse the repository at this point in the history
result is unbound if _receive times out with the follow exeception:

mtda-mcom mtda-service[1400]:     self._switch(False)
mtda-mcom mtda-service[1400]:   File "/usr/lib/python3.11/dist-packages/mtda/power/anel.py", line 88, in _switch
mtda-mcom mtda-service[1400]:     if result == "0":
mtda-mcom mtda-service[1400]:        ^^^^^^
mtda-mcom mtda-service[1400]: UnboundLocalError: cannot access local variable 'result' where it is not associated with a value
  • Loading branch information
gylstorffq authored and chombourger committed Dec 18, 2024
1 parent e8b4a47 commit 9e254cb
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions mtda/power/anel.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def _switch(self, state):
payload = f"Sw_{'on' if state else 'off'}{self._plug}"
self._send(payload)

result = None
try:
result = self._receive().split(':')[5+self._plug].rsplit(',', 1)[1]
except TimeoutError:
Expand Down

0 comments on commit 9e254cb

Please sign in to comment.