Skip to content

Commit 092d9c8

Browse files
authored
Merge pull request #64 from brentru/createdata
Update _create_data for dict. metadata
2 parents b95428e + 0e30d79 commit 092d9c8

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@ jobs:
5050
- name: Pre-commit hooks
5151
run: |
5252
pre-commit run --all-files
53-
- name: PyLint
54-
run: |
55-
pylint $( find . -path './adafruit*.py' )
56-
([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" ))
5753
- name: Build assets
5854
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
5955
- name: Archive bundles
6056
uses: actions/upload-artifact@v2
6157
with:
6258
name: bundles
6359
path: ${{ github.workspace }}/bundles/
60+
- name: Check For docs folder
61+
id: need-docs
62+
run: |
63+
echo ::set-output name=docs::$( find . -wholename './docs' )
6464
- name: Build docs
65+
if: contains(steps.need-docs.outputs.docs, 'docs')
6566
working-directory: docs
6667
run: sphinx-build -E -W -b html . _build/html
6768
- name: Check For setup.py

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,18 @@ repos:
1717
- id: check-yaml
1818
- id: end-of-file-fixer
1919
- id: trailing-whitespace
20+
- repo: https://github.com/pycqa/pylint
21+
rev: pylint-2.7.1
22+
hooks:
23+
- id: pylint
24+
name: pylint (library code)
25+
types: [python]
26+
exclude: "^(docs/|examples/|setup.py$)"
27+
- repo: local
28+
hooks:
29+
- id: pylint_examples
30+
name: pylint (examples code)
31+
description: Run pylint rules on "examples/*.py" files
32+
entry: /usr/bin/env bash -c
33+
args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)']
34+
language: system

adafruit_io/adafruit_io.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,10 @@ def subscribe_to_time(self, time_type):
282282
Information about these topics can be found on the Adafruit IO MQTT API Docs.:
283283
https://io.adafruit.com/api/docs/mqtt.html#time-topics
284284
"""
285-
if "seconds" or "millis" or "hours" in time_type:
286-
self._client.subscribe("time/" + time_type)
287-
elif time_type == "iso":
285+
if time_type == "iso":
288286
self._client.subscribe("time/ISO-8601")
289287
else:
290-
raise TypeError("Invalid time feed type specified")
288+
self._client.subscribe("time/" + time_type)
291289

292290
def unsubscribe(self, feed_key=None, group_key=None, shared_user=None):
293291
"""Unsubscribes from an Adafruit IO feed or group.
@@ -457,16 +455,16 @@ def _create_headers(io_headers):
457455

458456
@staticmethod
459457
def _create_data(data, metadata):
460-
"""Creates JSON data payload"""
461-
if metadata is not None:
462-
return {
463-
"value": data,
464-
"lat": metadata["lat"],
465-
"lon": metadata["lon"],
466-
"ele": metadata["ele"],
467-
"created_at": metadata["created_at"],
468-
}
469-
return {"value": data}
458+
"""Returns a data payload as expected by the Adafruit IO HTTP API
459+
:param data: Payload value.
460+
:param dict metadata: Payload metadata.
461+
462+
"""
463+
payload = {"value": data}
464+
if metadata: # metadata is expected as a dict, append key/vals
465+
for k, val in metadata.items():
466+
payload[k] = val
467+
return payload
470468

471469
@staticmethod
472470
def _handle_error(response):

0 commit comments

Comments
 (0)