Skip to content

Commit 4148f6c

Browse files
committed
Fix 100% spin if connection lost.
1 parent 96df415 commit 4148f6c

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/powersensor_local/listener.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ async def _send_subscribe(self, writer):
6767

6868
async def _processline(self, ip, mac, reader, writer):
6969
data = await reader.readline()
70-
if data != b'' and data != b'\n':
70+
if data == b'':
71+
reader.feed_eof()
72+
writer.close()
73+
await writer.wait_closed()
74+
raise ConnectionResetError
75+
if data != b'\n':
7176
try:
7277
message = json.loads(data.decode('utf-8'))
7378
typ = message['type']
@@ -98,7 +103,8 @@ async def _connect_to_device(self, ip, mac, backoff=0):
98103

99104
except (ConnectionResetError, asyncio.TimeoutError):
100105
# Handle disconnection and retry with exponential backoff
101-
del self._connections[ip]
106+
if self._connections.get(ip) is not None:
107+
del self._connections[ip]
102108
await asyncio.sleep(min(5 * 60, 2**backoff * 1))
103109
return await self._connect_to_device(ip, mac, backoff)
104110

0 commit comments

Comments
 (0)