Created
November 11, 2015 12:25
-
-
Save DeastinY/882bf2b23fb771a2cedc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
import os | |
import phue | |
import json | |
import logging | |
Lamp = namedtuple('Lamp', 'name state') | |
# setup lamps on first startup | |
bridge = phue.Bridge("192.168.0.10") # TODO: Bad hardcoded string | |
bridge.connect() | |
lamps = bridge.get_light_objects('name') | |
""" | |
Returns a list of named tuples containing name and state | |
""" | |
def getlamps(): | |
return sorted([Lamp(str(l), lamps[l].on) for l in lamps]) | |
""" | |
Sets a lamp to a defined state | |
""" | |
def setlamp(id, state): | |
try: | |
lamps[id].on = state | |
except Exception as e: | |
logging.exception(e) | |
""" | |
Returns all scenes read in from json | |
""" | |
def getscenes(): | |
try: | |
path = os.path.abspath(os.path.join(os.path.abspath(__file__), os.pardir, os.pardir, 'scenes.json')) | |
with open(path, 'r') as infile: | |
scenes = json.loads(infile.read()) | |
return scenes | |
except Exception as e: | |
logging.exception(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment