Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
tanasegabriel authored Dec 21, 2019
1 parent 0d9b71b commit 8da785e
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 76 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ venv.bak/

# mypy
.mypy_cache/

# PyCharm
.idea/
9 changes: 5 additions & 4 deletions hooks/build
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

echo "[***] Build hook running"
docker build --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--cache-from $IMAGE_NAME \
-t $IMAGE_NAME .

docker build --build-arg "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--build-arg VCS_REF="$(git rev-parse --short HEAD)" \
--cache-from "$IMAGE_NAME" \
-t "$IMAGE_NAME" .
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ six==1.12.0
stevedore==1.31.0
swagger-ui-bundle==0.0.5
tavern==0.30.3
urllib3==1.25.3
urllib3==1.25.7
wcwidth==0.1.7
Werkzeug==0.15.6
zipp==0.6.0
1 change: 1 addition & 0 deletions resolver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import sys

from sense_wrappers import sensors, led_matrix, joystick

if "emulation" in sys.argv:
Expand Down
4 changes: 3 additions & 1 deletion sense_wrappers/joystick.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3


class Joystick(object):
def __init__(self, sense):
self.__sense = sense
Expand All @@ -8,5 +9,6 @@ def get_events(self):
events = self.__sense.stick.get_events()[:1000]
return [self.__event_dict(event) for event in events]

def __event_dict(self, event):
@staticmethod
def __event_dict(event):
return dict(event._asdict())
6 changes: 3 additions & 3 deletions sense_wrappers/led_matrix.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3


class LedMatrix(object):
def __init__(self, sense):
self.__sense = sense
Expand Down Expand Up @@ -40,14 +41,13 @@ def show_letter(self, body):
self.__sense.show_letter(
body["letter"],
body.get("text_colour", [255, 255, 255]),
body.get("back_colour", [0,0,0])
body.get("back_colour", [0, 0, 0])
)

def show_message(self, body):
self.__sense.show_message(
body["message"],
body.get("scroll_speed", 0.1),
body.get("text_colour", [255, 255, 255]),
body.get("back_colour", [0,0,0])
body.get("back_colour", [0, 0, 0])
)

6 changes: 4 additions & 2 deletions sense_wrappers/sensors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3


class Sensors(object):
def __init__(self, sense):
self.__sense = sense
Expand Down Expand Up @@ -43,9 +44,10 @@ def accelerometer(self):
def get(self, name):
return getattr(self, name)()

def __u_v_dict(self, u, v):
@staticmethod
def __u_v_dict(u, v):
if isinstance(v, int):
v = float(v)
elif isinstance(v, dict):
v = { key:float(value) for key,value in v.items() }
v = {key: float(value) for key, value in v.items()}
return {"unit": u, "value": v}
2 changes: 2 additions & 0 deletions senseapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
application = connexion.App(__name__, specification_dir='./')
application.add_api('specification.yml')


@application.route('/')
def home():
return redirect('senseapi/v1/ui/')


if __name__ == '__main__':
application.run(host='0.0.0.0')
78 changes: 39 additions & 39 deletions specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ info:
email: [email protected]

servers:
- url: /senseapi/v1
- url: /senseapi/v1

paths:
/sensors/{name}:
get:
operationId: resolver.sensors.get
tags:
- Sensors
- Sensors
summary: Individual sensor values
parameters:
- name: name
in: path
description: Name of the sensor
required: true
schema:
$ref: '#/components/schemas/sensor'
- name: name
in: path
description: Name of the sensor
required: true
schema:
$ref: '#/components/schemas/sensor'
responses:
200:
description: OK
Expand All @@ -34,15 +34,15 @@ paths:
get:
operationId: resolver.led.get_settings
tags:
- LED Matrix
- LED Matrix
summary: Get the customizable settings
responses:
200:
description: OK
post:
operationId: resolver.led.update_settings
tags:
- LED Matrix
- LED Matrix
summary: Update settings
requestBody:
content:
Expand All @@ -63,21 +63,21 @@ paths:
get:
operationId: resolver.led.get_pixel
tags:
- LED Matrix
- LED Matrix
summary: Get the colour of a specific pixel
parameters:
- name: x
in: query
description: Position of the pixel on the X xis
required: true
schema:
$ref: '#/components/schemas/pixel_position'
- name: y
in: query
description: Position of the pixel on the Y xis
required: true
schema:
$ref: '#/components/schemas/pixel_position'
- name: x
in: query
description: Position of the pixel on the X xis
required: true
schema:
$ref: '#/components/schemas/pixel_position'
- name: y
in: query
description: Position of the pixel on the Y xis
required: true
schema:
$ref: '#/components/schemas/pixel_position'
responses:
200:
description: OK
Expand All @@ -86,7 +86,7 @@ paths:
post:
operationId: resolver.led.update_pixel
tags:
- LED Matrix
- LED Matrix
summary: Update the colour of a specific pixel
requestBody:
content:
Expand All @@ -108,30 +108,30 @@ paths:
get:
operationId: resolver.led.get_pixels
tags:
- LED Matrix
- LED Matrix
summary: Get the colour of all pixels
responses:
200:
description: OK
post:
operationId: resolver.led.update_pixels
tags:
- LED Matrix
- LED Matrix
summary: Update the colour of all pixels
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/pixels'
example: [
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
[0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255],
]
responses:
200:
Expand All @@ -141,7 +141,7 @@ paths:
post:
operationId: resolver.led.clear
tags:
- LED Matrix
- LED Matrix
summary: Clear the pixels
requestBody:
content:
Expand All @@ -160,7 +160,7 @@ paths:
post:
operationId: resolver.led.flip
tags:
- LED Matrix
- LED Matrix
summary: Flip the pixels horizontally or vertically
requestBody:
content:
Expand All @@ -176,7 +176,7 @@ paths:
post:
operationId: resolver.led.show_letter
tags:
- LED Matrix
- LED Matrix
summary: Display one letter
requestBody:
content:
Expand All @@ -196,7 +196,7 @@ paths:
post:
operationId: resolver.led.show_message
tags:
- LED Matrix
- LED Matrix
summary: Scroll a text message
requestBody:
content:
Expand All @@ -216,7 +216,7 @@ paths:
get:
operationId: resolver.joystick.get_events
tags:
- Joystick
- Joystick
summary: Get joystick events since last call (max 1000)
responses:
200:
Expand Down
50 changes: 25 additions & 25 deletions tests/tavern_senseapi_v1/test_led_matrix.tavern.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ stages:
response:
status_code: 200
body: [
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
]


Expand All @@ -219,14 +219,14 @@ stages:
url: http://127.0.0.1:8000/senseapi/v1/led/pixels
method: POST
json: [
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
]
response:
status_code: 200
Expand All @@ -236,14 +236,14 @@ stages:
url: http://127.0.0.1:8000/senseapi/v1/led/pixels
method: POST
json: [
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
[256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256],
]
response:
status_code: 400
Expand Down Expand Up @@ -452,7 +452,7 @@ stages:
- 128
- 128
- 128
message: TEST
message: TEST
scroll_speed: 0.05
response:
status_code: 200
Expand Down
3 changes: 2 additions & 1 deletion tests/test_senseapi.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python3
import atexit
import pytest
import subprocess

import pytest

sense_emulator = subprocess.Popen(["sense_play", "tests/sense_fixture.hat"])
atexit.register(sense_emulator.terminate)

Expand Down

0 comments on commit 8da785e

Please sign in to comment.