Merge pull request #1567 from jaharkes/wemo-color-lights
Update to new pywemo bridge APIpull/1528/merge
commit
bb5c80b8f5
|
@ -8,8 +8,10 @@ import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
import homeassistant.util as util
|
import homeassistant.util as util
|
||||||
|
import homeassistant.util.color as color_util
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
Light, ATTR_BRIGHTNESS)
|
Light, ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_RGB_COLOR, ATTR_TRANSITION,
|
||||||
|
ATTR_XY_COLOR)
|
||||||
|
|
||||||
DEPENDENCIES = ['wemo']
|
DEPENDENCIES = ['wemo']
|
||||||
|
|
||||||
|
@ -39,17 +41,14 @@ def setup_bridge(bridge, add_devices_callback):
|
||||||
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
|
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
|
||||||
def update_lights():
|
def update_lights():
|
||||||
"""Update the WeMo led objects with latest info from the bridge."""
|
"""Update the WeMo led objects with latest info from the bridge."""
|
||||||
bridge.bridge_get_lights()
|
bridge.bridge_update()
|
||||||
|
|
||||||
new_lights = []
|
new_lights = []
|
||||||
|
|
||||||
for light_id, info in bridge.Lights.items():
|
for light_id, device in bridge.Lights.items():
|
||||||
if light_id not in lights:
|
if light_id not in lights:
|
||||||
lights[light_id] = WemoLight(bridge, light_id, info,
|
lights[light_id] = WemoLight(device, update_lights)
|
||||||
update_lights)
|
|
||||||
new_lights.append(lights[light_id])
|
new_lights.append(lights[light_id])
|
||||||
else:
|
|
||||||
lights[light_id].info = info
|
|
||||||
|
|
||||||
if new_lights:
|
if new_lights:
|
||||||
add_devices_callback(new_lights)
|
add_devices_callback(new_lights)
|
||||||
|
@ -60,44 +59,73 @@ def setup_bridge(bridge, add_devices_callback):
|
||||||
class WemoLight(Light):
|
class WemoLight(Light):
|
||||||
"""Representation of a WeMo light."""
|
"""Representation of a WeMo light."""
|
||||||
|
|
||||||
def __init__(self, bridge, light_id, info, update_lights):
|
def __init__(self, device, update_lights):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
self.bridge = bridge
|
self.light_id = device.name
|
||||||
self.light_id = light_id
|
self.device = device
|
||||||
self.info = info
|
|
||||||
self.update_lights = update_lights
|
self.update_lights = update_lights
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return the ID of this light."""
|
"""Return the ID of this light."""
|
||||||
deviceid = self.bridge.light_get_id(self.info)
|
deviceid = self.device.uniqueID
|
||||||
return "{}.{}".format(self.__class__, deviceid)
|
return "{}.{}".format(self.__class__, deviceid)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the light."""
|
"""Return the name of the light."""
|
||||||
return self.bridge.light_name(self.info)
|
return self.device.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
"""Return the brightness of this light between 0..255."""
|
"""Return the brightness of this light between 0..255."""
|
||||||
state = self.bridge.light_get_state(self.info)
|
return self.device.state.get('level', 255)
|
||||||
return int(state['dim'])
|
|
||||||
|
@property
|
||||||
|
def xy_color(self):
|
||||||
|
"""Return the XY color values of this light."""
|
||||||
|
return self.device.state.get('color_xy')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def color_temp(self):
|
||||||
|
"""Return the color temperature of this light in mireds."""
|
||||||
|
return self.device.state.get('temperature_mireds')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""True if device is on."""
|
"""True if device is on."""
|
||||||
state = self.bridge.light_get_state(self.info)
|
return self.device.state['onoff'] != 0
|
||||||
return int(state['state'])
|
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn the light on."""
|
"""Turn the light on."""
|
||||||
dim = kwargs.get(ATTR_BRIGHTNESS, self.brightness)
|
transitiontime = int(kwargs.get(ATTR_TRANSITION, 0))
|
||||||
self.bridge.light_set_state(self.info, state=1, dim=dim)
|
|
||||||
|
if ATTR_XY_COLOR in kwargs:
|
||||||
|
xycolor = kwargs[ATTR_XY_COLOR]
|
||||||
|
elif ATTR_RGB_COLOR in kwargs:
|
||||||
|
xycolor = color_util.color_RGB_to_xy(
|
||||||
|
*(int(val) for val in kwargs[ATTR_RGB_COLOR]))
|
||||||
|
else:
|
||||||
|
xycolor = None
|
||||||
|
|
||||||
|
if xycolor is not None:
|
||||||
|
self.device.set_color(xycolor, transition=transitiontime)
|
||||||
|
|
||||||
|
if ATTR_COLOR_TEMP in kwargs:
|
||||||
|
colortemp = kwargs[ATTR_COLOR_TEMP]
|
||||||
|
self.device.set_temperature(mireds=colortemp,
|
||||||
|
transition=transitiontime)
|
||||||
|
|
||||||
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
|
brightness = kwargs.get(ATTR_BRIGHTNESS, self.brightness or 255)
|
||||||
|
self.device.turn_on(level=brightness, transition=transitiontime)
|
||||||
|
else:
|
||||||
|
self.device.turn_on(transition=transitiontime)
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Turn the light off."""
|
"""Turn the light off."""
|
||||||
self.bridge.light_set_state(self.info, state=0, dim=0)
|
transitiontime = int(kwargs.get(ATTR_TRANSITION, 0))
|
||||||
|
self.device.turn_off(transition=transitiontime)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Synchronize state with bridge."""
|
"""Synchronize state with bridge."""
|
||||||
|
|
|
@ -9,7 +9,7 @@ import logging
|
||||||
from homeassistant.components import discovery
|
from homeassistant.components import discovery
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
|
|
||||||
REQUIREMENTS = ['pywemo==0.3.16']
|
REQUIREMENTS = ['pywemo==0.3.17']
|
||||||
|
|
||||||
DOMAIN = 'wemo'
|
DOMAIN = 'wemo'
|
||||||
DISCOVER_LIGHTS = 'wemo.light'
|
DISCOVER_LIGHTS = 'wemo.light'
|
||||||
|
|
|
@ -222,7 +222,7 @@ pyuserinput==0.1.9
|
||||||
pyvera==0.2.8
|
pyvera==0.2.8
|
||||||
|
|
||||||
# homeassistant.components.wemo
|
# homeassistant.components.wemo
|
||||||
pywemo==0.3.16
|
pywemo==0.3.17
|
||||||
|
|
||||||
# homeassistant.components.thermostat.radiotherm
|
# homeassistant.components.thermostat.radiotherm
|
||||||
radiotherm==1.2
|
radiotherm==1.2
|
||||||
|
|
Loading…
Reference in New Issue