Bouni / python-luxtronik

python-luxtronik is a library that allow you to interact with a Luxtronik heatpump controller.
MIT License
37 stars 20 forks source link

Fix reading from socket #181

Closed gerw closed 1 month ago

gerw commented 3 months ago

Sometimes self._socket.recv returns fewer bytes than requested (for me, this happens sometimes over VPN). The current try-check in read_* is not helpful, since it just skews up the readings, e.g., if we only get 2 bytes for parameter 1, the remaining 2 bytes are then feed into parameter 2 and so on...

The current fix assures that the correct amount of bytes is read by introducing a new function _read_bytes().

github-actions[bot] commented 3 months ago

Coverage

Coverage Report
FileStmtsMissCoverMissing
luxtronik
   __init__.py18413328%39–51, 73–77, 80, 84–89, 93–97, 108–111, 119–121, 128–130, 137–139, 146–148, 157, 165–167, 170–173, 176–179, 182–198, 201–211, 214–226, 229–239, 243–245, 249–265, 269–270, 274–275, 286–288, 291, 294, 297, 300, 303–306, 309–312
   __main__.py21210%3–49
   datatypes.py275199%82
   discover.py403415%21–69
luxtronik/scripts
   dump_changes.py43430%7–85
   dump_luxtronik.py26260%6–52
TOTAL67525862% 

Tests Skipped Failures Errors Time
122 0 :zzz: 0 :x: 0 :fire: 0.762s :stopwatch:
kbabioch commented 3 months ago

What will happen if we request to read more data that is provided by the socket? Can thete be any kind of dead lock in this way?

gerw commented 3 months ago

Good point. I think one should check that at least one byte is returned, see https://docs.python.org/3/library/socket.html#socket.socket.recv.

In case nothing is returned by recv, the connection is lost. What to do in this case? Raise some error? Which one?