Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #58 from Ape/pr/pep8
Browse files Browse the repository at this point in the history
Fix PEP 8 style issues
  • Loading branch information
Ape authored Jan 15, 2018
2 parents 49cbabc + 77ed783 commit 3249ce9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
10 changes: 5 additions & 5 deletions samsungctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from .remote import Remote

__title__ = "samsungctl"
__version__ = "0.7.0+1"
__url__ = "https://github.com/Ape/samsungctl"
__author__ = "Lauri Niskanen"
__title__ = "samsungctl"
__version__ = "0.7.0+1"
__url__ = "https://github.com/Ape/samsungctl"
__author__ = "Lauri Niskanen"
__author_email__ = "[email protected]"
__license__ = "MIT"
__license__ = "MIT"
12 changes: 9 additions & 3 deletions samsungctl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from . import exceptions
from . import Remote


def _read_config():
config = collections.defaultdict(lambda: None, {
"name": "samsungctl",
Expand Down Expand Up @@ -51,16 +52,19 @@ def _read_config():
try:
config_json = json.load(config_file)
except ValueError as e:
logging.warning("Warning: Could not parse the configuration file.\n %s", e)
messsage = "Warning: Could not parse the configuration file.\n %s"
logging.warning(message, e)
return config

config.update(config_json)

return config


def main():
epilog = "E.g. %(prog)s --host 192.168.0.10 --name myremote KEY_VOLDOWN"
parser = argparse.ArgumentParser(prog=title, description=doc,
epilog="E.g. %(prog)s --host 192.168.0.10 --name myremote KEY_VOLDOWN")
epilog=epilog)
parser.add_argument("--version", action="version",
version="%(prog)s {0}".format(version))
parser.add_argument("-v", "--verbose", action="count",
Expand All @@ -71,7 +75,8 @@ def main():
help="interactive control")
parser.add_argument("--host", help="TV hostname or IP address")
parser.add_argument("--port", type=int, help="TV port number (TCP)")
parser.add_argument("--method", help="Connection method (legacy or websocket)")
parser.add_argument("--method",
help="Connection method (legacy or websocket)")
parser.add_argument("--name", help="remote control name")
parser.add_argument("--description", metavar="DESC",
help="remote control description")
Expand Down Expand Up @@ -123,5 +128,6 @@ def main():
except OSError as e:
logging.error("Error: %s", e.strerror)


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions samsungctl/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ class AccessDenied(Exception):
"""Connection was denied."""
pass


class ConnectionClosed(Exception):
"""Connection was closed."""
pass


class UnhandledResponse(Exception):
"""Received unknown response."""
pass


class UnknownMethod(Exception):
"""Unknown method."""
pass
3 changes: 3 additions & 0 deletions samsungctl/interactive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import curses


_mappings = [
["p", "KEY_POWEROFF", "P", "Power off"],
["KEY_UP", "KEY_UP", "Up", "Up"],
Expand Down Expand Up @@ -40,10 +41,12 @@
["KEY_F(2)", "KEY_HDMI", "F2", "HDMI Source"],
]


def run(remote):
"""Run interactive remote control application."""
curses.wrapper(_control, remote)


def _control(stdscr, remote):
height, width = stdscr.getmaxyx()

Expand Down
1 change: 1 addition & 0 deletions samsungctl/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .remote_legacy import RemoteLegacy
from .remote_websocket import RemoteWebsocket


class Remote:
def __init__(self, config):
if config["method"] == "legacy":
Expand Down
3 changes: 2 additions & 1 deletion samsungctl/remote_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from . import exceptions


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

Expand Down Expand Up @@ -94,7 +95,7 @@ def _read_response(self, first_time=False):
raise exceptions.UnhandledResponse(response)

@staticmethod
def _serialize_string(string, raw = False):
def _serialize_string(string, raw=False):
if isinstance(string, str):
string = str.encode(string)

Expand Down
11 changes: 7 additions & 4 deletions samsungctl/remote_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

from . import exceptions


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


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

Expand All @@ -18,11 +22,10 @@ def __init__(self, config):
if config["timeout"] == 0:
config["timeout"] = None

URL_FORMAT = "ws://{}:{}/api/v2/channels/samsung.remote.control?name={}"
url = URL_FORMAT.format(config["host"], config["port"],
self._serialize_string(config["name"]))

"""Make a new connection."""
self.connection = websocket.create_connection(URL_FORMAT.format(config["host"], config["port"],
self._serialize_string(config["name"])), config["timeout"])
self.connection = websocket.create_connection(url, config["timeout"])

self._read_response()

Expand Down

0 comments on commit 3249ce9

Please sign in to comment.