Skip to content
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

Migrate CI to GitHub Actions #275

Merged
merged 4 commits into from
Sep 3, 2020
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
7 changes: 7 additions & 0 deletions .github/dependaboy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
4 changes: 4 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
template: |
## What's Changed
$CHANGES
19 changes: 19 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Release Drafter

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
# config-name: my-config.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Run Tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r requirements_test.txt
- name: Lint with flake8
run: |
flake8 pytradfri
- name: Check formatting with black
run: |
black pytradfri examples tests --check
2 changes: 0 additions & 2 deletions .hound.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

40 changes: 25 additions & 15 deletions examples/debug_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Hack to allow relative import above top level package
import sys
import os

folder = os.path.dirname(os.path.abspath(__file__)) # noqa
sys.path.insert(0, os.path.normpath("%s/.." % folder)) # noqa

Expand All @@ -26,20 +27,28 @@
import uuid
import argparse

CONFIG_FILE = 'tradfri_standalone_psk.conf'
CONFIG_FILE = "tradfri_standalone_psk.conf"


parser = argparse.ArgumentParser()
parser.add_argument('host', metavar='IP', type=str,
help='IP Address of your Tradfri gateway')
parser.add_argument('-K', '--key', dest='key', required=False,
help='Security code found on your Tradfri gateway')
parser.add_argument(
"host", metavar="IP", type=str, help="IP Address of your Tradfri gateway"
)
parser.add_argument(
"-K",
"--key",
dest="key",
required=False,
help="Security code found on your Tradfri gateway",
)
args = parser.parse_args()


if args.host not in load_json(CONFIG_FILE) and args.key is None:
print("Please provide the 'Security Code' on the back of your "
"Tradfri gateway:", end=" ")
print(
"Please provide the 'Security Code' on the back of your " "Tradfri gateway:",
end=" ",
)
key = input().strip()
if len(key) != 16:
raise PytradfriError("Invalid 'Security Code' provided.")
Expand All @@ -50,24 +59,25 @@
conf = load_json(CONFIG_FILE)

try:
identity = conf[args.host].get('identity')
psk = conf[args.host].get('key')
identity = conf[args.host].get("identity")
psk = conf[args.host].get("key")
api_factory = APIFactory(host=args.host, psk_id=identity, psk=psk)
except KeyError:
identity = uuid.uuid4().hex
api_factory = APIFactory(host=args.host, psk_id=identity)

try:
psk = api_factory.generate_psk(args.key)
print('Generated PSK: ', psk)
print("Generated PSK: ", psk)

conf[args.host] = {'identity': identity,
'key': psk}
conf[args.host] = {"identity": identity, "key": psk}
save_json(CONFIG_FILE, conf)
except AttributeError:
raise PytradfriError("Please provide the 'Security Code' on the "
"back of your Tradfri gateway using the "
"-K flag.")
raise PytradfriError(
"Please provide the 'Security Code' on the "
"back of your Tradfri gateway using the "
"-K flag."
)

api = api_factory.request

Expand Down
51 changes: 28 additions & 23 deletions examples/example_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Hack to allow relative import above top level package
import sys
import os

folder = os.path.dirname(os.path.abspath(__file__)) # noqa
sys.path.insert(0, os.path.normpath("%s/.." % folder)) # noqa

Expand All @@ -27,20 +28,24 @@
import uuid
import argparse

CONFIG_FILE = 'tradfri_standalone_psk.conf'
CONFIG_FILE = "tradfri_standalone_psk.conf"


parser = argparse.ArgumentParser()
parser.add_argument('host', metavar='IP', type=str,
help='IP Address of your Tradfri gateway')
parser.add_argument('-K', '--key', dest='key', required=False,
help='Key found on your Tradfri gateway')
parser.add_argument(
"host", metavar="IP", type=str, help="IP Address of your Tradfri gateway"
)
parser.add_argument(
"-K", "--key", dest="key", required=False, help="Key found on your Tradfri gateway"
)
args = parser.parse_args()


if args.host not in load_json(CONFIG_FILE) and args.key is None:
print("Please provide the 'Security Code' on the back of your "
"Tradfri gateway:", end=" ")
print(
"Please provide the 'Security Code' on the back of your " "Tradfri gateway:",
end=" ",
)
key = input().strip()
if len(key) != 16:
raise PytradfriError("Invalid 'Security Code' provided.")
Expand All @@ -54,25 +59,25 @@ async def run():
conf = load_json(CONFIG_FILE)

try:
identity = conf[args.host].get('identity')
psk = conf[args.host].get('key')
api_factory = await APIFactory.init(host=args.host, psk_id=identity,
psk=psk)
identity = conf[args.host].get("identity")
psk = conf[args.host].get("key")
api_factory = await APIFactory.init(host=args.host, psk_id=identity, psk=psk)
except KeyError:
identity = uuid.uuid4().hex
api_factory = await APIFactory.init(host=args.host, psk_id=identity)

try:
psk = await api_factory.generate_psk(args.key)
print('Generated PSK: ', psk)
print("Generated PSK: ", psk)

conf[args.host] = {'identity': identity,
'key': psk}
conf[args.host] = {"identity": identity, "key": psk}
save_json(CONFIG_FILE, conf)
except AttributeError:
raise PytradfriError("Please provide the 'Security Code' on the "
"back of your Tradfri gateway using the "
"-K flag.")
raise PytradfriError(
"Please provide the 'Security Code' on the "
"back of your Tradfri gateway using the "
"-K flag."
)

api = api_factory.request

Expand All @@ -99,11 +104,12 @@ def observe_callback(updated_device):
print("Received message for: %s" % light)

def observe_err_callback(err):
print('observe error:', err)
print("observe error:", err)

for light in lights:
observe_command = light.observe(observe_callback, observe_err_callback,
duration=120)
observe_command = light.observe(
observe_callback, observe_err_callback, duration=120
)
# Start observation as a second task on the loop.
asyncio.ensure_future(api(observe_command))
# Yield to allow observing to start.
Expand All @@ -125,7 +131,7 @@ def observe_err_callback(err):

# Example 5: Change color of the light
# f5faf6 = cold | f1e0b5 = normal | efd275 = warm
color_command = light.light_control.set_hex_color('efd275')
color_command = light.light_control.set_hex_color("efd275")
await api(color_command)

# Get all blinds
Expand Down Expand Up @@ -153,8 +159,7 @@ def observe_err_callback(err):
print(tasks[0].task_control.tasks[0].transition_time)

# Example 7: Set the dimmer stop value to 30 for light#1 in task#1
dim_command_2 = tasks[0].start_action.devices[0].item_controller\
.set_dimmer(30)
dim_command_2 = tasks[0].start_action.devices[0].item_controller.set_dimmer(30)
await api(dim_command_2)

print("Waiting for observation to end (2 mins)")
Expand Down
55 changes: 34 additions & 21 deletions examples/example_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# Hack to allow relative import above top level package
import sys
import os

folder = os.path.dirname(os.path.abspath(__file__)) # noqa
sys.path.insert(0, os.path.normpath("%s/.." % folder)) # noqa

Expand All @@ -43,20 +44,24 @@
import uuid
import argparse

CONFIG_FILE = 'tradfri_standalone_psk.conf'
CONFIG_FILE = "tradfri_standalone_psk.conf"


parser = argparse.ArgumentParser()
parser.add_argument('host', metavar='IP', type=str,
help='IP Address of your Tradfri gateway')
parser.add_argument('-K', '--key', dest='key', required=False,
help='Key found on your Tradfri gateway')
parser.add_argument(
"host", metavar="IP", type=str, help="IP Address of your Tradfri gateway"
)
parser.add_argument(
"-K", "--key", dest="key", required=False, help="Key found on your Tradfri gateway"
)
args = parser.parse_args()


if args.host not in load_json(CONFIG_FILE) and args.key is None:
print("Please provide the 'Security Code' on the back of your "
"Tradfri gateway:", end=" ")
print(
"Please provide the 'Security Code' on the back of your " "Tradfri gateway:",
end=" ",
)
key = input().strip()
if len(key) != 16:
raise PytradfriError("Invalid 'Security Code' provided.")
Expand All @@ -70,25 +75,25 @@ async def run():
conf = load_json(CONFIG_FILE)

try:
identity = conf[args.host].get('identity')
psk = conf[args.host].get('key')
api_factory = await APIFactory.init(host=args.host, psk_id=identity,
psk=psk)
identity = conf[args.host].get("identity")
psk = conf[args.host].get("key")
api_factory = await APIFactory.init(host=args.host, psk_id=identity, psk=psk)
except KeyError:
identity = uuid.uuid4().hex
api_factory = await APIFactory.init(host=args.host, psk_id=identity)

try:
psk = await api_factory.generate_psk(args.key)
print('Generated PSK: ', psk)
print("Generated PSK: ", psk)

conf[args.host] = {'identity': identity,
'key': psk}
conf[args.host] = {"identity": identity, "key": psk}
save_json(CONFIG_FILE, conf)
except AttributeError:
raise PytradfriError("Please provide the 'Security Code' on the "
"back of your Tradfri gateway using the "
"-K flag.")
raise PytradfriError(
"Please provide the 'Security Code' on the "
"back of your Tradfri gateway using the "
"-K flag."
)

api = api_factory.request

Expand All @@ -103,8 +108,12 @@ async def run():
rgb = (0, 0, 102)

# Convert RGB to XYZ using a D50 illuminant.
xyz = convert_color(sRGBColor(rgb[0], rgb[1], rgb[2]), XYZColor,
observer='2', target_illuminant='d65')
xyz = convert_color(
sRGBColor(rgb[0], rgb[1], rgb[2]),
XYZColor,
observer="2",
target_illuminant="d65",
)
xy = int(xyz.xyz_x), int(xyz.xyz_y)

light = None
Expand All @@ -126,8 +135,12 @@ async def run():
# Normalize Z
Z = int(light.light_control.lights[0].dimmer / 254 * 65535)
xyZ = xy + (Z,)
rgb = convert_color(XYZColor(xyZ[0], xyZ[1], xyZ[2]), sRGBColor,
observer='2', target_illuminant='d65')
rgb = convert_color(
XYZColor(xyZ[0], xyZ[1], xyZ[2]),
sRGBColor,
observer="2",
target_illuminant="d65",
)
rgb = (int(rgb.rgb_r), int(rgb.rgb_g), int(rgb.rgb_b))
print(rgb)

Expand Down
Loading