Skip to content

Commit 9378730

Browse files
authored
Merge pull request #190 from jhmpub/lgtv_retry
lgtv ConnectionResetError exception retry
2 parents b163976 + 3913921 commit 9378730

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["3.9", "3.10", "3.11"]
19+
python-version: ["3.12", "3.13", "3.14"]
2020

2121
steps:
2222
- uses: actions/checkout@v3

LGTV/__init__.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,30 @@ def main():
181181
cursor.execute(args.args)
182182
return
183183

184-
try:
185-
ws = LGTVRemote(name, **config[name], ssl=args.ssl)
186-
187-
if args.command == "on":
188-
# "on" is special, it doesn't use a websocket connection
189-
ws.on()
190-
return
191-
192-
ws.connect()
193-
ws.execute(args.command, kwargs)
194-
ws.run_forever()
195-
except KeyboardInterrupt:
196-
ws.close()
184+
max_retries = 3
185+
for attempt in range(max_retries):
186+
try:
187+
ws = LGTVRemote(name, **config[name], ssl=args.ssl)
188+
189+
if args.command == "on":
190+
# "on" is special, it doesn't use a websocket connection
191+
ws.on()
192+
return
193+
194+
ws.connect()
195+
ws.execute(args.command, kwargs)
196+
ws.run_forever()
197+
break
198+
except ConnectionResetError:
199+
if attempt < max_retries - 1:
200+
wait = 5
201+
print(f"Retrying in {wait} seconds...")
202+
sleep(wait)
203+
else:
204+
print("Max retries reached. Script failed")
205+
raise
206+
except KeyboardInterrupt:
207+
ws.close()
197208

198209
if __name__ == '__main__':
199210
main()

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ A big thanks for the contributions over the years too, lots of people have made
2020
* 60UJ6300-UA
2121
* HU80KG.AEU (CineBeam 4K)
2222
* OLED48A2
23+
* OLED48C5PUA
2324
* OLED55B7
2425
* OLED55C9
2526
* OLED55CX5LB
@@ -49,10 +50,12 @@ Tested with python 3.9 on Debian Unstable.
4950
Tested with python 3.10 on Windows 10/11
5051
Tested with 3.10 on WSL (Ubuntu 20.04)
5152
Tested with python 3.12 on macOS
53+
Tested with python 3.14 on Windows 11
5254

5355
### Likely supports
5456

5557
All devices with firmware major version 4, product name "webOSTV 2.0"
58+
All devices with firmware major version 33, product name "webOSTV 25"
5659

5760
## Available Commands
5861
lgtv scan

0 commit comments

Comments
 (0)