Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samsungctl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def _read_config():
"id": "",
"method": "legacy",
"timeout": 0,
"token": "",
})

file_loaded = False
Expand Down
11 changes: 8 additions & 3 deletions samsungctl/remote_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import logging
import socket
import time
import ssl

from . import exceptions


URL_FORMAT = "ws://{}:{}/api/v2/channels/samsung.remote.control?name={}"
URL_FORMAT = "wss://{}:{}/api/v2/channels/samsung.remote.control?name={}"


class RemoteWebsocket():
"""Object for remote control connection."""

def __init__(self, config):
self.token = ""
import websocket

if not config["port"]:
Expand All @@ -24,8 +25,10 @@ def __init__(self, config):

url = URL_FORMAT.format(config["host"], config["port"],
self._serialize_string(config["name"]))
if config["token"]:
url += "&token=" + config["token"]

self.connection = websocket.create_connection(url, config["timeout"])
self.connection = websocket.create_connection(url, ssl_handshake_timeout=config["timeout"], sslopt={"cert_reqs": ssl.CERT_NONE})

self._read_response()

Expand Down Expand Up @@ -72,6 +75,8 @@ def _read_response(self):
raise exceptions.UnhandledResponse(response)

logging.debug("Access granted.")
if response.get("token", False):
logging.info("Token: {}".format(response["token"]))

@staticmethod
def _serialize_string(string):
Expand Down