Skip to content

Commit

Permalink
Update ordering, constants, and callback name (light.*) (home-assista…
Browse files Browse the repository at this point in the history
…nt#3339)

* Extend schema

* Update ordering

* Add line breaks

* Align callback name with other platforms

* ALign callbackname with other platforms

* Update callback name to match other platforms

* Update callback name

* Update callback name
  • Loading branch information
fabaff authored Sep 12, 2016
1 parent 44681eb commit c028e1f
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 59 deletions.
13 changes: 8 additions & 5 deletions homeassistant/components/light/blinksticklight.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@

import voluptuous as vol

from homeassistant.components.light import (ATTR_RGB_COLOR, SUPPORT_RGB_COLOR,
Light, PLATFORM_SCHEMA)
from homeassistant.components.light import (
ATTR_RGB_COLOR, SUPPORT_RGB_COLOR, Light, PLATFORM_SCHEMA)
from homeassistant.const import CONF_NAME
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['blinkstick==1.1.8']

_LOGGER = logging.getLogger(__name__)

CONF_SERIAL = 'serial'

DEFAULT_NAME = 'Blinkstick'
REQUIREMENTS = ["blinkstick==1.1.8"]

SUPPORT_BLINKSTICK = SUPPORT_RGB_COLOR

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_SERIAL): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})

_LOGGER = logging.getLogger(__name__)


# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
Expand Down
8 changes: 5 additions & 3 deletions homeassistant/components/light/enocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

_LOGGER = logging.getLogger(__name__)

DEPENDENCIES = ['enocean']
DEFAULT_NAME = 'EnOcean Light'
CONF_SENDER_ID = 'sender_id'

DEFAULT_NAME = 'EnOcean Light'

DEPENDENCIES = ['enocean']

SUPPORT_ENOCEAN = SUPPORT_BRIGHTNESS

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
Expand Down Expand Up @@ -50,7 +52,7 @@ def __init__(self, sender_id, devname, dev_id):
self._sender_id = sender_id
self.dev_id = dev_id
self._devname = devname
self.stype = "dimmer"
self.stype = 'dimmer'

@property
def name(self):
Expand Down
52 changes: 26 additions & 26 deletions homeassistant/components/light/flux_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,57 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.flux_led/
"""

import logging
import socket
import random

import voluptuous as vol

from homeassistant.components.light import (ATTR_BRIGHTNESS, ATTR_RGB_COLOR,
ATTR_EFFECT, EFFECT_RANDOM,
SUPPORT_BRIGHTNESS,
SUPPORT_EFFECT,
SUPPORT_RGB_COLOR, Light)
from homeassistant.const import CONF_DEVICES, CONF_NAME
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_EFFECT, EFFECT_RANDOM,
SUPPORT_BRIGHTNESS, SUPPORT_EFFECT, SUPPORT_RGB_COLOR, Light,
PLATFORM_SCHEMA)
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['https://github.com/Danielhiversen/flux_led/archive/0.6.zip'
'#flux_led==0.6']

_LOGGER = logging.getLogger(__name__)
DOMAIN = "flux_led"
ATTR_NAME = 'name'

DEVICE_SCHEMA = vol.Schema({
vol.Optional(ATTR_NAME): cv.string,
})
CONF_AUTOMATIC_ADD = 'automatic_add'

PLATFORM_SCHEMA = vol.Schema({
vol.Required('platform'): DOMAIN,
vol.Optional('devices', default={}): {cv.string: DEVICE_SCHEMA},
vol.Optional('automatic_add', default=False): cv.boolean,
}, extra=vol.ALLOW_EXTRA)
DOMAIN = 'flux_led'

SUPPORT_FLUX_LED = (SUPPORT_BRIGHTNESS | SUPPORT_EFFECT |
SUPPORT_RGB_COLOR)

DEVICE_SCHEMA = vol.Schema({
vol.Optional(CONF_NAME): cv.string,
})

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_DEVICES, default={}): {cv.string: DEVICE_SCHEMA},
vol.Optional(CONF_AUTOMATIC_ADD, default=False): cv.boolean,
})


def setup_platform(hass, config, add_devices_callback, discovery_info=None):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Flux lights."""
import flux_led
lights = []
light_ips = []
for ipaddr, device_config in config["devices"].items():
for ipaddr, device_config in config[CONF_DEVICES].items():
device = {}
device['name'] = device_config[ATTR_NAME]
device['name'] = device_config[CONF_NAME]
device['ipaddr'] = ipaddr
light = FluxLight(device)
if light.is_valid:
lights.append(light)
light_ips.append(ipaddr)

if not config['automatic_add']:
add_devices_callback(lights)
if not config[CONF_AUTOMATIC_ADD]:
add_devices(lights)
return

# Find the bulbs on the LAN
Expand All @@ -69,7 +70,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
lights.append(light)
light_ips.append(ipaddr)

add_devices_callback(lights)
add_devices(lights)


class FluxLight(Light):
Expand All @@ -88,14 +89,13 @@ def __init__(self, device):
self._bulb = flux_led.WifiLedBulb(self._ipaddr)
except socket.error:
self.is_valid = False
_LOGGER.error("Failed to connect to bulb %s, %s",
self._ipaddr, self._name)
_LOGGER.error(
"Failed to connect to bulb %s, %s", self._ipaddr, self._name)

@property
def unique_id(self):
"""Return the ID of this light."""
return "{}.{}".format(
self.__class__, self._ipaddr)
return "{}.{}".format(self.__class__, self._ipaddr)

@property
def name(self):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/light/homematic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
SUPPORT_HOMEMATIC = SUPPORT_BRIGHTNESS


def setup_platform(hass, config, add_callback_devices, discovery_info=None):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Homematic light platform."""
if discovery_info is None:
return

return homematic.setup_hmdevice_discovery_helper(
HMLight,
discovery_info,
add_callback_devices
add_devices
)


Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/light/rfxtrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
SUPPORT_RFXTRX = SUPPORT_BRIGHTNESS


def setup_platform(hass, config, add_devices_callback, discovery_info=None):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the RFXtrx platform."""
import RFXtrx as rfxtrxmod

lights = rfxtrx.get_devices_from_config(config, RfxtrxLight)
add_devices_callback(lights)
add_devices(lights)

def light_update(event):
"""Callback for light updates from the RFXtrx gateway."""
Expand All @@ -34,7 +34,7 @@ def light_update(event):

new_device = rfxtrx.get_new_device(event, config, RfxtrxLight)
if new_device:
add_devices_callback([new_device])
add_devices([new_device])

rfxtrx.apply_received_command(event)

Expand Down
15 changes: 7 additions & 8 deletions homeassistant/components/light/vera.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
"""
import logging

from homeassistant.components.light import (ATTR_BRIGHTNESS,
SUPPORT_BRIGHTNESS, Light)
from homeassistant.const import (
STATE_OFF, STATE_ON)
from homeassistant.components.light import (
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
from homeassistant.const import (STATE_OFF, STATE_ON)
from homeassistant.components.vera import (
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)

DEPENDENCIES = ['vera']

_LOGGER = logging.getLogger(__name__)

DEPENDENCIES = ['vera']

SUPPORT_VERA = SUPPORT_BRIGHTNESS


# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup Vera lights."""
add_devices_callback(
add_devices(
VeraLight(device, VERA_CONTROLLER) for device in VERA_DEVICES['light'])


Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/light/wemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
SUPPORT_TRANSITION | SUPPORT_XY_COLOR)


def setup_platform(hass, config, add_devices_callback, discovery_info=None):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup WeMo bridges and register connected lights."""
import pywemo.discovery as discovery

Expand All @@ -35,10 +35,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
device = discovery.device_from_description(location, mac)

if device:
setup_bridge(device, add_devices_callback)
setup_bridge(device, add_devices)


def setup_bridge(bridge, add_devices_callback):
def setup_bridge(bridge, add_devices):
"""Setup a WeMo link."""
lights = {}

Expand All @@ -55,7 +55,7 @@ def update_lights():
new_lights.append(lights[light_id])

if new_lights:
add_devices_callback(new_lights)
add_devices(new_lights)

update_lights()

Expand All @@ -73,7 +73,7 @@ def __init__(self, device, update_lights):
def unique_id(self):
"""Return the ID of this light."""
deviceid = self.device.uniqueID
return "{}.{}".format(self.__class__, deviceid)
return '{}.{}'.format(self.__class__, deviceid)

@property
def name(self):
Expand Down
13 changes: 6 additions & 7 deletions homeassistant/components/light/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import logging
import colorsys

from homeassistant.components.light import ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, \
ATTR_RGB_COLOR, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, \
SUPPORT_RGB_COLOR, Light
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_RGB_COLOR, SUPPORT_BRIGHTNESS,
SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR, Light)
from homeassistant.components.wink import WinkDevice
from homeassistant.const import CONF_ACCESS_TOKEN
from homeassistant.util import color as color_util
Expand All @@ -21,8 +21,8 @@
SUPPORT_WINK = SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR


def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Setup Wink lights."""
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Wink lights."""
import pywink

token = config.get(CONF_ACCESS_TOKEN)
Expand All @@ -36,8 +36,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
elif token is not None:
pywink.set_bearer_token(token)

add_devices_callback(
WinkLight(light) for light in pywink.get_bulbs())
add_devices(WinkLight(light) for light in pywink.get_bulbs())


class WinkLight(WinkDevice, Light):
Expand Down

0 comments on commit c028e1f

Please sign in to comment.