Skip to content

Commit

Permalink
Put config schema inside the main module. flyte#13
Browse files Browse the repository at this point in the history
  • Loading branch information
flyte committed Jul 26, 2017
1 parent 68a36e0 commit 4006f32
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 6 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# http://packages.python.org/distribute/setuptools.html#including-data-files
include *requirements.txt
recursive-include . *.yml
119 changes: 119 additions & 0 deletions pi_mqtt_gpio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import yaml

CONFIG_SCHEMA = yaml.load("""
mqtt:
type: dict
required: yes
schema:
host:
type: string
empty: no
required: no
default: localhost
port:
type: integer
min: 1
max: 65535
required: no
default: 1883
user:
type: string
required: no
default: ""
password:
type: string
required: no
default: ""
topic_prefix:
type: string
required: no
default: ""
coerce: rstrip_slash
protocol:
type: string
required: no
empty: no
coerce: tostring
default: "3.1.1"
allowed:
- "3.1"
- "3.1.1"
gpio_modules:
type: list
required: yes
schema:
type: dict
allow_unknown: yes
schema:
name:
type: string
required: yes
empty: no
module:
type: string
required: yes
empty: no
digital_inputs:
type: list
required: no
default: []
schema:
type: dict
schema:
name:
type: string
required: yes
empty: no
module:
type: string
required: yes
empty: no
pin:
type: integer
required: yes
min: 0
on_payload:
type: string
required: yes
empty: no
off_payload:
type: string
required: yes
empty: no
pullup:
type: boolean
required: no
default: no
pulldown:
type: boolean
required: no
default: no
digital_outputs:
type: list
required: no
default: []
schema:
type: dict
schema:
name:
type: string
required: yes
module:
type: string
required: yes
pin:
type: integer
required: yes
min: 0
on_payload:
type: string
required: no
empty: no
off_payload:
type: string
required: no
empty: no
""")
6 changes: 1 addition & 5 deletions pi_mqtt_gpio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import paho.mqtt.client as mqtt
import cerberus

from pi_mqtt_gpio import CONFIG_SCHEMA
from pi_mqtt_gpio.modules import PinPullup, PinDirection, BASE_SCHEMA
from pi_mqtt_gpio.scheduler import Scheduler, Task

Expand All @@ -30,11 +31,6 @@
OUTPUT_TOPIC = "output"
INPUT_TOPIC = "input2"

# @TODO: Don't load this at module level
THIS_DIR = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(THIS_DIR, "..", "config.schema.yml")) as schema:
CONFIG_SCHEMA = yaml.load(schema)

_LOG = logging.getLogger(__name__)
_LOG.addHandler(logging.StreamHandler())
_LOG.setLevel(logging.DEBUG)
Expand Down

0 comments on commit 4006f32

Please sign in to comment.