Merge pull request #819 from rhooper/phue-deconz

Add support for deCONZ (Raspbee-GW hue-like API)
This commit is contained in:
Paulus Schoutsen 2016-01-01 22:21:48 -08:00
commit a698bc477d

View file

@ -121,10 +121,17 @@ def setup_bridge(host, hass, add_devices_callback):
new_lights = [] new_lights = []
api_name = api.get('config').get('name')
if api_name == 'RaspBee-GW':
bridge_type = 'deconz'
else:
bridge_type = 'hue'
for light_id, info in api_states.items(): for light_id, info in api_states.items():
if light_id not in lights: if light_id not in lights:
lights[light_id] = HueLight(int(light_id), info, lights[light_id] = HueLight(int(light_id), info,
bridge, update_lights) bridge, update_lights,
bridge_type=bridge_type)
new_lights.append(lights[light_id]) new_lights.append(lights[light_id])
else: else:
lights[light_id].info = info lights[light_id].info = info
@ -163,11 +170,14 @@ def request_configuration(host, hass, add_devices_callback):
class HueLight(Light): class HueLight(Light):
""" Represents a Hue light """ """ Represents a Hue light """
def __init__(self, light_id, info, bridge, update_lights): # pylint: disable=too-many-arguments
def __init__(self, light_id, info, bridge, update_lights,
bridge_type='hue'):
self.light_id = light_id self.light_id = light_id
self.info = info self.info = info
self.bridge = bridge self.bridge = bridge
self.update_lights = update_lights self.update_lights = update_lights
self.bridge_type = bridge_type
@property @property
def unique_id(self): def unique_id(self):
@ -227,7 +237,7 @@ class HueLight(Light):
command['alert'] = 'lselect' command['alert'] = 'lselect'
elif flash == FLASH_SHORT: elif flash == FLASH_SHORT:
command['alert'] = 'select' command['alert'] = 'select'
else: elif self.bridge_type == 'hue':
command['alert'] = 'none' command['alert'] = 'none'
effect = kwargs.get(ATTR_EFFECT) effect = kwargs.get(ATTR_EFFECT)
@ -237,7 +247,7 @@ class HueLight(Light):
elif effect == EFFECT_RANDOM: elif effect == EFFECT_RANDOM:
command['hue'] = random.randrange(0, 65535) command['hue'] = random.randrange(0, 65535)
command['sat'] = random.randrange(150, 254) command['sat'] = random.randrange(150, 254)
else: elif self.bridge_type == 'hue':
command['effect'] = 'none' command['effect'] = 'none'
self.bridge.set_light(self.light_id, command) self.bridge.set_light(self.light_id, command)