You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LOGGER.debug("Received response from %s %s", ip_address, str(res))
try:
port=int(res[2])
ifport<1orport>65535:
LOGGER.debug(
"Response contained an invalid port, ignoring"
)
port=None
exceptValueError:
port=None
ifportisNone:
LOGGER.debug(
"Response did not contain a valid port number,"
"an old Luxtronic software version might be the reason."
)
results.append((ip_address, port))
LOGGER.debug(
"Received response from %s, but with wrong content, skipping",
ip_address,
)
continue
# if the timeout triggers, go on an use the other broadcast port
exceptsocket.timeout:
break
returnresults
It works perfectly fine, but the function is potentially too big / complex.
It could be split into (at least) two functions, e.g. one that will send the packets and another one which will process the result. Potentially it could also be refactored to work asynchronously.
The advantage of having two such functions would be:
We could get rid of the pylint disable statement, since some of the complexity / indents would go into a dedicated function.
We could better test this module. Testing the function currently with pytest is non-trivial, because of the socket handling. On the other hand, having a function that will process data is easier to test.
This is not a high priority. Just writing it down, because I though about it. Also this might be a good start for new comers, so I would suggest to leave this open for someone to pick it up, since there is enough more serious work to do.
The text was updated successfully, but these errors were encountered:
The discover function in the discover module currently looks like this:
python-luxtronik/luxtronik/discover.py
Lines 20 to 73 in 72f2a05
It works perfectly fine, but the function is potentially too big / complex.
It could be split into (at least) two functions, e.g. one that will send the packets and another one which will process the result. Potentially it could also be refactored to work asynchronously.
The advantage of having two such functions would be:
pylint
disable statement, since some of the complexity / indents would go into a dedicated function.pytest
is non-trivial, because of the socket handling. On the other hand, having a function that will process data is easier to test.This is not a high priority. Just writing it down, because I though about it. Also this might be a good start for new comers, so I would suggest to leave this open for someone to pick it up, since there is enough more serious work to do.
The text was updated successfully, but these errors were encountered: