Skip to content

Commit

Permalink
modified to work with Home Assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
steve28 committed Apr 29, 2018
1 parent 4622fae commit 927f7df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
17 changes: 10 additions & 7 deletions mca66_server.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
# Open the serial port to communicate with the MCA-66
# Exit if it fails.

# Deafults
logfile = open('/tmp/mca66_server.log','w',0)
# Defults
logfile = open('/var/log/mca66_server/server.log','w',0)
sys.stdout = logfile
sys.stderr = logfile




audio = mca66.MCA66('/dev/ttyUSB0')
if audio.open() is False:
print("False!!")
sys.exit()

# define list of commands we handle
Expand All @@ -35,18 +33,20 @@ def GET(self):
class controller:

def GET(self):
print("Received GET")
# we're going to return JSON
web.header('Content-Type', 'application/json')
# Grab the arguements from the URL
user_data = web.input()
print("user_data:",user_data)
#print user_data, commands
# do some input validation
if 'command' in user_data:
command = user_data.command.lower()
if command in get_commands:
print("Processing...",command)
zone = int(user_data.zone) if 'zone' in user_data else None

# Process the commnads
if command == "status":
if zone:
Expand All @@ -68,6 +68,9 @@ def POST(self):
# we're going to return JSON
web.header('Content-Type', 'application/json')

print("Received POST")
print("user_data:",user_data)
print("data:", web.data())
if 'command' in user_data:
command = user_data.command.lower()
if command in post_commands:
Expand Down Expand Up @@ -121,4 +124,4 @@ def POST(self):
if __name__ == "__main__":

app = web.application(urls, globals())
app.run()
app.run()
10 changes: 5 additions & 5 deletions mca66_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Put a short description of the service here
# Description: Put a long description of the service here
# Short-Description: MCA-66 Server
# Description: MCA-66 Server
### END INIT INFO

# Change the next 3 lines to suit where you install your script and what you want to call it
DIR=/usr/local/bin/myservice
DIR=/usr/local/bin/mca66_server
DAEMON=$DIR/mca66_server.py
DAEMON_NAME=mca66_server

# Add any command line options for your daemon here
DAEMON_OPTS="-l"
DAEMON_OPTS=""

# This next line determines what user the script runs as.
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
Expand All @@ -29,7 +29,7 @@ PIDFILE=/var/run/$DAEMON_NAME.pid

do_start () {
log_daemon_msg "Starting system $DAEMON_NAME daemon"
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON -- $DAEMON_OPTS
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --chdir $DIR --startas $DAEMON -- $DAEMON_OPTS
log_end_msg $?
}
do_stop () {
Expand Down

0 comments on commit 927f7df

Please sign in to comment.