Skip to content

Update _create_data for dict. metadata #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 26, 2021
Merged
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
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,19 @@ 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
uses: actions/upload-artifact@v2
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
Expand Down
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 12 additions & 14 deletions adafruit_io/adafruit_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -457,16 +455,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):
Expand Down