Skip to content

Instantly share code, notes, and snippets.

@DeastinY
Created November 11, 2015 12:25
Show Gist options
  • Save DeastinY/882bf2b23fb771a2cedc to your computer and use it in GitHub Desktop.
Save DeastinY/882bf2b23fb771a2cedc to your computer and use it in GitHub Desktop.
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