Skip to content

Commit

Permalink
Merge pull request #64 from brentru/createdata
Browse files Browse the repository at this point in the history
Update _create_data for dict. metadata
  • Loading branch information
ladyada committed Feb 26, 2021
2 parents b95428e + 0e30d79 commit 092d9c8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
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

0 comments on commit 092d9c8

Please sign in to comment.