fix: IP-independent pairing key fallback; run commands off the paho thread
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -153,8 +153,21 @@ from bscpylgtv import WebOsClient
|
||||
# = works regardless of cwd/env. Override with LGTV_KEY_FILE if needed.
|
||||
KEY = os.environ.get('LGTV_KEY_FILE') or os.path.expanduser('~/.aiopylgtv.sqlite')
|
||||
|
||||
# bscpylgtv stores keys per IP, but the TV doesn't care which IP a key comes
|
||||
# from. Without this, every DHCP drift = a fresh on-TV pairing prompt.
|
||||
def newest_key():
|
||||
import pickle, sqlite3
|
||||
try:
|
||||
row = sqlite3.connect(KEY).execute(
|
||||
"SELECT value FROM unnamed ORDER BY rowid DESC LIMIT 1").fetchone()
|
||||
return pickle.loads(row[0]) if row else None
|
||||
except sqlite3.Error:
|
||||
return None
|
||||
|
||||
async def main():
|
||||
client = await WebOsClient.create(os.environ['TV_IP'], key_file_path=KEY)
|
||||
if client.client_key is None:
|
||||
client.client_key = newest_key()
|
||||
await client.connect()
|
||||
await client.power_off()
|
||||
await asyncio.sleep(1)
|
||||
|
||||
Reference in New Issue
Block a user