From e6927a95f20811c4df729751ba9fec677d3bdfa8 Mon Sep 17 00:00:00 2001 From: Marcus Young Date: Thu, 22 Jul 2021 21:29:11 -0500 Subject: [PATCH] Allow temperature and gravity offsets --- README.md | 2 + poetry.lock | 562 +++++++++++++++++++++++-------------------- tests/test_tilty.py | 36 ++- tilty/cli.py | 28 ++- tilty/common.py | 2 +- tilty/tilt_device.py | 10 +- 6 files changed, 366 insertions(+), 274 deletions(-) diff --git a/README.md b/README.md index 5dbcd69..f996e7d 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ The Tilt supports writing to a google doc which you could use with something lik $ cat <config.ini [general] sleep_interval = 2 # defaults to 1 +gravity_offset = -0.001 # subtract 0.001 gravity +temperature_offset = 3 # add 3 degrees logging_level = DEBUG # defaults to INFO logfile = /var/log/foo.log # defaults to stdout diff --git a/poetry.lock b/poetry.lock index 2d33a01..2139f09 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,116 +1,121 @@ [[package]] -name = "appdirs" -version = "1.4.4" -description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." category = "dev" +description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +name = "appdirs" optional = false python-versions = "*" +version = "1.4.4" [[package]] -name = "astroid" -version = "2.5.6" -description = "An abstract syntax tree for Python with inference support." category = "dev" +description = "An abstract syntax tree for Python with inference support." +name = "astroid" optional = false python-versions = "~=3.6" +version = "2.5.6" [package.dependencies] lazy-object-proxy = ">=1.4.0" -typed-ast = {version = ">=1.4.0,<1.5", markers = "implementation_name == \"cpython\" and python_version < \"3.8\""} wrapt = ">=1.11,<1.13" +[package.dependencies.typed-ast] +python = "<3.8" +version = ">=1.4.0,<1.5" + [[package]] -name = "atomicwrites" -version = "1.4.0" -description = "Atomic file writes." category = "dev" +description = "Atomic file writes." +marker = "sys_platform == \"win32\"" +name = "atomicwrites" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "1.4.0" [[package]] -name = "attrs" -version = "21.2.0" -description = "Classes Without Boilerplate" category = "dev" +description = "Classes Without Boilerplate" +name = "attrs" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "21.2.0" [package.extras] -dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit"] +dev = ["coverage (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit"] docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] -tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface"] -tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins"] +tests = ["coverage (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface"] +tests_no_zope = ["coverage (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins"] [[package]] -name = "bandit" -version = "1.7.0" -description = "Security oriented static analyser for python code." category = "dev" +description = "Security oriented static analyser for python code." +name = "bandit" optional = false python-versions = ">=3.5" +version = "1.7.0" [package.dependencies] -colorama = {version = ">=0.3.9", markers = "platform_system == \"Windows\""} GitPython = ">=1.0.1" PyYAML = ">=5.3.1" +colorama = ">=0.3.9" six = ">=1.10.0" stevedore = ">=1.20.0" [[package]] -name = "cachetools" -version = "4.2.2" -description = "Extensible memoizing collections and decorators" category = "main" +description = "Extensible memoizing collections and decorators" +name = "cachetools" optional = false python-versions = "~=3.5" +version = "4.2.2" [[package]] -name = "certifi" -version = "2021.5.30" -description = "Python package for providing Mozilla's CA Bundle." category = "main" +description = "Python package for providing Mozilla's CA Bundle." +name = "certifi" optional = false python-versions = "*" +version = "2021.5.30" [[package]] -name = "chardet" -version = "4.0.0" -description = "Universal encoding detector for Python 2 and 3" category = "main" +description = "Universal encoding detector for Python 2 and 3" +name = "chardet" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "4.0.0" [[package]] -name = "click" -version = "7.1.2" -description = "Composable command line interface toolkit" category = "main" +description = "Composable command line interface toolkit" +name = "click" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "7.1.2" [[package]] -name = "colorama" -version = "0.4.4" -description = "Cross-platform colored terminal text." category = "dev" +description = "Cross-platform colored terminal text." +marker = "sys_platform == \"win32\" or platform_system == \"Windows\"" +name = "colorama" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "0.4.4" [[package]] -name = "coverage" -version = "4.5.4" -description = "Code coverage measurement for Python" category = "dev" +description = "Code coverage measurement for Python" +name = "coverage" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*, <4" +version = "4.5.4" [[package]] -name = "coveralls" -version = "1.11.1" -description = "Show coverage stats online via coveralls.io" category = "dev" +description = "Show coverage stats online via coveralls.io" +name = "coveralls" optional = false python-versions = "*" +version = "1.11.1" [package.dependencies] coverage = ">=3.6,<6.0" @@ -121,93 +126,99 @@ requests = ">=1.0.0" yaml = ["PyYAML (>=3.10,<5.3)"] [[package]] -name = "datadog" -version = "0.34.1" -description = "The Datadog Python library" category = "main" +description = "The Datadog Python library" +name = "datadog" optional = false python-versions = "*" +version = "0.34.1" [package.dependencies] decorator = ">=3.3.2" requests = ">=2.6.0" [[package]] -name = "decorator" -version = "5.0.9" -description = "Decorators for Humans" category = "main" +description = "Decorators for Humans" +name = "decorator" optional = false python-versions = ">=3.5" +version = "5.0.9" [[package]] -name = "distlib" -version = "0.3.2" -description = "Distribution utilities" category = "dev" +description = "Distribution utilities" +name = "distlib" optional = false python-versions = "*" +version = "0.3.2" [[package]] -name = "docopt" -version = "0.6.2" -description = "Pythonic argument parser, that will make you smile" category = "dev" +description = "Pythonic argument parser, that will make you smile" +name = "docopt" optional = false python-versions = "*" +version = "0.6.2" [[package]] -name = "filelock" -version = "3.0.12" -description = "A platform independent file lock." category = "dev" +description = "A platform independent file lock." +name = "filelock" optional = false python-versions = "*" +version = "3.0.12" [[package]] -name = "flake8" -version = "3.9.2" -description = "the modular source code checker: pep8 pyflakes and co" category = "dev" +description = "the modular source code checker: pep8 pyflakes and co" +name = "flake8" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" +version = "3.9.2" [package.dependencies] -importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} mccabe = ">=0.6.0,<0.7.0" pycodestyle = ">=2.7.0,<2.8.0" pyflakes = ">=2.3.0,<2.4.0" +[package.dependencies.importlib-metadata] +python = "<3.8" +version = "*" + [[package]] -name = "gitdb" -version = "4.0.7" -description = "Git Object Database" category = "dev" +description = "Git Object Database" +name = "gitdb" optional = false python-versions = ">=3.4" +version = "4.0.7" [package.dependencies] smmap = ">=3.0.1,<5" [[package]] -name = "gitpython" -version = "3.1.17" -description = "Python Git Library" category = "dev" +description = "Python Git Library" +name = "gitpython" optional = false python-versions = ">=3.5" +version = "3.1.17" [package.dependencies] gitdb = ">=4.0.1,<5" -typing-extensions = {version = ">=3.7.4.0", markers = "python_version < \"3.8\""} + +[package.dependencies.typing-extensions] +python = "<3.8" +version = ">=3.7.4.0" [[package]] -name = "google-api-core" -version = "1.20.1" -description = "Google API client core library" category = "main" +description = "Google API client core library" +name = "google-api-core" optional = false python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*" +version = "1.20.1" [package.dependencies] google-auth = ">=1.14.0,<2.0dev" @@ -215,6 +226,7 @@ googleapis-common-protos = ">=1.6.0,<2.0dev" protobuf = ">=3.12.0" pytz = "*" requests = ">=2.18.0,<3.0.0dev" +setuptools = ">=34.0.0" six = ">=1.10.0" [package.extras] @@ -223,12 +235,12 @@ grpcgcp = ["grpcio-gcp (>=0.2.2)"] grpcio-gcp = ["grpcio-gcp (>=0.2.2)"] [[package]] -name = "google-api-python-client" -version = "1.11.0" -description = "Google API Client Library for Python" category = "main" +description = "Google API Client Library for Python" +name = "google-api-python-client" optional = false python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*" +version = "1.11.0" [package.dependencies] google-api-core = ">=1.18.0,<2dev" @@ -239,31 +251,35 @@ six = ">=1.6.1,<2dev" uritemplate = ">=3.0.0,<4dev" [[package]] -name = "google-auth" -version = "1.30.1" -description = "Google Authentication Library" category = "main" +description = "Google Authentication Library" +name = "google-auth" optional = false python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*" +version = "1.30.1" [package.dependencies] cachetools = ">=2.0.0,<5.0" pyasn1-modules = ">=0.2.1" -rsa = {version = ">=3.1.4,<5", markers = "python_version >= \"3.6\""} +setuptools = ">=40.3.0" six = ">=1.9.0" +[package.dependencies.rsa] +python = ">=3.6" +version = ">=3.1.4,<5" + [package.extras] aiohttp = ["aiohttp (>=3.6.2,<4.0.0dev)"] pyopenssl = ["pyopenssl (>=20.0.0)"] reauth = ["pyu2f (>=0.1.5)"] [[package]] -name = "google-auth-httplib2" -version = "0.0.4" -description = "Google Authentication Library: httplib2 transport" category = "main" +description = "Google Authentication Library: httplib2 transport" +name = "google-auth-httplib2" optional = false python-versions = "*" +version = "0.0.4" [package.dependencies] google-auth = "*" @@ -271,12 +287,12 @@ httplib2 = ">=0.9.1" six = "*" [[package]] -name = "google-auth-oauthlib" -version = "0.4.4" -description = "Google Authentication Library" category = "main" +description = "Google Authentication Library" +name = "google-auth-oauthlib" optional = false python-versions = ">=3.6" +version = "0.4.4" [package.dependencies] google-auth = ">=1.0.0" @@ -286,12 +302,12 @@ requests-oauthlib = ">=0.7.0" tool = ["click (>=6.0.0)"] [[package]] -name = "googleapis-common-protos" -version = "1.53.0" -description = "Common protobufs used in Google APIs" category = "main" +description = "Common protobufs used in Google APIs" +name = "googleapis-common-protos" optional = false python-versions = ">=3.6" +version = "1.53.0" [package.dependencies] protobuf = ">=3.12.0" @@ -300,68 +316,76 @@ protobuf = ">=3.12.0" grpc = ["grpcio (>=1.0.0)"] [[package]] -name = "httplib2" -version = "0.19.1" -description = "A comprehensive HTTP client library." category = "main" +description = "A comprehensive HTTP client library." +name = "httplib2" optional = false python-versions = "*" +version = "0.19.1" [package.dependencies] pyparsing = ">=2.4.2,<3" [[package]] -name = "idna" -version = "2.10" -description = "Internationalized Domain Names in Applications (IDNA)" category = "main" +description = "Internationalized Domain Names in Applications (IDNA)" +name = "idna" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "2.10" [[package]] -name = "importlib-metadata" -version = "4.4.0" -description = "Read metadata from Python packages" category = "dev" +description = "Read metadata from Python packages" +marker = "python_version < \"3.8\"" +name = "importlib-metadata" optional = false python-versions = ">=3.6" +version = "4.4.0" [package.dependencies] -typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} zipp = ">=0.5" +[package.dependencies.typing-extensions] +python = "<3.8" +version = ">=3.6.4" + [package.extras] docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"] [[package]] -name = "importlib-resources" -version = "5.1.4" -description = "Read resources from Python packages" category = "dev" +description = "Read resources from Python packages" +marker = "python_version < \"3.7\"" +name = "importlib-resources" optional = false python-versions = ">=3.6" +version = "5.1.4" [package.dependencies] -zipp = {version = ">=3.1.0", markers = "python_version < \"3.10\""} +[package.dependencies.zipp] +python = "<3.10" +version = ">=3.1.0" [package.extras] docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "pytest-black (>=0.3.7)", "pytest-mypy"] [[package]] -name = "influxdb-client" -version = "1.17.0" -description = "InfluxDB 2.0 Python client library" category = "main" +description = "InfluxDB 2.0 Python client library" +name = "influxdb-client" optional = false python-versions = ">=3.6" +version = "1.17.0" [package.dependencies] certifi = ">=14.05.14" python-dateutil = ">=2.5.3" pytz = ">=2019.1" rx = ">=3.0.1" +setuptools = ">=21.0.0" six = ">=1.10" urllib3 = ">=1.15.1" @@ -371,12 +395,12 @@ extra = ["pandas (>=0.25.3)", "numpy"] test = ["coverage (>=4.0.3)", "nose (>=1.3.7)", "pluggy (>=0.3.1)", "py (>=1.4.31)", "randomize (>=0.13)", "pytest (>=5.0.0)", "httpretty (>=1.0.2)", "psutil (>=5.6.3)"] [[package]] -name = "isort" -version = "4.3.21" -description = "A Python utility / library to sort Python imports." category = "dev" +description = "A Python utility / library to sort Python imports." +name = "isort" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "4.3.21" [package.extras] pipfile = ["pipreqs", "requirementslib"] @@ -385,12 +409,12 @@ requirements = ["pipreqs", "pip-api"] xdg_home = ["appdirs (>=1.4.0)"] [[package]] -name = "jinja2" -version = "3.0.1" -description = "A very fast and expressive template engine." category = "main" +description = "A very fast and expressive template engine." +name = "jinja2" optional = false python-versions = ">=3.6" +version = "3.0.1" [package.dependencies] MarkupSafe = ">=2.0" @@ -399,44 +423,44 @@ MarkupSafe = ">=2.0" i18n = ["Babel (>=2.7)"] [[package]] -name = "lazy-object-proxy" -version = "1.6.0" -description = "A fast and thorough lazy object proxy." category = "dev" +description = "A fast and thorough lazy object proxy." +name = "lazy-object-proxy" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" +version = "1.6.0" [[package]] -name = "markupsafe" -version = "2.0.1" -description = "Safely add untrusted strings to HTML/XML markup." category = "main" +description = "Safely add untrusted strings to HTML/XML markup." +name = "markupsafe" optional = false python-versions = ">=3.6" +version = "2.0.1" [[package]] -name = "mccabe" -version = "0.6.1" -description = "McCabe checker, plugin for flake8" category = "dev" +description = "McCabe checker, plugin for flake8" +name = "mccabe" optional = false python-versions = "*" +version = "0.6.1" [[package]] -name = "more-itertools" -version = "8.8.0" -description = "More routines for operating on iterables, beyond itertools" category = "dev" +description = "More routines for operating on iterables, beyond itertools" +name = "more-itertools" optional = false python-versions = ">=3.5" +version = "8.8.0" [[package]] -name = "mypy" -version = "0.782" -description = "Optional static typing for Python" category = "dev" +description = "Optional static typing for Python" +name = "mypy" optional = false python-versions = ">=3.5" +version = "0.782" [package.dependencies] mypy-extensions = ">=0.4.3,<0.5.0" @@ -447,20 +471,20 @@ typing-extensions = ">=3.7.4" dmypy = ["psutil (>=4.0)"] [[package]] -name = "mypy-extensions" -version = "0.4.3" -description = "Experimental type system extensions for programs checked with the mypy typechecker." category = "dev" +description = "Experimental type system extensions for programs checked with the mypy typechecker." +name = "mypy-extensions" optional = false python-versions = "*" +version = "0.4.3" [[package]] -name = "oauth2client" -version = "4.1.3" -description = "OAuth 2.0 client library" category = "main" +description = "OAuth 2.0 client library" +name = "oauth2client" optional = false python-versions = "*" +version = "4.1.3" [package.dependencies] httplib2 = ">=0.9.1" @@ -470,12 +494,12 @@ rsa = ">=3.1.4" six = ">=1.6.1" [[package]] -name = "oauthlib" -version = "3.1.1" -description = "A generic, spec-compliant, thorough implementation of the OAuth request-signing logic" category = "main" +description = "A generic, spec-compliant, thorough implementation of the OAuth request-signing logic" +name = "oauthlib" optional = false python-versions = ">=3.6" +version = "3.1.1" [package.extras] rsa = ["cryptography (>=3.0.0,<4)"] @@ -483,209 +507,214 @@ signals = ["blinker (>=1.4.0)"] signedtoken = ["cryptography (>=3.0.0,<4)", "pyjwt (>=2.0.0,<3)"] [[package]] -name = "packaging" -version = "20.9" -description = "Core utilities for Python packages" category = "dev" +description = "Core utilities for Python packages" +name = "packaging" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "20.9" [package.dependencies] pyparsing = ">=2.0.2" [[package]] -name = "pbr" -version = "5.6.0" -description = "Python Build Reasonableness" category = "dev" +description = "Python Build Reasonableness" +name = "pbr" optional = false python-versions = ">=2.6" +version = "5.6.0" [[package]] -name = "pluggy" -version = "0.13.1" -description = "plugin and hook calling mechanisms for python" category = "dev" +description = "plugin and hook calling mechanisms for python" +name = "pluggy" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "0.13.1" [package.dependencies] -importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} +[package.dependencies.importlib-metadata] +python = "<3.8" +version = ">=0.12" [package.extras] dev = ["pre-commit", "tox"] [[package]] -name = "prometheus-client" -version = "0.8.0" -description = "Python client for the Prometheus monitoring system." category = "main" +description = "Python client for the Prometheus monitoring system." +name = "prometheus-client" optional = false python-versions = "*" +version = "0.8.0" [package.extras] twisted = ["twisted"] [[package]] -name = "protobuf" -version = "3.17.2" -description = "Protocol Buffers" category = "main" +description = "Protocol Buffers" +name = "protobuf" optional = false python-versions = "*" +version = "3.17.2" [package.dependencies] six = ">=1.9" [[package]] -name = "py" -version = "1.10.0" -description = "library with cross-python path, ini-parsing, io, code, log facilities" category = "dev" +description = "library with cross-python path, ini-parsing, io, code, log facilities" +name = "py" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "1.10.0" [[package]] -name = "pyasn1" -version = "0.4.8" -description = "ASN.1 types and codecs" category = "main" +description = "ASN.1 types and codecs" +name = "pyasn1" optional = false python-versions = "*" +version = "0.4.8" [[package]] -name = "pyasn1-modules" -version = "0.2.8" -description = "A collection of ASN.1-based protocols modules." category = "main" +description = "A collection of ASN.1-based protocols modules." +name = "pyasn1-modules" optional = false python-versions = "*" +version = "0.2.8" [package.dependencies] pyasn1 = ">=0.4.6,<0.5.0" [[package]] -name = "pybluez" -version = "0.22" -description = "Bluetooth Python extension module" category = "main" +description = "Bluetooth Python extension module" +name = "pybluez" optional = false python-versions = "*" +version = "0.22" [package.extras] -ble = ["gattlib (==0.20150805)"] +ble = ["gattlib (0.20150805)"] [[package]] -name = "pycodestyle" -version = "2.7.0" -description = "Python style guide checker" category = "dev" +description = "Python style guide checker" +name = "pycodestyle" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "2.7.0" [[package]] -name = "pyflakes" -version = "2.3.1" -description = "passive checker of Python programs" category = "dev" +description = "passive checker of Python programs" +name = "pyflakes" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "2.3.1" [[package]] -name = "pylint" -version = "2.8.3" -description = "python code static checker" category = "dev" +description = "python code static checker" +name = "pylint" optional = false python-versions = "~=3.6" +version = "2.8.3" [package.dependencies] astroid = "2.5.6" -colorama = {version = "*", markers = "sys_platform == \"win32\""} +colorama = "*" isort = ">=4.2.5,<6" mccabe = ">=0.6,<0.7" toml = ">=0.7.1" [[package]] -name = "pyparsing" -version = "2.4.7" -description = "Python parsing module" category = "main" +description = "Python parsing module" +name = "pyparsing" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +version = "2.4.7" [[package]] -name = "pytest" -version = "5.4.3" -description = "pytest: simple powerful testing with Python" category = "dev" +description = "pytest: simple powerful testing with Python" +name = "pytest" optional = false python-versions = ">=3.5" +version = "5.4.3" [package.dependencies] -atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""} +atomicwrites = ">=1.0" attrs = ">=17.4.0" -colorama = {version = "*", markers = "sys_platform == \"win32\""} -importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} +colorama = "*" more-itertools = ">=4.0.0" packaging = "*" pluggy = ">=0.12,<1.0" py = ">=1.5.0" wcwidth = "*" +[package.dependencies.importlib-metadata] +python = "<3.8" +version = ">=0.12" + [package.extras] -checkqa-mypy = ["mypy (==v0.761)"] +checkqa-mypy = ["mypy (v0.761)"] testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] [[package]] -name = "pytest-cov" -version = "2.10.1" -description = "Pytest plugin for measuring coverage." category = "dev" +description = "Pytest plugin for measuring coverage." +name = "pytest-cov" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "2.10.1" [package.dependencies] coverage = ">=4.4" pytest = ">=4.6" [package.extras] -testing = ["fields", "hunter", "process-tests (==2.0.2)", "six", "pytest-xdist", "virtualenv"] +testing = ["fields", "hunter", "process-tests (2.0.2)", "six", "pytest-xdist", "virtualenv"] [[package]] -name = "python-dateutil" -version = "2.8.1" -description = "Extensions to the standard Python datetime module" category = "main" +description = "Extensions to the standard Python datetime module" +name = "python-dateutil" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" +version = "2.8.1" [package.dependencies] six = ">=1.5" [[package]] -name = "pytz" -version = "2021.1" -description = "World timezone definitions, modern and historical" category = "main" +description = "World timezone definitions, modern and historical" +name = "pytz" optional = false python-versions = "*" +version = "2021.1" [[package]] -name = "pyyaml" -version = "5.4.1" -description = "YAML parser and emitter for Python" category = "dev" +description = "YAML parser and emitter for Python" +name = "pyyaml" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" +version = "5.4.1" [[package]] -name = "requests" -version = "2.25.1" -description = "Python HTTP for Humans." category = "main" +description = "Python HTTP for Humans." +name = "requests" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "2.25.1" [package.dependencies] certifi = ">=2017.4.17" @@ -695,90 +724,92 @@ urllib3 = ">=1.21.1,<1.27" [package.extras] security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"] -socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"] +socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7)", "win-inet-pton"] [[package]] -name = "requests-oauthlib" -version = "1.3.0" -description = "OAuthlib authentication support for Requests." category = "main" +description = "OAuthlib authentication support for Requests." +name = "requests-oauthlib" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "1.3.0" [package.dependencies] oauthlib = ">=3.0.0" requests = ">=2.0.0" [package.extras] -rsa = ["oauthlib[signedtoken] (>=3.0.0)"] +rsa = ["oauthlib (>=3.0.0)"] [[package]] -name = "rsa" -version = "4.7.2" -description = "Pure-Python RSA implementation" category = "main" +description = "Pure-Python RSA implementation" +name = "rsa" optional = false python-versions = ">=3.5, <4" +version = "4.7.2" [package.dependencies] pyasn1 = ">=0.1.3" [[package]] -name = "rx" -version = "3.2.0" -description = "Reactive Extensions (Rx) for Python" category = "main" +description = "Reactive Extensions (Rx) for Python" +name = "rx" optional = false python-versions = ">=3.6.0" +version = "3.2.0" [[package]] -name = "six" -version = "1.16.0" -description = "Python 2 and 3 compatibility utilities" category = "main" +description = "Python 2 and 3 compatibility utilities" +name = "six" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +version = "1.16.0" [[package]] -name = "smmap" -version = "4.0.0" -description = "A pure Python implementation of a sliding window memory map manager" category = "dev" +description = "A pure Python implementation of a sliding window memory map manager" +name = "smmap" optional = false python-versions = ">=3.5" +version = "4.0.0" [[package]] -name = "stevedore" -version = "3.3.0" -description = "Manage dynamic plugins for Python applications" category = "dev" +description = "Manage dynamic plugins for Python applications" +name = "stevedore" optional = false python-versions = ">=3.6" +version = "3.3.0" [package.dependencies] -importlib-metadata = {version = ">=1.7.0", markers = "python_version < \"3.8\""} pbr = ">=2.0.0,<2.1.0 || >2.1.0" +[package.dependencies.importlib-metadata] +python = "<3.8" +version = ">=1.7.0" + [[package]] -name = "toml" -version = "0.10.2" -description = "Python Library for Tom's Obvious, Minimal Language" category = "dev" +description = "Python Library for Tom's Obvious, Minimal Language" +name = "toml" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +version = "0.10.2" [[package]] -name = "tox" -version = "3.23.1" -description = "tox is a generic virtualenv management and test command line tool" category = "dev" +description = "tox is a generic virtualenv management and test command line tool" +name = "tox" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" +version = "3.23.1" [package.dependencies] -colorama = {version = ">=0.4.1", markers = "platform_system == \"Windows\""} +colorama = ">=0.4.1" filelock = ">=3.0.0" -importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} packaging = ">=14" pluggy = ">=0.12.0" py = ">=1.4.17" @@ -786,99 +817,110 @@ six = ">=1.14.0" toml = ">=0.9.4" virtualenv = ">=16.0.0,<20.0.0 || >20.0.0,<20.0.1 || >20.0.1,<20.0.2 || >20.0.2,<20.0.3 || >20.0.3,<20.0.4 || >20.0.4,<20.0.5 || >20.0.5,<20.0.6 || >20.0.6,<20.0.7 || >20.0.7" +[package.dependencies.importlib-metadata] +python = "<3.8" +version = ">=0.12" + [package.extras] docs = ["pygments-github-lexers (>=0.0.5)", "sphinx (>=2.0.0)", "sphinxcontrib-autoprogram (>=0.1.5)", "towncrier (>=18.5.0)"] testing = ["flaky (>=3.4.0)", "freezegun (>=0.3.11)", "psutil (>=5.6.1)", "pytest (>=4.0.0)", "pytest-cov (>=2.5.1)", "pytest-mock (>=1.10.0)", "pytest-randomly (>=1.0.0)", "pytest-xdist (>=1.22.2)", "pathlib2 (>=2.3.3)"] [[package]] -name = "typed-ast" -version = "1.4.3" -description = "a fork of Python 2 and 3 ast modules with type comment support" category = "dev" +description = "a fork of Python 2 and 3 ast modules with type comment support" +name = "typed-ast" optional = false python-versions = "*" +version = "1.4.3" [[package]] -name = "typing-extensions" -version = "3.10.0.0" -description = "Backported and Experimental Type Hints for Python 3.5+" category = "dev" +description = "Backported and Experimental Type Hints for Python 3.5+" +name = "typing-extensions" optional = false python-versions = "*" +version = "3.10.0.0" [[package]] -name = "uritemplate" -version = "3.0.1" -description = "URI templates" category = "main" +description = "URI templates" +name = "uritemplate" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "3.0.1" [[package]] -name = "urllib3" -version = "1.26.5" -description = "HTTP library with thread-safe connection pooling, file post, and more." category = "main" +description = "HTTP library with thread-safe connection pooling, file post, and more." +name = "urllib3" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4" +version = "1.26.5" [package.extras] brotli = ["brotlipy (>=0.6.0)"] secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"] -socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] +socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7,<2.0)"] [[package]] -name = "virtualenv" -version = "20.4.7" -description = "Virtual Python Environment builder" category = "dev" +description = "Virtual Python Environment builder" +name = "virtualenv" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7" +version = "20.4.7" [package.dependencies] appdirs = ">=1.4.3,<2" distlib = ">=0.3.1,<1" filelock = ">=3.0.0,<4" -importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} -importlib-resources = {version = ">=1.0", markers = "python_version < \"3.7\""} six = ">=1.9.0,<2" +[package.dependencies.importlib-metadata] +python = "<3.8" +version = ">=0.12" + +[package.dependencies.importlib-resources] +python = "<3.7" +version = ">=1.0" + [package.extras] docs = ["proselint (>=0.10.2)", "sphinx (>=3)", "sphinx-argparse (>=0.2.5)", "sphinx-rtd-theme (>=0.4.3)", "towncrier (>=19.9.0rc1)"] testing = ["coverage (>=4)", "coverage-enable-subprocess (>=1)", "flaky (>=3)", "pytest (>=4)", "pytest-env (>=0.6.2)", "pytest-freezegun (>=0.4.1)", "pytest-mock (>=2)", "pytest-randomly (>=1)", "pytest-timeout (>=1)", "packaging (>=20.0)", "xonsh (>=0.9.16)"] [[package]] -name = "wcwidth" -version = "0.2.5" -description = "Measures the displayed width of unicode strings in a terminal" category = "dev" +description = "Measures the displayed width of unicode strings in a terminal" +name = "wcwidth" optional = false python-versions = "*" +version = "0.2.5" [[package]] -name = "wrapt" -version = "1.12.1" -description = "Module for decorators, wrappers and monkey patching." category = "dev" +description = "Module for decorators, wrappers and monkey patching." +name = "wrapt" optional = false python-versions = "*" +version = "1.12.1" [[package]] -name = "zipp" -version = "3.4.1" -description = "Backport of pathlib-compatible object wrapper for zip files" category = "dev" +description = "Backport of pathlib-compatible object wrapper for zip files" +marker = "python_version < \"3.8\"" +name = "zipp" optional = false python-versions = ">=3.6" +version = "3.4.1" [package.extras] docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "pytest-enabler", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"] [metadata] -lock-version = "1.1" -python-versions = ">=3.6,<4" content-hash = "6786034df2de7931812f952f04f42633907cfc527c918145547379b12820bfec" +lock-version = "1.0" +python-versions = ">=3.6,<4" [metadata.files] appdirs = [ @@ -1260,26 +1302,18 @@ pyyaml = [ {file = "PyYAML-5.4.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:bb4191dfc9306777bc594117aee052446b3fa88737cd13b7188d0e7aa8162185"}, {file = "PyYAML-5.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:6c78645d400265a062508ae399b60b8c167bf003db364ecb26dcab2bda048253"}, {file = "PyYAML-5.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:4e0583d24c881e14342eaf4ec5fbc97f934b999a6828693a99157fde912540cc"}, - {file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:72a01f726a9c7851ca9bfad6fd09ca4e090a023c00945ea05ba1638c09dc3347"}, - {file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_s390x.whl", hash = "sha256:895f61ef02e8fed38159bb70f7e100e00f471eae2bc838cd0f4ebb21e28f8541"}, {file = "PyYAML-5.4.1-cp36-cp36m-win32.whl", hash = "sha256:3bd0e463264cf257d1ffd2e40223b197271046d09dadf73a0fe82b9c1fc385a5"}, {file = "PyYAML-5.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:e4fac90784481d221a8e4b1162afa7c47ed953be40d31ab4629ae917510051df"}, {file = "PyYAML-5.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:5accb17103e43963b80e6f837831f38d314a0495500067cb25afab2e8d7a4018"}, {file = "PyYAML-5.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e1d4970ea66be07ae37a3c2e48b5ec63f7ba6804bdddfdbd3cfd954d25a82e63"}, - {file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:cb333c16912324fd5f769fff6bc5de372e9e7a202247b48870bc251ed40239aa"}, - {file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_s390x.whl", hash = "sha256:fe69978f3f768926cfa37b867e3843918e012cf83f680806599ddce33c2c68b0"}, {file = "PyYAML-5.4.1-cp37-cp37m-win32.whl", hash = "sha256:dd5de0646207f053eb0d6c74ae45ba98c3395a571a2891858e87df7c9b9bd51b"}, {file = "PyYAML-5.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:08682f6b72c722394747bddaf0aa62277e02557c0fd1c42cb853016a38f8dedf"}, {file = "PyYAML-5.4.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d2d9808ea7b4af864f35ea216be506ecec180628aced0704e34aca0b040ffe46"}, {file = "PyYAML-5.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:8c1be557ee92a20f184922c7b6424e8ab6691788e6d86137c5d93c1a6ec1b8fb"}, - {file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:fd7f6999a8070df521b6384004ef42833b9bd62cfee11a09bda1079b4b704247"}, - {file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_s390x.whl", hash = "sha256:bfb51918d4ff3d77c1c856a9699f8492c612cde32fd3bcd344af9be34999bfdc"}, {file = "PyYAML-5.4.1-cp38-cp38-win32.whl", hash = "sha256:fa5ae20527d8e831e8230cbffd9f8fe952815b2b7dae6ffec25318803a7528fc"}, {file = "PyYAML-5.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:0f5f5786c0e09baddcd8b4b45f20a7b5d61a7e7e99846e3c799b05c7c53fa696"}, {file = "PyYAML-5.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:294db365efa064d00b8d1ef65d8ea2c3426ac366c0c4368d930bf1c5fb497f77"}, {file = "PyYAML-5.4.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:74c1485f7707cf707a7aef42ef6322b8f97921bd89be2ab6317fd782c2d53183"}, - {file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:d483ad4e639292c90170eb6f7783ad19490e7a8defb3e46f97dfe4bacae89122"}, - {file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_s390x.whl", hash = "sha256:fdc842473cd33f45ff6bce46aea678a54e3d21f1b61a7750ce3c498eedfe25d6"}, {file = "PyYAML-5.4.1-cp39-cp39-win32.whl", hash = "sha256:49d4cdd9065b9b6e206d0595fee27a96b5dd22618e7520c33204a4a3239d5b10"}, {file = "PyYAML-5.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:c20cfa2d49991c8b4147af39859b167664f2ad4561704ee74c1de03318e898db"}, {file = "PyYAML-5.4.1.tar.gz", hash = "sha256:607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e"}, diff --git a/tests/test_tilty.py b/tests/test_tilty.py index fb918a3..319cdee 100644 --- a/tests/test_tilty.py +++ b/tests/test_tilty.py @@ -36,13 +36,45 @@ def test_parse_config_invalid_emitter(): -@mock.patch('tilty.blescan.get_events', return_value=[{'uuid': 'foo', 'major': 2, 'minor': 1}]) # noqa +@mock.patch('tilty.blescan.get_events', return_value=[{'mac': '00:0a:95:9d:68:16', 'uuid': 'a495bb30c5b14b44b5121370f02d74de', 'major': 2, 'minor': 1}]) # noqa def test_scan_for_tilt_data( bt_events, ): t = tilt_device.TiltDevice() - t.scan_for_tilt_data() + tilt_data = t.scan_for_tilt_data() bt_events.assert_called() + assert tilt_data == [{ + 'color': 'Black', + 'gravity': 0.001, + 'temp': 2.0, + 'mac': '00:0a:95:9d:68:16', + 'timestamp': mock.ANY, + 'uuid': 'a495bb30c5b14b44b5121370f02d74de' + }] + + assert t.scan_for_tilt_data( + temperature_offset=10, + gravity_offset=-0.05, + ) == [{ + 'color': 'Black', + 'gravity': -0.049, + 'temp': 12, + 'mac': '00:0a:95:9d:68:16', + 'timestamp': mock.ANY, + 'uuid': 'a495bb30c5b14b44b5121370f02d74de' + }] + + assert t.scan_for_tilt_data( + temperature_offset=-5, + gravity_offset=0.001, + ) == [{ + 'color': 'Black', + 'gravity': 0.002, + 'temp': -3.0, + 'mac': '00:0a:95:9d:68:16', + 'timestamp': mock.ANY, + 'uuid': 'a495bb30c5b14b44b5121370f02d74de' + }] @mock.patch('tilty.emitters.sqlite.sqlite3') diff --git a/tilty/cli.py b/tilty/cli.py index 6c5c8b0..c84f3b0 100644 --- a/tilty/cli.py +++ b/tilty/cli.py @@ -15,6 +15,7 @@ import click from tilty import tilt_device +from tilty.common import safe_get_key from tilty.exceptions import ConfigurationFileNotFoundException from tilty.tilty import LOGGER, emit, parse_config @@ -38,15 +39,24 @@ def terminate_process( sys.exit() -def scan_and_emit(device: tilt_device.TiltDevice, emitters: List[dict]): +def scan_and_emit( + device: tilt_device.TiltDevice, + emitters: List[dict], + gravity_offset: float, + temperature_offset: float +): """ Scans and emits the data via the loaded emitters. Args: device (TiltDevice): The bluetooth device to operate on. emitters ([dict]): The emitters to use. """ + LOGGER.debug('Starting device scan') - tilt_data = device.scan_for_tilt_data() + tilt_data = device.scan_for_tilt_data( + gravity_offset=gravity_offset, + temperature_offset=temperature_offset, + ) if tilt_data: for event in tilt_data: LOGGER.debug('tilt data retrieved') @@ -70,11 +80,21 @@ def scan_and_emit_thread( """ emitters = parse_config(config) click.echo('Scanning for Tilt data...') - scan_and_emit(device, emitters) + + gravity_offset = float( + safe_get_key(CONFIG, 'general', {}).get('gravity_offset', '0') + ) + LOGGER.debug('Gravity offset: %f', gravity_offset) + temperature_offset = float( + safe_get_key(CONFIG, 'general', {}).get('temperature_offset', '0') + ) + LOGGER.debug('Temperature offset: %f', temperature_offset) + + scan_and_emit(device, emitters, gravity_offset, temperature_offset) while keep_running: LOGGER.debug('Scanning for Tilt data...') try: - scan_and_emit(device, emitters) + scan_and_emit(device, emitters, gravity_offset, temperature_offset) except Exception as exception: # pylint: disable=broad-except LOGGER.error( "%s\n%s", diff --git a/tilty/common.py b/tilty/common.py index c9098d7..cc26d39 100644 --- a/tilty/common.py +++ b/tilty/common.py @@ -4,7 +4,7 @@ from typing import Any, Optional -def safe_get_key(config: dict, key: str, fallback: Optional[Any] = None): +def safe_get_key(config, key: str, fallback: Optional[Any] = None): """ Class to safely pull key from config or a fallback value Args: diff --git a/tilty/tilt_device.py b/tilty/tilt_device.py index 7934ff6..68aa203 100644 --- a/tilty/tilt_device.py +++ b/tilty/tilt_device.py @@ -38,7 +38,11 @@ def stop(self) -> None: LOGGER.debug('Stopping device socket') blescan.hci_disable_le_scan(self.sock) - def scan_for_tilt_data(self) -> list: + def scan_for_tilt_data( + self, + temperature_offset: float = 0, + gravity_offset: float = 0 + ) -> list: """ scan for tilt and return data if found """ data = [] @@ -51,8 +55,8 @@ def scan_for_tilt_data(self) -> list: if color: data.append({ 'color': color, - 'gravity': float(beacon['minor']/1000), - 'temp': beacon['major'], + 'gravity': (float(beacon['minor']/1000) + gravity_offset), + 'temp': float(beacon['major'] + temperature_offset), 'mac': beacon['mac'], 'timestamp': datetime.now().isoformat(), 'uuid': uuid