From 304687f7bd82cc918dcf127666339966503b08cd Mon Sep 17 00:00:00 2001 From: Micah Bowerbank Date: Fri, 9 Mar 2018 14:05:34 -0500 Subject: [PATCH] I added a file called settings.py which contains constants for ip address and port. This file is then used by all the other files that need the default IP address and port. I felt this was easier, so now you only have to change them in one place --- .gitignore | 2 ++ anthemav/tools.py | 5 +++-- example.py | 5 +++-- settings.py | 2 ++ setup.py | 2 +- tests/fulltests.py | 11 ++++++++--- 6 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 settings.py diff --git a/.gitignore b/.gitignore index 72364f9..a3c3406 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,8 @@ var/ *.egg-info/ .installed.cfg *.egg +.vscode/ +.pylintrc # PyInstaller # Usually these files are written by a python script from a template diff --git a/anthemav/tools.py b/anthemav/tools.py index 5448107..a6c2f0e 100644 --- a/anthemav/tools.py +++ b/anthemav/tools.py @@ -2,6 +2,7 @@ import argparse import asyncio import logging +import settings import anthemav @@ -22,8 +23,8 @@ def console(loop, log): Show debug logging. """ parser = argparse.ArgumentParser(description=console.__doc__) - parser.add_argument('--host', default='127.0.0.1', help='IP or FQDN of AVR') - parser.add_argument('--port', default='14999', help='Port of AVR') + parser.add_argument('--host', default=settings.IPADDRESS, help='IP or FQDN of AVR') + parser.add_argument('--port', default=settings.PORT, help='Port of AVR') parser.add_argument('--verbose', '-v', action='count') args = parser.parse_args() diff --git a/example.py b/example.py index 676e455..7f87cdd 100755 --- a/example.py +++ b/example.py @@ -4,14 +4,15 @@ import asyncio import anthemav import logging +import settings log = logging.getLogger(__name__) @asyncio.coroutine def test(): parser = argparse.ArgumentParser(description=test.__doc__) - parser.add_argument('--host', default='127.0.0.1', help='IP or FQDN of AVR') - parser.add_argument('--port', default='14999', help='Port of AVR') + parser.add_argument('--host', default=settings.IPADDRESS, help='IP or FQDN of AVR') + parser.add_argument('--port', default=settings.PORT, help='Port of AVR') parser.add_argument('--verbose', '-v', action='count') args = parser.parse_args() diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..f79e404 --- /dev/null +++ b/settings.py @@ -0,0 +1,2 @@ +IPADDRESS = '192.168.3.54' +PORT = '14999' \ No newline at end of file diff --git a/setup.py b/setup.py index 3139f6b..bc20d57 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup( name='anthemav', - version='1.1.8', + version='1.1.9', author='David McNett', author_email='nugget@macnugget.org', url='https://github.com/nugget/python-anthemav', diff --git a/tests/fulltests.py b/tests/fulltests.py index 49b61e6..4c84116 100755 --- a/tests/fulltests.py +++ b/tests/fulltests.py @@ -1,8 +1,13 @@ #!/usr/bin/env python3 +# to run this test you need to add the parent folder path to your PYTHONPATH. See the following example +# Use this command if your terminal is in the parent folder: PYTHONPATH=/path/to/parent/folder python tests/fulltests.py +# Use this command if your terminal is in the tests folder: PYTHONPATH=/path/to/parent/folder python fulltests.py + import asyncio import unittest import logging +import settings import anthemav @@ -13,10 +18,10 @@ def test(): def log_callback(message): log.info('Callback invoked: %s' % message) - host = '127.0.0.1' - port = 14999 + host = settings.IPADDRESS + port = settings.PORT - log.info('Connecting to Anthem AVR at %s:%i' % (host, port)) + log.info('Connecting to Anthem AVR at %s:%s' % (host, port)) # conn = yield from anthemav.Connection.create(host=host,port=port,loop=loop,update_callback=log_callback,auto_reconnect=False)