From f74d0cd57423ec87bf5e626568874bcbdfc18394 Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 25 Feb 2021 15:30:20 -0500 Subject: [PATCH 1/3] refactor create_data --- adafruit_io/adafruit_io.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/adafruit_io/adafruit_io.py b/adafruit_io/adafruit_io.py index cfc62aa..161120d 100755 --- a/adafruit_io/adafruit_io.py +++ b/adafruit_io/adafruit_io.py @@ -457,16 +457,16 @@ def _create_headers(io_headers): @staticmethod def _create_data(data, metadata): - """Creates JSON data payload""" - if metadata is not None: - return { - "value": data, - "lat": metadata["lat"], - "lon": metadata["lon"], - "ele": metadata["ele"], - "created_at": metadata["created_at"], - } - return {"value": data} + """Returns a data payload as expected by the Adafruit IO HTTP API + :param data: Payload value. + :param dict metadata: Payload metadata. + + """ + payload = {"value": data} + if metadata: # metadata is expected as a dict, append key/vals + for k, val in metadata.items(): + payload[k] = val + return payload @staticmethod def _handle_error(response): From 49e54bf82f765d55ddaf5c6397981f919c0c9461 Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 25 Feb 2021 15:46:06 -0500 Subject: [PATCH 2/3] eval time sub. differently for pylint --- adafruit_io/adafruit_io.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/adafruit_io/adafruit_io.py b/adafruit_io/adafruit_io.py index 161120d..bb8d1f4 100755 --- a/adafruit_io/adafruit_io.py +++ b/adafruit_io/adafruit_io.py @@ -282,12 +282,10 @@ def subscribe_to_time(self, time_type): Information about these topics can be found on the Adafruit IO MQTT API Docs.: https://io.adafruit.com/api/docs/mqtt.html#time-topics """ - if "seconds" or "millis" or "hours" in time_type: - self._client.subscribe("time/" + time_type) - elif time_type == "iso": + if time_type == "iso": self._client.subscribe("time/ISO-8601") else: - raise TypeError("Invalid time feed type specified") + self._client.subscribe("time/" + time_type) def unsubscribe(self, feed_key=None, group_key=None, shared_user=None): """Unsubscribes from an Adafruit IO feed or group. From 0e30d791a2a2232849c946ebb50530aff14a7bfb Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 25 Feb 2021 16:01:23 -0500 Subject: [PATCH 3/3] patch in new precommit, workflow build from cookiecutter --- .github/workflows/build.yml | 9 +++++---- .pre-commit-config.yaml | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59baa53..fd99fee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,10 +50,6 @@ jobs: - name: Pre-commit hooks run: | pre-commit run --all-files - - name: PyLint - run: | - pylint $( find . -path './adafruit*.py' ) - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - name: Archive bundles @@ -61,7 +57,12 @@ jobs: with: name: bundles path: ${{ github.workspace }}/bundles/ + - name: Check For docs folder + id: need-docs + run: | + echo ::set-output name=docs::$( find . -wholename './docs' ) - name: Build docs + if: contains(steps.need-docs.outputs.docs, 'docs') working-directory: docs run: sphinx-build -E -W -b html . _build/html - name: Check For setup.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 07f886c..354c761 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,18 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace +- repo: https://github.com/pycqa/pylint + rev: pylint-2.7.1 + hooks: + - id: pylint + name: pylint (library code) + types: [python] + exclude: "^(docs/|examples/|setup.py$)" +- repo: local + hooks: + - id: pylint_examples + name: pylint (examples code) + description: Run pylint rules on "examples/*.py" files + entry: /usr/bin/env bash -c + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + language: system