Merge branch 'pep257-light' into dev

This commit is contained in:
Fabian Affolter 2016-03-08 08:11:12 +01:00
commit db6212dae3
19 changed files with 234 additions and 274 deletions

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides functionality to interact with lights. Provides functionality to interact with lights.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
@ -30,26 +28,26 @@ ENTITY_ID_ALL_LIGHTS = group.ENTITY_ID_FORMAT.format('all_lights')
ENTITY_ID_FORMAT = DOMAIN + ".{}" ENTITY_ID_FORMAT = DOMAIN + ".{}"
# integer that represents transition time in seconds to make change # Integer that represents transition time in seconds to make change.
ATTR_TRANSITION = "transition" ATTR_TRANSITION = "transition"
# lists holding color values # Lists holding color values
ATTR_RGB_COLOR = "rgb_color" ATTR_RGB_COLOR = "rgb_color"
ATTR_XY_COLOR = "xy_color" ATTR_XY_COLOR = "xy_color"
ATTR_COLOR_TEMP = "color_temp" ATTR_COLOR_TEMP = "color_temp"
# int with value 0 .. 255 representing brightness of the light # int with value 0 .. 255 representing brightness of the light.
ATTR_BRIGHTNESS = "brightness" ATTR_BRIGHTNESS = "brightness"
# String representing a profile (built-in ones or external defined) # String representing a profile (built-in ones or external defined).
ATTR_PROFILE = "profile" ATTR_PROFILE = "profile"
# If the light should flash, can be FLASH_SHORT or FLASH_LONG # If the light should flash, can be FLASH_SHORT or FLASH_LONG.
ATTR_FLASH = "flash" ATTR_FLASH = "flash"
FLASH_SHORT = "short" FLASH_SHORT = "short"
FLASH_LONG = "long" FLASH_LONG = "long"
# Apply an effect to the light, can be EFFECT_COLORLOOP # Apply an effect to the light, can be EFFECT_COLORLOOP.
ATTR_EFFECT = "effect" ATTR_EFFECT = "effect"
EFFECT_COLORLOOP = "colorloop" EFFECT_COLORLOOP = "colorloop"
EFFECT_RANDOM = "random" EFFECT_RANDOM = "random"
@ -57,7 +55,7 @@ EFFECT_WHITE = "white"
LIGHT_PROFILES_FILE = "light_profiles.csv" LIGHT_PROFILES_FILE = "light_profiles.csv"
# Maps discovered services to their platforms # Maps discovered services to their platforms.
DISCOVERY_PLATFORMS = { DISCOVERY_PLATFORMS = {
wemo.DISCOVER_LIGHTS: 'wemo', wemo.DISCOVER_LIGHTS: 'wemo',
wink.DISCOVER_LIGHTS: 'wink', wink.DISCOVER_LIGHTS: 'wink',
@ -79,9 +77,8 @@ _LOGGER = logging.getLogger(__name__)
def is_on(hass, entity_id=None): def is_on(hass, entity_id=None):
""" Returns if the lights are on based on the statemachine. """ """Return if the lights are on based on the statemachine."""
entity_id = entity_id or ENTITY_ID_ALL_LIGHTS entity_id = entity_id or ENTITY_ID_ALL_LIGHTS
return hass.states.is_state(entity_id, STATE_ON) return hass.states.is_state(entity_id, STATE_ON)
@ -89,7 +86,7 @@ def is_on(hass, entity_id=None):
def turn_on(hass, entity_id=None, transition=None, brightness=None, def turn_on(hass, entity_id=None, transition=None, brightness=None,
rgb_color=None, xy_color=None, color_temp=None, profile=None, rgb_color=None, xy_color=None, color_temp=None, profile=None,
flash=None, effect=None): flash=None, effect=None):
""" Turns all or specified light on. """ """Turn all or specified light on."""
data = { data = {
key: value for key, value in [ key: value for key, value in [
(ATTR_ENTITY_ID, entity_id), (ATTR_ENTITY_ID, entity_id),
@ -108,7 +105,7 @@ def turn_on(hass, entity_id=None, transition=None, brightness=None,
def turn_off(hass, entity_id=None, transition=None): def turn_off(hass, entity_id=None, transition=None):
""" Turns all or specified light off. """ """Turn all or specified light off."""
data = { data = {
key: value for key, value in [ key: value for key, value in [
(ATTR_ENTITY_ID, entity_id), (ATTR_ENTITY_ID, entity_id),
@ -120,7 +117,7 @@ def turn_off(hass, entity_id=None, transition=None):
def toggle(hass, entity_id=None, transition=None): def toggle(hass, entity_id=None, transition=None):
""" Toggles all or specified light. """ """Toggle all or specified light."""
data = { data = {
key: value for key, value in [ key: value for key, value in [
(ATTR_ENTITY_ID, entity_id), (ATTR_ENTITY_ID, entity_id),
@ -133,8 +130,7 @@ def toggle(hass, entity_id=None, transition=None):
# pylint: disable=too-many-branches, too-many-locals, too-many-statements # pylint: disable=too-many-branches, too-many-locals, too-many-statements
def setup(hass, config): def setup(hass, config):
""" Exposes light control via statemachine and services. """ """Expose light control via statemachine and services."""
component = EntityComponent( component = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, DISCOVERY_PLATFORMS, _LOGGER, DOMAIN, hass, SCAN_INTERVAL, DISCOVERY_PLATFORMS,
GROUP_NAME_ALL_LIGHTS) GROUP_NAME_ALL_LIGHTS)
@ -168,7 +164,7 @@ def setup(hass, config):
return False return False
def handle_light_service(service): def handle_light_service(service):
""" Hande a turn light on or off service call. """ """Hande a turn light on or off service call."""
# Get and validate data # Get and validate data
dat = service.data dat = service.data
@ -197,11 +193,11 @@ def setup(hass, config):
light.update_ha_state(True) light.update_ha_state(True)
return return
# Processing extra data for turn light on request # Processing extra data for turn light on request.
# We process the profile first so that we get the desired # We process the profile first so that we get the desired
# behavior that extra service data attributes overwrite # behavior that extra service data attributes overwrite
# profile values # profile values.
profile = profiles.get(dat.get(ATTR_PROFILE)) profile = profiles.get(dat.get(ATTR_PROFILE))
if profile: if profile:
@ -215,10 +211,10 @@ def setup(hass, config):
if ATTR_XY_COLOR in dat: if ATTR_XY_COLOR in dat:
try: try:
# xy_color should be a list containing 2 floats # xy_color should be a list containing 2 floats.
xycolor = dat.get(ATTR_XY_COLOR) xycolor = dat.get(ATTR_XY_COLOR)
# Without this check, a xycolor with value '99' would work # Without this check, a xycolor with value '99' would work.
if not isinstance(xycolor, str): if not isinstance(xycolor, str):
params[ATTR_XY_COLOR] = [float(val) for val in xycolor] params[ATTR_XY_COLOR] = [float(val) for val in xycolor]
@ -263,7 +259,7 @@ def setup(hass, config):
if light.should_poll: if light.should_poll:
light.update_ha_state(True) light.update_ha_state(True)
# Listen for light on and light off service calls # Listen for light on and light off service calls.
descriptions = load_yaml_config_file( descriptions = load_yaml_config_file(
os.path.join(os.path.dirname(__file__), 'services.yaml')) os.path.join(os.path.dirname(__file__), 'services.yaml'))
hass.services.register(DOMAIN, SERVICE_TURN_ON, handle_light_service, hass.services.register(DOMAIN, SERVICE_TURN_ON, handle_light_service,
@ -279,32 +275,32 @@ def setup(hass, config):
class Light(ToggleEntity): class Light(ToggleEntity):
""" Represents a light within Home Assistant. """ """Representation of a light."""
# pylint: disable=no-self-use
# pylint: disable=no-self-use
@property @property
def brightness(self): def brightness(self):
""" Brightness of this light between 0..255. """ """Return the brightness of this light between 0..255."""
return None return None
@property @property
def xy_color(self): def xy_color(self):
""" XY color value [float, float]. """ """Return the XY color value [float, float]."""
return None return None
@property @property
def rgb_color(self): def rgb_color(self):
""" RGB color value [int, int, int] """ """Return the RGB color value [int, int, int]."""
return None return None
@property @property
def color_temp(self): def color_temp(self):
""" CT color value in mirads. """ """Return the CT color value in mirads."""
return None return None
@property @property
def state_attributes(self): def state_attributes(self):
""" Returns optional state attributes. """ """Return optional state attributes."""
data = {} data = {}
if self.is_on: if self.is_on:

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light.blinksticklight
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Blinkstick lights. Support for Blinkstick lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -18,7 +16,7 @@ REQUIREMENTS = ["blinkstick==1.1.7"]
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Add device specified by serial number. """ """Add device specified by serial number."""
from blinkstick import blinkstick from blinkstick import blinkstick
stick = blinkstick.find_by_serial(config['serial']) stick = blinkstick.find_by_serial(config['serial'])
@ -27,9 +25,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class BlinkStickLight(Light): class BlinkStickLight(Light):
""" Represents a BlinkStick light. """ """Representation of a BlinkStick light."""
def __init__(self, stick, name): def __init__(self, stick, name):
"""Initialize the light."""
self._stick = stick self._stick = stick
self._name = name self._name = name
self._serial = stick.get_serial() self._serial = stick.get_serial()
@ -37,30 +36,30 @@ class BlinkStickLight(Light):
@property @property
def should_poll(self): def should_poll(self):
""" Polling needed. """ """Polling needed."""
return True return True
@property @property
def name(self): def name(self):
""" The name of the light. """ """Return the name of the light."""
return self._name return self._name
@property @property
def rgb_color(self): def rgb_color(self):
""" Read back the color of the light. """ """Read back the color of the light."""
return self._rgb_color return self._rgb_color
@property @property
def is_on(self): def is_on(self):
""" Check whether any of the LEDs colors are non-zero. """ """Check whether any of the LEDs colors are non-zero."""
return sum(self._rgb_color) > 0 return sum(self._rgb_color) > 0
def update(self): def update(self):
""" Read back the device state """ """Read back the device state."""
self._rgb_color = self._stick.get_color() self._rgb_color = self._stick.get_color()
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
if ATTR_RGB_COLOR in kwargs: if ATTR_RGB_COLOR in kwargs:
self._rgb_color = kwargs[ATTR_RGB_COLOR] self._rgb_color = kwargs[ATTR_RGB_COLOR]
else: else:
@ -71,5 +70,5 @@ class BlinkStickLight(Light):
blue=self._rgb_color[2]) blue=self._rgb_color[2])
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off """ """Turn the device off."""
self._stick.turn_off() self._stick.turn_off()

View File

@ -27,9 +27,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class DemoLight(Light): class DemoLight(Light):
"""Provides a demo light.""" """Provide a demo light."""
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def __init__(self, name, state, rgb=None, ct=None, brightness=180): def __init__(self, name, state, rgb=None, ct=None, brightness=180):
"""Initialize the light."""
self._name = name self._name = name
self._state = state self._state = state
self._rgb = rgb or random.choice(LIGHT_COLORS) self._rgb = rgb or random.choice(LIGHT_COLORS)

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light.hue
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Hue lights. Support for Hue lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -36,7 +34,7 @@ _LOGGER = logging.getLogger(__name__)
def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE): def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE):
""" Attempt to detect host based on existing configuration. """ """Attempt to detect host based on existing configuration."""
path = hass.config.path(filename) path = hass.config.path(filename)
if not os.path.isfile(path): if not os.path.isfile(path):
@ -53,7 +51,7 @@ def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE):
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Gets the Hue lights. """ """Setup the Hue lights."""
filename = config.get(CONF_FILENAME, PHUE_CONFIG_FILE) filename = config.get(CONF_FILENAME, PHUE_CONFIG_FILE)
if discovery_info is not None: if discovery_info is not None:
host = urlparse(discovery_info[1]).hostname host = urlparse(discovery_info[1]).hostname
@ -75,7 +73,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
def setup_bridge(host, hass, add_devices_callback, filename): def setup_bridge(host, hass, add_devices_callback, filename):
""" Setup a phue bridge based on host parameter. """ """Setup a phue bridge based on host parameter."""
import phue import phue
try: try:
@ -106,7 +104,7 @@ def setup_bridge(host, hass, add_devices_callback, filename):
@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():
""" Updates the Hue light objects with latest info from the bridge. """ """Update the Hue light objects with latest info from the bridge."""
try: try:
api = bridge.get_api() api = bridge.get_api()
except socket.error: except socket.error:
@ -144,7 +142,7 @@ def setup_bridge(host, hass, add_devices_callback, filename):
def request_configuration(host, hass, add_devices_callback, filename): def request_configuration(host, hass, add_devices_callback, filename):
""" Request configuration steps from the user. """ """Request configuration steps from the user."""
configurator = get_component('configurator') configurator = get_component('configurator')
# We got an error if this method is called while we are configuring # We got an error if this method is called while we are configuring
@ -156,7 +154,7 @@ def request_configuration(host, hass, add_devices_callback, filename):
# pylint: disable=unused-argument # pylint: disable=unused-argument
def hue_configuration_callback(data): def hue_configuration_callback(data):
""" Actions to do when our configuration callback is called. """ """The actions to do when our configuration callback is called."""
setup_bridge(host, hass, add_devices_callback, filename) setup_bridge(host, hass, add_devices_callback, filename)
_CONFIGURING[host] = configurator.request_config( _CONFIGURING[host] = configurator.request_config(
@ -169,11 +167,12 @@ def request_configuration(host, hass, add_devices_callback, filename):
class HueLight(Light): class HueLight(Light):
""" Represents a Hue light """ """Representation of a Hue light."""
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def __init__(self, light_id, info, bridge, update_lights, def __init__(self, light_id, info, bridge, update_lights,
bridge_type='hue'): bridge_type='hue'):
"""Initialize the light."""
self.light_id = light_id self.light_id = light_id
self.info = info self.info = info
self.bridge = bridge self.bridge = bridge
@ -182,39 +181,38 @@ class HueLight(Light):
@property @property
def unique_id(self): def unique_id(self):
""" Returns the id of this Hue light """ """Return the ID of this Hue light."""
return "{}.{}".format( return "{}.{}".format(
self.__class__, self.info.get('uniqueid', self.name)) self.__class__, self.info.get('uniqueid', self.name))
@property @property
def name(self): def name(self):
""" Get the mame of the Hue light. """ """Return the mame of the Hue light."""
return self.info.get('name', DEVICE_DEFAULT_NAME) return self.info.get('name', DEVICE_DEFAULT_NAME)
@property @property
def brightness(self): def brightness(self):
""" Brightness of this light between 0..255. """ """Return the brightness of this light between 0..255."""
return self.info['state'].get('bri') return self.info['state'].get('bri')
@property @property
def xy_color(self): def xy_color(self):
""" XY color value. """ """Return the XY color value."""
return self.info['state'].get('xy') return self.info['state'].get('xy')
@property @property
def color_temp(self): def color_temp(self):
""" CT color value. """ """Return the CT color value."""
return self.info['state'].get('ct') return self.info['state'].get('ct')
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """Return true if device is on."""
self.update_lights() self.update_lights()
return self.info['state']['reachable'] and self.info['state']['on'] return self.info['state']['reachable'] and self.info['state']['on']
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the specified or all lights on. """ """Turn the specified or all lights on."""
command = {'on': True} command = {'on': True}
if ATTR_TRANSITION in kwargs: if ATTR_TRANSITION in kwargs:
@ -254,7 +252,7 @@ class HueLight(Light):
self.bridge.set_light(self.light_id, command) self.bridge.set_light(self.light_id, command)
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the specified or all lights off. """ """Turn the specified or all lights off."""
command = {'on': False} command = {'on': False}
if ATTR_TRANSITION in kwargs: if ATTR_TRANSITION in kwargs:
@ -265,5 +263,5 @@ class HueLight(Light):
self.bridge.set_light(self.light_id, command) self.bridge.set_light(self.light_id, command)
def update(self): def update(self):
""" Synchronize state with bridge. """ """Synchronize state with bridge."""
self.update_lights(no_throttle=True) self.update_lights(no_throttle=True)

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light.hyperion
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Hyperion remotes. Support for Hyperion remotes.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -18,7 +16,7 @@ REQUIREMENTS = []
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Sets up a Hyperion server remote """ """Setup a Hyperion server remote."""
host = config.get(CONF_HOST, None) host = config.get(CONF_HOST, None)
port = config.get("port", 19444) port = config.get("port", 19444)
device = Hyperion(host, port) device = Hyperion(host, port)
@ -30,9 +28,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class Hyperion(Light): class Hyperion(Light):
""" Represents a Hyperion remote """ """Representation of a Hyperion remote."""
def __init__(self, host, port): def __init__(self, host, port):
"""Initialize the light."""
self._host = host self._host = host
self._port = port self._port = port
self._name = host self._name = host
@ -41,21 +40,21 @@ class Hyperion(Light):
@property @property
def name(self): def name(self):
""" Return the hostname of the server. """ """Return the hostname of the server."""
return self._name return self._name
@property @property
def rgb_color(self): def rgb_color(self):
""" Last RGB color value set. """ """Return last RGB color value set."""
return self._rgb_color return self._rgb_color
@property @property
def is_on(self): def is_on(self):
""" True if the device is online. """ """Return true if the device is online."""
return self._is_available return self._is_available
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the lights on. """ """Turn the lights on."""
if self._is_available: if self._is_available:
if ATTR_RGB_COLOR in kwargs: if ATTR_RGB_COLOR in kwargs:
self._rgb_color = kwargs[ATTR_RGB_COLOR] self._rgb_color = kwargs[ATTR_RGB_COLOR]
@ -64,16 +63,16 @@ class Hyperion(Light):
"color": self._rgb_color}) "color": self._rgb_color})
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Disconnect the remote. """ """Disconnect the remote."""
self.json_request({"command": "clearall"}) self.json_request({"command": "clearall"})
def update(self): def update(self):
""" Ping the remote. """ """Ping the remote."""
# just see if the remote port is open # just see if the remote port is open
self._is_available = self.json_request() self._is_available = self.json_request()
def setup(self): def setup(self):
""" Get the hostname of the remote. """ """Get the hostname of the remote."""
response = self.json_request({"command": "serverinfo"}) response = self.json_request({"command": "serverinfo"})
if response: if response:
self._name = response["info"]["hostname"] self._name = response["info"]["hostname"]
@ -82,7 +81,7 @@ class Hyperion(Light):
return False return False
def json_request(self, request=None, wait_for_response=False): def json_request(self, request=None, wait_for_response=False):
""" Communicate with the json server. """ """Communicate with the JSON server."""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5) sock.settimeout(5)
@ -93,7 +92,7 @@ class Hyperion(Light):
return False return False
if not request: if not request:
# no communication needed, simple presence detection returns True # No communication needed, simple presence detection returns True
sock.close() sock.close()
return True return True
@ -101,11 +100,11 @@ class Hyperion(Light):
try: try:
buf = sock.recv(4096) buf = sock.recv(4096)
except socket.timeout: except socket.timeout:
# something is wrong, assume it's offline # Something is wrong, assume it's offline
sock.close() sock.close()
return False return False
# read until a newline or timeout # Read until a newline or timeout
buffering = True buffering = True
while buffering: while buffering:
if "\n" in str(buf, "utf-8"): if "\n" in str(buf, "utf-8"):

View File

@ -1,14 +1,14 @@
""" """
homeassistant.components.light.insteon
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Insteon Hub lights. Support for Insteon Hub lights.
"""
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/insteon_hub/
"""
from homeassistant.components.insteon_hub import INSTEON, InsteonToggleDevice from homeassistant.components.insteon_hub import INSTEON, InsteonToggleDevice
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Insteon Hub light platform. """ """Setup the Insteon Hub light platform."""
devs = [] devs = []
for device in INSTEON.devices: for device in INSTEON.devices:
if device.DeviceCategory == "Switched Lighting Control": if device.DeviceCategory == "Switched Lighting Control":

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light.isy994
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for ISY994 lights. Support for ISY994 lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -15,15 +13,15 @@ from homeassistant.const import STATE_OFF, STATE_ON
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the ISY994 platform. """ """Setup the ISY994 platform."""
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
devs = [] devs = []
# verify connection
if ISY is None or not ISY.connected: if ISY is None or not ISY.connected:
logger.error('A connection has not been made to the ISY controller.') logger.error('A connection has not been made to the ISY controller.')
return False return False
# import dimmable nodes # Import dimmable nodes
for (path, node) in ISY.nodes: for (path, node) in ISY.nodes:
if node.dimmable and SENSOR_STRING not in node.name: if node.dimmable and SENSOR_STRING not in node.name:
if HIDDEN_STRING in path: if HIDDEN_STRING in path:
@ -34,7 +32,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ISYLightDevice(ISYDeviceABC): class ISYLightDevice(ISYDeviceABC):
""" Represents as ISY light. """ """Representation of a ISY light."""
_domain = 'light' _domain = 'light'
_dtype = 'analog' _dtype = 'analog'
@ -43,7 +41,7 @@ class ISYLightDevice(ISYDeviceABC):
_states = [STATE_ON, STATE_OFF] _states = [STATE_ON, STATE_OFF]
def _attr_filter(self, attr): def _attr_filter(self, attr):
""" Filter brightness out of entity while off. """ """Filter brightness out of entity while off."""
if ATTR_BRIGHTNESS in attr and not self.is_on: if ATTR_BRIGHTNESS in attr and not self.is_on:
del attr[ATTR_BRIGHTNESS] del attr[ATTR_BRIGHTNESS]
return attr return attr

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.light.lifx Support for the LIFX platform that implements lights.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LIFX platform that implements lights
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.lifx/ https://home-assistant.io/components/light.lifx/
@ -31,8 +29,11 @@ TEMP_MAX_HASS = 500 # home assistant maximum temperature
class LIFX(): class LIFX():
"""Representation of a LIFX light."""
def __init__(self, add_devices_callback, def __init__(self, add_devices_callback,
server_addr=None, broadcast_addr=None): server_addr=None, broadcast_addr=None):
"""Initialize the light."""
import liffylights import liffylights
self._devices = [] self._devices = []
@ -47,6 +48,7 @@ class LIFX():
broadcast_addr) broadcast_addr)
def find_bulb(self, ipaddr): def find_bulb(self, ipaddr):
"""Search for bulbs."""
bulb = None bulb = None
for device in self._devices: for device in self._devices:
if device.ipaddr == ipaddr: if device.ipaddr == ipaddr:
@ -56,6 +58,7 @@ class LIFX():
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def on_device(self, ipaddr, name, power, hue, sat, bri, kel): def on_device(self, ipaddr, name, power, hue, sat, bri, kel):
"""Initialize the light."""
bulb = self.find_bulb(ipaddr) bulb = self.find_bulb(ipaddr)
if bulb is None: if bulb is None:
@ -74,6 +77,7 @@ class LIFX():
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def on_color(self, ipaddr, hue, sat, bri, kel): def on_color(self, ipaddr, hue, sat, bri, kel):
"""Initialize the light."""
bulb = self.find_bulb(ipaddr) bulb = self.find_bulb(ipaddr)
if bulb is not None: if bulb is not None:
@ -81,6 +85,7 @@ class LIFX():
bulb.update_ha_state() bulb.update_ha_state()
def on_power(self, ipaddr, power): def on_power(self, ipaddr, power):
"""Initialize the light."""
bulb = self.find_bulb(ipaddr) bulb = self.find_bulb(ipaddr)
if bulb is not None: if bulb is not None:
@ -89,28 +94,30 @@ class LIFX():
# pylint: disable=unused-argument # pylint: disable=unused-argument
def poll(self, now): def poll(self, now):
"""Initialize the light."""
self.probe() self.probe()
def probe(self, address=None): def probe(self, address=None):
"""Initialize the light."""
self._liffylights.probe(address) self._liffylights.probe(address)
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Set up platform. """ """Setup the LIFX platform."""
server_addr = config.get(CONF_SERVER, None) server_addr = config.get(CONF_SERVER, None)
broadcast_addr = config.get(CONF_BROADCAST, None) broadcast_addr = config.get(CONF_BROADCAST, None)
lifx_library = LIFX(add_devices_callback, server_addr, broadcast_addr) lifx_library = LIFX(add_devices_callback, server_addr, broadcast_addr)
# register our poll service # Register our poll service
track_time_change(hass, lifx_library.poll, second=[10, 40]) track_time_change(hass, lifx_library.poll, second=[10, 40])
lifx_library.probe() lifx_library.probe()
def convert_rgb_to_hsv(rgb): def convert_rgb_to_hsv(rgb):
""" Convert HASS RGB values to HSV values. """ """Convert Home Assistant RGB values to HSV values."""
red, green, blue = [_ / BYTE_MAX for _ in rgb] red, green, blue = [_ / BYTE_MAX for _ in rgb]
hue, saturation, brightness = colorsys.rgb_to_hsv(red, green, blue) hue, saturation, brightness = colorsys.rgb_to_hsv(red, green, blue)
@ -122,10 +129,12 @@ def convert_rgb_to_hsv(rgb):
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
class LIFXLight(Light): class LIFXLight(Light):
""" Provides LIFX light. """ """Representation of a LIFX light."""
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def __init__(self, liffy, ipaddr, name, power, hue, def __init__(self, liffy, ipaddr, name, power, hue,
saturation, brightness, kelvin): saturation, brightness, kelvin):
"""Initialize the light."""
_LOGGER.debug("LIFXLight: %s %s", _LOGGER.debug("LIFXLight: %s %s",
ipaddr, name) ipaddr, name)
@ -137,58 +146,50 @@ class LIFXLight(Light):
@property @property
def should_poll(self): def should_poll(self):
""" No polling needed for LIFX light. """ """No polling needed for LIFX light."""
return False return False
@property @property
def name(self): def name(self):
""" Returns the name of the device. """ """Return the name of the device."""
return self._name return self._name
@property @property
def ipaddr(self): def ipaddr(self):
""" Returns the ip of the device. """ """Return the IP address of the device."""
return self._ip return self._ip
@property @property
def rgb_color(self): def rgb_color(self):
""" Returns RGB value. """ """Return the RGB value."""
_LOGGER.debug("rgb_color: [%d %d %d]", _LOGGER.debug("rgb_color: [%d %d %d]",
self._rgb[0], self._rgb[1], self._rgb[2]) self._rgb[0], self._rgb[1], self._rgb[2])
return self._rgb return self._rgb
@property @property
def brightness(self): def brightness(self):
""" Returns brightness of this light between 0..255. """ """Return the brightness of this light between 0..255."""
brightness = int(self._bri / (BYTE_MAX + 1)) brightness = int(self._bri / (BYTE_MAX + 1))
_LOGGER.debug("brightness: %d", brightness)
_LOGGER.debug("brightness: %d",
brightness)
return brightness return brightness
@property @property
def color_temp(self): def color_temp(self):
""" Returns color temperature. """ """Return the color temperature."""
temperature = int(TEMP_MIN_HASS + (TEMP_MAX_HASS - TEMP_MIN_HASS) * temperature = int(TEMP_MIN_HASS + (TEMP_MAX_HASS - TEMP_MIN_HASS) *
(self._kel - TEMP_MIN) / (TEMP_MAX - TEMP_MIN)) (self._kel - TEMP_MIN) / (TEMP_MAX - TEMP_MIN))
_LOGGER.debug("color_temp: %d", _LOGGER.debug("color_temp: %d", temperature)
temperature)
return temperature return temperature
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """Return true if device is on."""
_LOGGER.debug("is_on: %d", _LOGGER.debug("is_on: %d", self._power)
self._power)
return self._power != 0 return self._power != 0
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
if ATTR_TRANSITION in kwargs: if ATTR_TRANSITION in kwargs:
fade = kwargs[ATTR_TRANSITION] * 1000 fade = kwargs[ATTR_TRANSITION] * 1000
else: else:
@ -225,30 +226,26 @@ class LIFXLight(Light):
brightness, kelvin, fade) brightness, kelvin, fade)
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """Turn the device off."""
if ATTR_TRANSITION in kwargs: if ATTR_TRANSITION in kwargs:
fade = kwargs[ATTR_TRANSITION] * 1000 fade = kwargs[ATTR_TRANSITION] * 1000
else: else:
fade = 0 fade = 0
_LOGGER.debug("turn_off: %s %d", _LOGGER.debug("turn_off: %s %d", self._ip, fade)
self._ip, fade)
self._liffylights.set_power(self._ip, 0, fade) self._liffylights.set_power(self._ip, 0, fade)
def set_name(self, name): def set_name(self, name):
""" Set name. """ """Set name of the light."""
self._name = name self._name = name
def set_power(self, power): def set_power(self, power):
""" Set power state value. """ """Set power state value."""
_LOGGER.debug("set_power: %d", _LOGGER.debug("set_power: %d", power)
power)
self._power = (power != 0) self._power = (power != 0)
def set_color(self, hue, sat, bri, kel): def set_color(self, hue, sat, bri, kel):
""" Set color state values. """ """Set color state values."""
self._hue = hue self._hue = hue
self._sat = sat self._sat = sat
self._bri = bri self._bri = bri

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light.limitlessled
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for LimitlessLED bulbs. Support for LimitlessLED bulbs.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -23,7 +21,7 @@ WHITE = [255, 255, 255]
def rewrite_legacy(config): def rewrite_legacy(config):
""" Rewrite legacy configuration to new format. """ """Rewrite legacy configuration to new format."""
bridges = config.get('bridges', [config]) bridges = config.get('bridges', [config])
new_bridges = [] new_bridges = []
for bridge_conf in bridges: for bridge_conf in bridges:
@ -49,7 +47,7 @@ def rewrite_legacy(config):
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Gets the LimitlessLED lights. """ """Setup the LimitlessLED lights."""
from limitlessled.bridge import Bridge from limitlessled.bridge import Bridge
# Two legacy configuration formats are supported to # Two legacy configuration formats are supported to
@ -71,15 +69,15 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
def state(new_state): def state(new_state):
""" State decorator. """State decorator.
Specify True (turn on) or False (turn off). Specify True (turn on) or False (turn off).
""" """
def decorator(function): def decorator(function):
""" Decorator function. """ """Decorator function."""
# pylint: disable=no-member,protected-access # pylint: disable=no-member,protected-access
def wrapper(self, **kwargs): def wrapper(self, **kwargs):
""" Wrap a group state change. """ """Wrap a group state change."""
from limitlessled.pipeline import Pipeline from limitlessled.pipeline import Pipeline
pipeline = Pipeline() pipeline = Pipeline()
transition_time = DEFAULT_TRANSITION transition_time = DEFAULT_TRANSITION
@ -104,9 +102,10 @@ def state(new_state):
class LimitlessLEDGroup(Light): class LimitlessLEDGroup(Light):
""" LimitessLED group. """ """Representation of a LimitessLED group."""
def __init__(self, group): def __init__(self, group):
""" Initialize a group. """ """Initialize a group."""
self.group = group self.group = group
self.repeating = False self.repeating = False
self._is_on = False self._is_on = False
@ -114,7 +113,7 @@ class LimitlessLEDGroup(Light):
@staticmethod @staticmethod
def factory(group): def factory(group):
""" Produce LimitlessLEDGroup objects. """ """Produce LimitlessLEDGroup objects."""
from limitlessled.group.rgbw import RgbwGroup from limitlessled.group.rgbw import RgbwGroup
from limitlessled.group.white import WhiteGroup from limitlessled.group.white import WhiteGroup
if isinstance(group, WhiteGroup): if isinstance(group, WhiteGroup):
@ -124,38 +123,36 @@ class LimitlessLEDGroup(Light):
@property @property
def should_poll(self): def should_poll(self):
""" No polling needed. """No polling needed."""
LimitlessLED state cannot be fetched.
"""
return False return False
@property @property
def name(self): def name(self):
""" Returns the name of the group. """ """Return the name of the group."""
return self.group.name return self.group.name
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """Return true if device is on."""
return self._is_on return self._is_on
@property @property
def brightness(self): def brightness(self):
""" Brightness property. """ """Return the brightness property."""
return self._brightness return self._brightness
@state(False) @state(False)
def turn_off(self, transition_time, pipeline, **kwargs): def turn_off(self, transition_time, pipeline, **kwargs):
""" Turn off a group. """ """Turn off a group."""
if self.is_on: if self.is_on:
pipeline.transition(transition_time, brightness=0.0).off() pipeline.transition(transition_time, brightness=0.0).off()
class LimitlessLEDWhiteGroup(LimitlessLEDGroup): class LimitlessLEDWhiteGroup(LimitlessLEDGroup):
""" LimitlessLED White group. """ """Representation of a LimitlessLED White group."""
def __init__(self, group): def __init__(self, group):
""" Initialize White group. """ """Initialize White group."""
super().__init__(group) super().__init__(group)
# Initialize group with known values. # Initialize group with known values.
self.group.on = True self.group.on = True
@ -167,12 +164,12 @@ class LimitlessLEDWhiteGroup(LimitlessLEDGroup):
@property @property
def color_temp(self): def color_temp(self):
""" Temperature property. """ """Return the temperature property."""
return self._temperature return self._temperature
@state(True) @state(True)
def turn_on(self, transition_time, pipeline, **kwargs): def turn_on(self, transition_time, pipeline, **kwargs):
""" Turn on (or adjust property of) a group. """ """Turn on (or adjust property of) a group."""
# Check arguments. # Check arguments.
if ATTR_BRIGHTNESS in kwargs: if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS] self._brightness = kwargs[ATTR_BRIGHTNESS]
@ -187,9 +184,10 @@ class LimitlessLEDWhiteGroup(LimitlessLEDGroup):
class LimitlessLEDRGBWGroup(LimitlessLEDGroup): class LimitlessLEDRGBWGroup(LimitlessLEDGroup):
""" LimitlessLED RGBW group. """ """Representation of a LimitlessLED RGBW group."""
def __init__(self, group): def __init__(self, group):
""" Initialize RGBW group. """ """Initialize RGBW group."""
super().__init__(group) super().__init__(group)
# Initialize group with known values. # Initialize group with known values.
self.group.on = True self.group.on = True
@ -201,12 +199,12 @@ class LimitlessLEDRGBWGroup(LimitlessLEDGroup):
@property @property
def rgb_color(self): def rgb_color(self):
""" Color property. """ """Return the color property."""
return self._color return self._color
@state(True) @state(True)
def turn_on(self, transition_time, pipeline, **kwargs): def turn_on(self, transition_time, pipeline, **kwargs):
""" Turn on (or adjust property of) a group. """ """Turn on (or adjust property of) a group."""
from limitlessled.presets import COLORLOOP from limitlessled.presets import COLORLOOP
# Check arguments. # Check arguments.
if ATTR_BRIGHTNESS in kwargs: if ATTR_BRIGHTNESS in kwargs:
@ -239,43 +237,31 @@ class LimitlessLEDRGBWGroup(LimitlessLEDGroup):
def _from_hass_temperature(temperature): def _from_hass_temperature(temperature):
""" Convert Home Assistant color temperature """Convert Home Assistant color temperature units to percentage."""
units to percentage.
"""
return (temperature - 154) / 346 return (temperature - 154) / 346
def _to_hass_temperature(temperature): def _to_hass_temperature(temperature):
""" Convert percentage to Home Assistant """Convert percentage to Home Assistant color temperature units."""
color temperature units.
"""
return int(temperature * 346) + 154 return int(temperature * 346) + 154
def _from_hass_brightness(brightness): def _from_hass_brightness(brightness):
""" Convert Home Assistant brightness units """Convert Home Assistant brightness units to percentage."""
to percentage.
"""
return brightness / 255 return brightness / 255
def _to_hass_brightness(brightness): def _to_hass_brightness(brightness):
""" Convert percentage to Home Assistant """Convert percentage to Home Assistant brightness units."""
brightness units.
"""
return int(brightness * 255) return int(brightness * 255)
def _from_hass_color(color): def _from_hass_color(color):
""" Convert Home Assistant RGB list """Convert Home Assistant RGB list to Color tuple."""
to Color tuple.
"""
from limitlessled import Color from limitlessled import Color
return Color(*tuple(color)) return Color(*tuple(color))
def _to_hass_color(color): def _to_hass_color(color):
""" Convert from Color tuple to """Convert from Color tuple to Home Assistant RGB list."""
Home Assistant RGB list.
"""
return list([int(c) for c in color]) return list([int(c) for c in color])

View File

@ -119,12 +119,12 @@ class MqttLight(Light):
@property @property
def brightness(self): def brightness(self):
"""Brightness of this light between 0..255.""" """Return the brightness of this light between 0..255."""
return self._brightness return self._brightness
@property @property
def rgb_color(self): def rgb_color(self):
"""RGB color value.""" """Return the RGB color value."""
return self._rgb return self._rgb
@property @property
@ -134,17 +134,17 @@ class MqttLight(Light):
@property @property
def name(self): def name(self):
"""Name of the device if any.""" """Return the name of the device if any."""
return self._name return self._name
@property @property
def is_on(self): def is_on(self):
"""True if device is on.""" """Return true if device is on."""
return self._state return self._state
@property @property
def assumed_state(self): def assumed_state(self):
"""Return True if we do optimistic updates.""" """Return true if we do optimistic updates."""
return self._optimistic return self._optimistic
def turn_on(self, **kwargs): def turn_on(self, **kwargs):

View File

@ -56,7 +56,6 @@ class MySensorsLight(Light):
"""Represent the value of a MySensors child node.""" """Represent the value of a MySensors child node."""
# pylint: disable=too-many-arguments,too-many-instance-attributes # pylint: disable=too-many-arguments,too-many-instance-attributes
def __init__( def __init__(
self, gateway, node_id, child_id, name, value_type, child_type): self, gateway, node_id, child_id, name, value_type, child_type):
"""Setup instance attributes.""" """Setup instance attributes."""
@ -75,27 +74,27 @@ class MySensorsLight(Light):
@property @property
def should_poll(self): def should_poll(self):
"""MySensor gateway pushes its state to HA.""" """No polling needed."""
return False return False
@property @property
def name(self): def name(self):
"""The name of this entity.""" """Return the name of this entity."""
return self._name return self._name
@property @property
def brightness(self): def brightness(self):
"""Brightness of this light between 0..255.""" """Return the brightness of this light between 0..255."""
return self._brightness return self._brightness
@property @property
def rgb_color(self): def rgb_color(self):
"""RGB color value [int, int, int].""" """Return the RGB color value [int, int, int]."""
return self._rgb return self._rgb
@property @property
def rgb_white(self): # not implemented in the frontend yet def rgb_white(self): # not implemented in the frontend yet
"""White value in RGBW, value between 0..255.""" """Return the white value in RGBW, value between 0..255."""
return self._white return self._white
@property @property
@ -113,17 +112,17 @@ class MySensorsLight(Light):
@property @property
def available(self): def available(self):
"""Return True if entity is available.""" """Return true if entity is available."""
return self.value_type in self._values return self.value_type in self._values
@property @property
def assumed_state(self): def assumed_state(self):
"""Return True if unable to access real state of entity.""" """Return true if unable to access real state of entity."""
return self.gateway.optimistic return self.gateway.optimistic
@property @property
def is_on(self): def is_on(self):
"""True if device is on.""" """Return true if device is on."""
return self._state return self._state
def _turn_on_light(self): def _turn_on_light(self):

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light.rfxtrx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for RFXtrx lights. Support for RFXtrx lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -22,7 +20,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Setup the RFXtrx platform. """ """Setup the RFXtrx platform."""
import RFXtrx as rfxtrxmod import RFXtrx as rfxtrxmod
lights = [] lights = []
@ -47,7 +45,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
add_devices_callback(lights) add_devices_callback(lights)
def light_update(event): def light_update(event):
""" Callback for light updates from the RFXtrx gateway. """ """Callback for light updates from the RFXtrx gateway."""
if not isinstance(event.device, rfxtrxmod.LightingDevice) or \ if not isinstance(event.device, rfxtrxmod.LightingDevice) or \
not event.device.known_to_be_dimmable: not event.device.known_to_be_dimmable:
return return
@ -120,8 +118,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class RfxtrxLight(Light): class RfxtrxLight(Light):
""" Provides a RFXtrx light. """ """Represenation of a RFXtrx light."""
def __init__(self, name, event, datas, signal_repetitions): def __init__(self, name, event, datas, signal_repetitions):
"""Initialize the light."""
self._name = name self._name = name
self._event = event self._event = event
self._state = datas[ATTR_STATE] self._state = datas[ATTR_STATE]
@ -131,27 +131,27 @@ class RfxtrxLight(Light):
@property @property
def should_poll(self): def should_poll(self):
""" No polling needed for a light. """ """No polling needed for a light."""
return False return False
@property @property
def name(self): def name(self):
""" Returns the name of the light if any. """ """Return the name of the light if any."""
return self._name return self._name
@property @property
def should_fire_event(self): def should_fire_event(self):
""" Returns is the device must fire event""" """Return true if the device must fire event."""
return self._should_fire_event return self._should_fire_event
@property @property
def is_on(self): def is_on(self):
""" True if light is on. """ """Return true if light is on."""
return self._state return self._state
@property @property
def brightness(self): def brightness(self):
""" Brightness of this light between 0..255. """ """Return the brightness of this light between 0..255."""
return self._brightness return self._brightness
@property @property
@ -160,7 +160,7 @@ class RfxtrxLight(Light):
return True return True
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the light on. """ """Turn the light on."""
brightness = kwargs.get(ATTR_BRIGHTNESS) brightness = kwargs.get(ATTR_BRIGHTNESS)
if not self._event: if not self._event:
return return
@ -178,8 +178,7 @@ class RfxtrxLight(Light):
self.update_ha_state() self.update_ha_state()
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the light off. """ """Turn the light off."""
if not self._event: if not self._event:
return return

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light.scsgate
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for SCSGate lights. Support for SCSGate lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -16,8 +14,7 @@ DEPENDENCIES = ['scsgate']
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Add the SCSGate swiches defined inside of the configuration file. """ """Add the SCSGate swiches defined inside of the configuration file."""
devices = config.get('devices') devices = config.get('devices')
lights = [] lights = []
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -42,8 +39,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class SCSGateLight(Light): class SCSGateLight(Light):
""" Provides a SCSGate light. """ """representation of a SCSGate light."""
def __init__(self, scs_id, name, logger): def __init__(self, scs_id, name, logger):
"""Initialize the light."""
self._name = name self._name = name
self._scs_id = scs_id self._scs_id = scs_id
self._toggled = False self._toggled = False
@ -51,26 +50,26 @@ class SCSGateLight(Light):
@property @property
def scs_id(self): def scs_id(self):
""" SCS ID """ """Return the SCS ID."""
return self._scs_id return self._scs_id
@property @property
def should_poll(self): def should_poll(self):
""" No polling needed for a SCSGate light. """ """No polling needed for a SCSGate light."""
return False return False
@property @property
def name(self): def name(self):
""" Returns the name of the device if any. """ """Return the name of the device if any."""
return self._name return self._name
@property @property
def is_on(self): def is_on(self):
""" True if light is on. """ """Return true if light is on."""
return self._toggled return self._toggled
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
from scsgate.tasks import ToggleStatusTask from scsgate.tasks import ToggleStatusTask
scsgate.SCSGATE.append_task( scsgate.SCSGATE.append_task(
@ -82,7 +81,7 @@ class SCSGateLight(Light):
self.update_ha_state() self.update_ha_state()
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """Turn the device off."""
from scsgate.tasks import ToggleStatusTask from scsgate.tasks import ToggleStatusTask
scsgate.SCSGATE.append_task( scsgate.SCSGATE.append_task(
@ -94,7 +93,7 @@ class SCSGateLight(Light):
self.update_ha_state() self.update_ha_state()
def process_event(self, message): def process_event(self, message):
""" Handle a SCSGate message related with this light """ """Handle a SCSGate message related with this light."""
if self._toggled == message.toggled: if self._toggled == message.toggled:
self._logger.info( self._logger.info(
"Light %s, ignoring message %s because state already active", "Light %s, ignoring message %s because state already active",

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light.tellstick
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Tellstick lights. Support for Tellstick lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -15,8 +13,7 @@ SIGNAL_REPETITIONS = 1
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return Tellstick lights. """ """Setup Tellstick lights."""
import tellcore.telldus as telldus import tellcore.telldus as telldus
from tellcore.library import DirectCallbackDispatcher from tellcore.library import DirectCallbackDispatcher
import tellcore.constants as tellcore_constants import tellcore.constants as tellcore_constants
@ -32,7 +29,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
lights.append(TellstickLight(switch, signal_repetitions)) lights.append(TellstickLight(switch, signal_repetitions))
def _device_event_callback(id_, method, data, cid): def _device_event_callback(id_, method, data, cid):
""" Called from the TelldusCore library to update one device """ """Called from the TelldusCore library to update one device."""
for light_device in lights: for light_device in lights:
if light_device.tellstick_device.id == id_: if light_device.tellstick_device.id == id_:
# Execute the update in another thread # Execute the update in another thread
@ -42,7 +39,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
callback_id = core.register_device_event(_device_event_callback) callback_id = core.register_device_event(_device_event_callback)
def unload_telldus_lib(event): def unload_telldus_lib(event):
""" Un-register the callback bindings """ """Un-register the callback bindings."""
if callback_id is not None: if callback_id is not None:
core.unregister_callback(callback_id) core.unregister_callback(callback_id)
@ -52,9 +49,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class TellstickLight(Light): class TellstickLight(Light):
""" Represents a Tellstick light. """ """Representation of a Tellstick light."""
def __init__(self, tellstick_device, signal_repetitions): def __init__(self, tellstick_device, signal_repetitions):
"""Initialize the light."""
import tellcore.constants as tellcore_constants import tellcore.constants as tellcore_constants
self.tellstick_device = tellstick_device self.tellstick_device = tellstick_device
@ -70,28 +68,28 @@ class TellstickLight(Light):
@property @property
def name(self): def name(self):
""" Returns the name of the switch if any. """ """Return the name of the switch if any."""
return self.tellstick_device.name return self.tellstick_device.name
@property @property
def is_on(self): def is_on(self):
""" True if switch is on. """ """Return true if switch is on."""
return self._brightness > 0 return self._brightness > 0
@property @property
def brightness(self): def brightness(self):
""" Brightness of this light between 0..255. """ """Return the brightness of this light between 0..255."""
return self._brightness return self._brightness
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turns the switch off. """ """Turn the switch off."""
for _ in range(self.signal_repetitions): for _ in range(self.signal_repetitions):
self.tellstick_device.turn_off() self.tellstick_device.turn_off()
self._brightness = 0 self._brightness = 0
self.update_ha_state() self.update_ha_state()
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turns the switch on. """ """Turn the switch on."""
brightness = kwargs.get(ATTR_BRIGHTNESS) brightness = kwargs.get(ATTR_BRIGHTNESS)
if brightness is None: if brightness is None:
@ -104,7 +102,7 @@ class TellstickLight(Light):
self.update_ha_state() self.update_ha_state()
def update(self): def update(self):
""" Update state of the light. """ """Update state of the light."""
import tellcore.constants as tellcore_constants import tellcore.constants as tellcore_constants
last_command = self.tellstick_device.last_sent_command( last_command = self.tellstick_device.last_sent_command(
@ -123,10 +121,10 @@ class TellstickLight(Light):
@property @property
def should_poll(self): def should_poll(self):
""" Tells Home Assistant not to poll this entity. """ """No polling needed."""
return False return False
@property @property
def assumed_state(self): def assumed_state(self):
""" Tellstick devices are always assumed state """ """Tellstick devices are always assumed state."""
return True return True

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light.vera
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Vera lights. Support for Vera lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -23,7 +21,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return Vera lights. """ """Setup Vera lights."""
import pyvera as veraApi import pyvera as veraApi
base_url = config.get('vera_controller_url') base_url = config.get('vera_controller_url')
@ -40,7 +38,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
if created: if created:
def stop_subscription(event): def stop_subscription(event):
""" Shutdown Vera subscriptions and subscription thread on exit""" """Shutdown Vera subscriptions and subscription thread on exit."""
_LOGGER.info("Shutting down subscriptions.") _LOGGER.info("Shutting down subscriptions.")
vera_controller.stop() vera_controller.stop()
@ -53,7 +51,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
'On/Off Switch', 'On/Off Switch',
'Dimmable Switch']) 'Dimmable Switch'])
except RequestException: except RequestException:
# There was a network related error connecting to the vera controller # There was a network related error connecting to the vera controller.
_LOGGER.exception("Error communicating with Vera API") _LOGGER.exception("Error communicating with Vera API")
return False return False
@ -69,9 +67,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class VeraLight(Light): class VeraLight(Light):
""" Represents a Vera Light, including dimmable. """ """Representation of a Vera Light, including dimmable."""
def __init__(self, vera_device, controller, extra_data=None): def __init__(self, vera_device, controller, extra_data=None):
"""Initialize the light."""
self.vera_device = vera_device self.vera_device = vera_device
self.extra_data = extra_data self.extra_data = extra_data
self.controller = controller self.controller = controller
@ -89,16 +88,17 @@ class VeraLight(Light):
@property @property
def name(self): def name(self):
""" Get the mame of the switch. """ """Return the name of the light."""
return self._name return self._name
@property @property
def brightness(self): def brightness(self):
"""Brightness of the light.""" """Return the brightness of the light."""
if self.vera_device.is_dimmable: if self.vera_device.is_dimmable:
return self.vera_device.get_brightness() return self.vera_device.get_brightness()
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
"""Turn the light on."""
if ATTR_BRIGHTNESS in kwargs and self.vera_device.is_dimmable: if ATTR_BRIGHTNESS in kwargs and self.vera_device.is_dimmable:
self.vera_device.set_brightness(kwargs[ATTR_BRIGHTNESS]) self.vera_device.set_brightness(kwargs[ATTR_BRIGHTNESS])
else: else:
@ -108,12 +108,14 @@ class VeraLight(Light):
self.update_ha_state(True) self.update_ha_state(True)
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
"""Turn the light off."""
self.vera_device.switch_off() self.vera_device.switch_off()
self._state = STATE_OFF self._state = STATE_OFF
self.update_ha_state() self.update_ha_state()
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes."""
attr = {} attr = {}
if self.vera_device.has_battery: if self.vera_device.has_battery:
@ -138,16 +140,16 @@ class VeraLight(Light):
@property @property
def should_poll(self): def should_poll(self):
""" Tells Home Assistant not to poll this entity. """ """No polling needed."""
return False return False
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """Return true if device is on."""
return self._state == STATE_ON return self._state == STATE_ON
def update(self): def update(self):
""" Called by the vera device callback to update state. """ """Called by the vera device callback to update state."""
if self.vera_device.is_switched_on(): if self.vera_device.is_switched_on():
self._state = STATE_ON self._state = STATE_ON
else: else:

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light.wemo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Belkin WeMo lights. Support for Belkin WeMo lights.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
@ -22,7 +20,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Probe WeMo bridges and register connected lights.""" """Setup WeMo bridges and register connected lights."""
import pywemo.discovery as discovery import pywemo.discovery as discovery
if discovery_info is not None: if discovery_info is not None:
@ -40,8 +38,7 @@ 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():
"""Updates 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_get_lights()
new_lights = [] new_lights = []
@ -61,9 +58,10 @@ def setup_bridge(bridge, add_devices_callback):
class WemoLight(Light): class WemoLight(Light):
"""Represents a WeMo light""" """Representation of a WeMo light."""
def __init__(self, bridge, light_id, info, update_lights): def __init__(self, bridge, light_id, info, update_lights):
"""Initialize the light."""
self.bridge = bridge self.bridge = bridge
self.light_id = light_id self.light_id = light_id
self.info = info self.info = info
@ -71,18 +69,18 @@ class WemoLight(Light):
@property @property
def unique_id(self): def unique_id(self):
"""Returns the id of this light""" """Return the ID of this light."""
deviceid = self.bridge.light_get_id(self.info) deviceid = self.bridge.light_get_id(self.info)
return "{}.{}".format(self.__class__, deviceid) return "{}.{}".format(self.__class__, deviceid)
@property @property
def name(self): def name(self):
"""Get the name of the light.""" """Return the name of the light."""
return self.bridge.light_name(self.info) return self.bridge.light_name(self.info)
@property @property
def brightness(self): def brightness(self):
"""Brightness of this light between 0..255.""" """Return the brightness of this light between 0..255."""
state = self.bridge.light_get_state(self.info) state = self.bridge.light_get_state(self.info)
return int(state['dim']) return int(state['dim'])

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light.wink
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Wink lights. Support for Wink lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -15,7 +13,7 @@ REQUIREMENTS = ['python-wink==0.6.2']
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return Wink lights. """ """Setup Wink lights."""
import pywink import pywink
token = config.get(CONF_ACCESS_TOKEN) token = config.get(CONF_ACCESS_TOKEN)
@ -34,46 +32,46 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class WinkLight(Light): class WinkLight(Light):
""" Represents a Wink light. """ """Representation of a Wink light."""
def __init__(self, wink): def __init__(self, wink):
"""Initialize the light."""
self.wink = wink self.wink = wink
@property @property
def unique_id(self): def unique_id(self):
""" Returns the id of this Wink switch. """ """Return the ID of this Wink light."""
return "{}.{}".format(self.__class__, self.wink.device_id()) return "{}.{}".format(self.__class__, self.wink.device_id())
@property @property
def name(self): def name(self):
""" Returns the name of the light if any. """ """Return the name of the light if any."""
return self.wink.name() return self.wink.name()
@property @property
def is_on(self): def is_on(self):
""" True if light is on. """ """Return true if light is on."""
return self.wink.state() return self.wink.state()
@property @property
def brightness(self): def brightness(self):
"""Brightness of the light.""" """Return the brightness of the light."""
return int(self.wink.brightness() * 255) return int(self.wink.brightness() * 255)
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turns the switch on. """ """Turn the switch on."""
brightness = kwargs.get(ATTR_BRIGHTNESS) brightness = kwargs.get(ATTR_BRIGHTNESS)
if brightness is not None: if brightness is not None:
self.wink.set_state(True, brightness=brightness / 255) self.wink.set_state(True, brightness=brightness / 255)
else: else:
self.wink.set_state(True) self.wink.set_state(True)
def turn_off(self): def turn_off(self):
""" Turns the switch off. """ """Turn the switch off."""
self.wink.set_state(False) self.wink.set_state(False)
def update(self): def update(self):
""" Update state of the light. """ """Update state of the light."""
self.wink.update_state() self.wink.update_state()

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.light.zigbee Functionality to use a ZigBee device as a light.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Contains functionality to use a ZigBee device as a light.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.zigbee/ https://home-assistant.io/components/light.zigbee/
@ -14,15 +12,13 @@ DEPENDENCIES = ["zigbee"]
def setup_platform(hass, config, add_entities, discovery_info=None): def setup_platform(hass, config, add_entities, discovery_info=None):
""" Create and add an entity based on the configuration. """ """Create and add an entity based on the configuration."""
add_entities([ add_entities([
ZigBeeLight(hass, ZigBeeDigitalOutConfig(config)) ZigBeeLight(hass, ZigBeeDigitalOutConfig(config))
]) ])
class ZigBeeLight(ZigBeeDigitalOut, Light): class ZigBeeLight(ZigBeeDigitalOut, Light):
""" """Use ZigBeeDigitalOut as light."""
Use multiple inheritance to turn an instance of ZigBeeDigitalOut into a
Light.
"""
pass pass

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.light.zwave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Z-Wave lights. Support for Z-Wave lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -18,7 +16,7 @@ from homeassistant.const import STATE_OFF, STATE_ON
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Find and add Z-Wave lights. """ """Find and add Z-Wave lights."""
if discovery_info is None or NETWORK is None: if discovery_info is None or NETWORK is None:
return return
@ -37,10 +35,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
def brightness_state(value): def brightness_state(value):
""" """Return the brightness and state."""
Returns the brightness and state according to the current data of given
value.
"""
if value.data > 0: if value.data > 0:
return (value.data / 99) * 255, STATE_ON return (value.data / 99) * 255, STATE_ON
else: else:
@ -48,9 +43,11 @@ def brightness_state(value):
class ZwaveDimmer(ZWaveDeviceEntity, Light): class ZwaveDimmer(ZWaveDeviceEntity, Light):
""" Provides a Z-Wave dimmer. """ """Representation of a Z-Wave dimmer."""
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def __init__(self, value): def __init__(self, value):
"""Initialize the light."""
from openzwave.network import ZWaveNetwork from openzwave.network import ZWaveNetwork
from pydispatch import dispatcher from pydispatch import dispatcher
@ -66,7 +63,7 @@ class ZwaveDimmer(ZWaveDeviceEntity, Light):
self._value_changed, ZWaveNetwork.SIGNAL_VALUE_CHANGED) self._value_changed, ZWaveNetwork.SIGNAL_VALUE_CHANGED)
def _value_changed(self, value): def _value_changed(self, value):
""" Called when a value has changed on the network. """ """Called when a value has changed on the network."""
if self._value.value_id != value.value_id: if self._value.value_id != value.value_id:
return return
@ -89,17 +86,16 @@ class ZwaveDimmer(ZWaveDeviceEntity, Light):
@property @property
def brightness(self): def brightness(self):
""" Brightness of this light between 0..255. """ """Return the brightness of this light between 0..255."""
return self._brightness return self._brightness
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """Return true if device is on."""
return self._state == STATE_ON return self._state == STATE_ON
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """Turn the device on."""
if ATTR_BRIGHTNESS in kwargs: if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS] self._brightness = kwargs[ATTR_BRIGHTNESS]
@ -111,6 +107,6 @@ class ZwaveDimmer(ZWaveDeviceEntity, Light):
self._state = STATE_ON self._state = STATE_ON
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """Turn the device off."""
if self._value.node.set_dimmer(self._value.value_id, 0): if self._value.node.set_dimmer(self._value.value_id, 0):
self._state = STATE_OFF self._state = STATE_OFF