Skip to content

Commit

Permalink
Auto detect and pickle error check
Browse files Browse the repository at this point in the history
  • Loading branch information
kusti8 committed Apr 15, 2017
1 parent 1d1e8a2 commit 38adbf9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion hue_plus/hue_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def error(self, message):
def get_port(self):
ports = []
for port in list_ports.comports():
if 'MCP2200' in port[1]:
if 'MCP2200' in port[1] or 'USB Serial Device' in port[1]:
ports.append(port[0])
if ports:
return ports[0]
Expand Down
18 changes: 13 additions & 5 deletions hue_plus/previous.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ def write(line1, line2, profiles):
global path
pickle.dump(([line1, line2], profiles), open(path, 'wb'))

def read():
global path
out = pickle.load(open(path, 'rb'))
if type(out) is tuple:
return out
else:
return (out, {})


def get_colors(channel, changer):
"""Get the previous colors stored so channel 2 stays the same"""
data, profiles = pickle.load(open(path, 'rb'))
data, profiles = read()
if channel == 0:
#print(changer)
# Changer[0] is list of commands for first channel
Expand All @@ -60,24 +68,24 @@ def get_colors(channel, changer):
return [data[0], changer[0]]

def add_profile(name):
data, profiles = pickle.load(open(path, 'rb'))
data, profiles = read()
profiles[name] = data
write(data[0], data[1], profiles)

def list_profile():
data, profiles = pickle.load(open(path, 'rb'))
data, profiles = read()
return(list(profiles))

def rm_profile(name):
data, profiles = pickle.load(open(path, 'rb'))
data, profiles = read()
try:
del profiles[name]
except:
pass
write(data[0], data[1], profiles)

def apply_profile(name):
data, profiles = pickle.load(open(path, 'rb'))
data, profiles = read()
try:
return profiles[name]
except:
Expand Down

0 comments on commit 38adbf9

Please sign in to comment.