-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathencrypted_authenticator.py
42 lines (30 loc) · 1.08 KB
/
encrypted_authenticator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import asyncio
import logging
from typing import Optional
import aiohttp
from samsungtvws.encrypted.authenticator import (
SamsungTVEncryptedWSAsyncAuthenticator,
)
logging.basicConfig(level=logging.DEBUG)
HOST = "1.2.3.4"
PORT = 8080 # Warning: this can be different from the remote port
async def _get_token(
host: str, web_session: aiohttp.ClientSession, port: int
) -> tuple[str, str]:
authenticator = SamsungTVEncryptedWSAsyncAuthenticator(
host, web_session=web_session, port=port
)
await authenticator.start_pairing()
token: Optional[str] = None
while not token:
pin = input("Please enter pin from tv: ")
token = await authenticator.try_pin(pin)
session_id = await authenticator.get_session_id_and_close()
return (token, session_id)
async def main() -> None:
"""Get token."""
async with aiohttp.ClientSession() as web_session:
token, session_id = await _get_token(HOST, web_session, PORT)
print(f"Token: '{token}', session: '{session_id}'")
loop = asyncio.get_event_loop()
loop.run_until_complete(main())