Skip to content
Open
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
16 changes: 11 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,24 @@ Due to PyBluez limitations, this library will currently only work on Linux and W

Dependencies
____________
- `Python 2.7.x`_
- `Python 2.7.x or Python 3.3+`_
- PyBluez_

Installation
____________
First, install PyBluez using the appropriate link or command for your OS:

**Windows**
Download and install `PyBluez for Python 2.7`_
Download and install `PyBluez for Python 2.7`_, or `PyBlues on Windows with Python 3.3+`_

**Ubuntu/Debian**::

sudo apt-get install python-bluez
For Python 2, there's a system package:
sudo apt install python-bluez

For Python 3, install dependencies, and use pip:
sudo apt install libbluetooth-dev
sudo pip install pybluez

**Fedora**::

Expand All @@ -77,6 +82,7 @@ When I try to pip install plugable-btaps I get a compilation error:

.. _Plugable PS-BTAPS1 Bluetooth Home Automation Switch: http://plugable.com/products/ps-btaps1/
.. _PyBluez: https://code.google.com/p/pybluez/
.. _Python 2.7.x: https://www.python.org/
.. _Python 2.7.x or Python 3.3+: https://www.python.org/
.. _PyBluez for Python 2.7: https://code.google.com/p/pybluez/downloads/detail?name=PyBluez-0.20.win32-py2.7.exe
.. _GitHub Wiki: https://github.com/bernieplug/plugable-btaps/wiki/libbtaps-Documentation-and-Examples
.. _PyBluez on Windows for Python 3.3+: https://stackoverflow.com/questions/48821917/downloading-and-installing-pybluez-for-a-64-bit-windows-10-pc
.. _GitHub Wiki: https://github.com/bernieplug/plugable-btaps/wiki/libbtaps-Documentation-and-Examples
114 changes: 63 additions & 51 deletions btaps/btaps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
from __future__ import absolute_import, division, unicode_literals, print_function, nested_scopes

import sys
import libbtaps
from . import libbtaps
import time

try:
# Py2.7
# noinspection PyShadowingBuiltins,PyUnresolvedReferences
input = raw_input
# noinspection PyShadowingBuiltins,PyUnresolvedReferences
range = xrange
# noinspection PyShadowingBuiltins,PyUnresolvedReferences
str = unicode
# noinspection PyUnresolvedReferences,PyCompatibility
from future_builtins import *
except (ImportError, NameError):
# Py3.3+
pass


def get_line():
line = raw_input('> ')
Expand All @@ -14,27 +30,23 @@ def get_line():
def print_dic_sorted(dic):
order = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
for key in sorted(dic, key=order.index):
print key, ":", dic[key], "",
print(key, ":", dic[key], "", end='')

print ""
print("")


# Given a list of BTApsTimer objects, print them in a legible format
# Given a list of BTApsTimer objects, print(them in a legible format)
def print_timers(timer_list):
print "Timers:"
print("Timers:")
for timer in timer_list:
print "\tName: ", timer.name
print "\tID: ", timer.timer_id
print "\tOn: ",
if timer.on == 1:
print "On"
else:
print "Off"
print "\tDays: ",
print("\tName: ", timer.name)
print("\tID: ", timer.timer_id)
print("\tOn: ", "On" if timer.on == 1 else 'Off')
print("\tDays: ", end='')
print_dic_sorted(timer.repeat_days)
print "\tStart Time: ", timer.start_time
print "\tEnd Time: ", timer.end_time
print ""
print("\tStart Time: ", timer.start_time)
print("\tEnd Time: ", timer.end_time)
print("")


# Turn switch on/off
Expand All @@ -50,40 +62,40 @@ def print_status(btaps):
name = btaps.get_dev_name()
status = btaps.get_switch_state()

print "Name: " + name
print "Switch: ",
print("Name: " + name)
print("Switch: ", end='')
if status[0] == 1:
print "On"
print("On")
else:
print "Off"
print("Off")

return status


# Simple interactive command line prompts for creating new timer
def create_timer(btaps, timer_list):
print "Creating New Timer:"
print "Name: "
print("Creating New Timer:")
print("Name: ")
name = get_line()
new_timer = libbtaps.BTapsTimer(len(timer_list) + 1, name)

print "Enter Start and End Time in 24-hour format (ex: 23:54)"
print "Start Time: "
print("Enter Start and End Time in 24-hour format (ex: 23:54)")
print("Start Time: ")
start = get_line()
start = time.strptime(start, "%H:%M")
new_timer.set_start_time(start[3], start[4])

print "End Time: "
print("End Time: ")
end = get_line()
end = time.strptime(end, "%H:%M")
new_timer.set_end_time(end[3], end[4])

print "Repeat Timer?"
print("Repeat Timer?")
repeat = get_line().lower()
if repeat == "y":
day_list = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
for i, day in enumerate(day_list):
print day, "?"
print(day, "?")
repeat = get_line().lower()
if repeat == 'y':
day_list[i] = True
Expand All @@ -93,7 +105,7 @@ def create_timer(btaps, timer_list):
new_timer.set_repeat_days(day_list[0], day_list[1], day_list[2], day_list[3],
day_list[4], day_list[5], day_list[6])

print "Enable New Timer? Y/N"
print("Enable New Timer? Y/N")
enable = get_line().lower()
if enable == 'y':
new_timer.toggle_on()
Expand All @@ -103,36 +115,36 @@ def create_timer(btaps, timer_list):

# Simple interactive command line prompts for modifying a timer
def modify_timer(btaps, timer_list):
print "Enter Timer ID for the timer you wish to modify:"
print("Enter Timer ID for the timer you wish to modify:")
id = get_line()
mod_timer = timer_list[int(id)-1]

print "Enter values you wish to change, leave blank to keep original value"
print "Name: ", mod_timer.name
print("Enter values you wish to change, leave blank to keep original value")
print("Name: ", mod_timer.name)
name = get_line()
if name != '':
mod_timer.set_name(name)

print "Enter Start and End Time in 24-hour format (ex: 23:54)"
print "Start Time: ",
print("Enter Start and End Time in 24-hour format (ex: 23:54)")
print("Start Time: ", end='')
print_dic_sorted(mod_timer.start_time)
start = get_line()
if start != '':
start = time.strptime(start, "%H:%M")
mod_timer.set_start_time(start[3], start[4])

print "End Time: ", mod_timer.end_time
print("End Time: ", mod_timer.end_time)
end = get_line()
if end != '':
end = time.strptime(end, "%H:%M")
mod_timer.set_end_time(end[3], end[4])

print "Repeat Timer?", mod_timer.repeat_days
print("Repeat Timer?", mod_timer.repeat_days)
repeat = get_line().lower()
if repeat == "y":
day_list = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
for i, day in enumerate(day_list):
print day, "?"
print(day, "?")
repeat = get_line().lower()
if repeat == 'y':
day_list[i] = True
Expand All @@ -142,7 +154,7 @@ def modify_timer(btaps, timer_list):
mod_timer.set_repeat_days(day_list[0], day_list[1], day_list[2], day_list[3],
day_list[4], day_list[5], day_list[6])

print "Enable Timer? Y/N"
print("Enable Timer? Y/N")
enable = get_line().lower()
if (enable == 'y') and (mod_timer.on != 1):
mod_timer.toggle_on()
Expand All @@ -153,10 +165,10 @@ def modify_timer(btaps, timer_list):


def main(argv):
print " === Plugable PS-BTAPS CLI v0.8 ==="
print(" === Plugable PS-BTAPS CLI v0.8 ===")
if len(argv) != 2:
print "USAGE: python", sys.argv[0], "[Bluetooth address]"
print "EXAMPLE: python", sys.argv[0], "00:00:FF:FF:00:00"
print("USAGE: python", sys.argv[0], "[Bluetooth address]")
print("EXAMPLE: python", sys.argv[0], "00:00:FF:FF:00:00")
sys.exit(0)

# Establish connection to BTAPS
Expand All @@ -169,14 +181,14 @@ def main(argv):
print_timers(status[1])

while True:
print "Select a function..."
print "1. (T)oggle Switch"
print "2. (C)reate Timer"
print "3. (M)odify Timer"
print "4. (D)elete Timer"
print "5. (S)et Device Name"
print "6. (G)et Switch Status (Name, On/Off, Timers)"
print "7. E(x)it"
print("Select a function...")
print("1. (T)oggle Switch")
print("2. (C)reate Timer")
print("3. (M)odify Timer")
print("4. (D)elete Timer")
print("5. (S)et Device Name")
print("6. (G)et Switch Status (Name, On/Off, Timers)")
print("7. E(x)it")

try:
function = get_line().lower()
Expand All @@ -189,11 +201,11 @@ def main(argv):
modify_timer(btaps, status[1])
elif function in ['4', 'd']:
print_timers(status[1])
print "Enter Timer ID to delete:"
print("Enter Timer ID to delete:")
timer_id = get_line()
btaps.delete_timer(timer_id)
elif function in ['5', 's']:
print "New Device Name:"
print("New Device Name:")
name = get_line()
btaps.set_dev_name(name)
elif function in ['6', 'g']:
Expand All @@ -210,4 +222,4 @@ def main(argv):
btaps.disconnect()

if __name__ == '__main__':
main(sys.argv)
main(sys.argv)
Loading