mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Update ordering, constants, and callback name (light.*) (#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
This commit is contained in:
parent
44681ebd55
commit
c028e1fc6f
@ -8,14 +8,19 @@ import logging
|
|||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.light import (ATTR_RGB_COLOR, SUPPORT_RGB_COLOR,
|
from homeassistant.components.light import (
|
||||||
Light, PLATFORM_SCHEMA)
|
ATTR_RGB_COLOR, SUPPORT_RGB_COLOR, Light, PLATFORM_SCHEMA)
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_NAME
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
|
REQUIREMENTS = ['blinkstick==1.1.8']
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONF_SERIAL = 'serial'
|
CONF_SERIAL = 'serial'
|
||||||
|
|
||||||
DEFAULT_NAME = 'Blinkstick'
|
DEFAULT_NAME = 'Blinkstick'
|
||||||
REQUIREMENTS = ["blinkstick==1.1.8"]
|
|
||||||
SUPPORT_BLINKSTICK = SUPPORT_RGB_COLOR
|
SUPPORT_BLINKSTICK = SUPPORT_RGB_COLOR
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
@ -23,8 +28,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
})
|
})
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
@ -17,10 +17,12 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['enocean']
|
|
||||||
DEFAULT_NAME = 'EnOcean Light'
|
|
||||||
CONF_SENDER_ID = 'sender_id'
|
CONF_SENDER_ID = 'sender_id'
|
||||||
|
|
||||||
|
DEFAULT_NAME = 'EnOcean Light'
|
||||||
|
|
||||||
|
DEPENDENCIES = ['enocean']
|
||||||
|
|
||||||
SUPPORT_ENOCEAN = SUPPORT_BRIGHTNESS
|
SUPPORT_ENOCEAN = SUPPORT_BRIGHTNESS
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
@ -50,7 +52,7 @@ class EnOceanLight(enocean.EnOceanDevice, Light):
|
|||||||
self._sender_id = sender_id
|
self._sender_id = sender_id
|
||||||
self.dev_id = dev_id
|
self.dev_id = dev_id
|
||||||
self._devname = devname
|
self._devname = devname
|
||||||
self.stype = "dimmer"
|
self.stype = 'dimmer'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -4,56 +4,57 @@ Support for Flux 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.flux_led/
|
https://home-assistant.io/components/light.flux_led/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.light import (ATTR_BRIGHTNESS, ATTR_RGB_COLOR,
|
from homeassistant.const import CONF_DEVICES, CONF_NAME
|
||||||
ATTR_EFFECT, EFFECT_RANDOM,
|
from homeassistant.components.light import (
|
||||||
SUPPORT_BRIGHTNESS,
|
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_EFFECT, EFFECT_RANDOM,
|
||||||
SUPPORT_EFFECT,
|
SUPPORT_BRIGHTNESS, SUPPORT_EFFECT, SUPPORT_RGB_COLOR, Light,
|
||||||
SUPPORT_RGB_COLOR, Light)
|
PLATFORM_SCHEMA)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['https://github.com/Danielhiversen/flux_led/archive/0.6.zip'
|
REQUIREMENTS = ['https://github.com/Danielhiversen/flux_led/archive/0.6.zip'
|
||||||
'#flux_led==0.6']
|
'#flux_led==0.6']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
DOMAIN = "flux_led"
|
|
||||||
ATTR_NAME = 'name'
|
|
||||||
|
|
||||||
DEVICE_SCHEMA = vol.Schema({
|
CONF_AUTOMATIC_ADD = 'automatic_add'
|
||||||
vol.Optional(ATTR_NAME): cv.string,
|
|
||||||
})
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = vol.Schema({
|
DOMAIN = 'flux_led'
|
||||||
vol.Required('platform'): DOMAIN,
|
|
||||||
vol.Optional('devices', default={}): {cv.string: DEVICE_SCHEMA},
|
|
||||||
vol.Optional('automatic_add', default=False): cv.boolean,
|
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
|
||||||
|
|
||||||
SUPPORT_FLUX_LED = (SUPPORT_BRIGHTNESS | SUPPORT_EFFECT |
|
SUPPORT_FLUX_LED = (SUPPORT_BRIGHTNESS | SUPPORT_EFFECT |
|
||||||
SUPPORT_RGB_COLOR)
|
SUPPORT_RGB_COLOR)
|
||||||
|
|
||||||
|
DEVICE_SCHEMA = vol.Schema({
|
||||||
|
vol.Optional(CONF_NAME): cv.string,
|
||||||
|
})
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
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, discovery_info=None):
|
||||||
"""Setup the Flux lights."""
|
"""Setup the Flux lights."""
|
||||||
import flux_led
|
import flux_led
|
||||||
lights = []
|
lights = []
|
||||||
light_ips = []
|
light_ips = []
|
||||||
for ipaddr, device_config in config["devices"].items():
|
for ipaddr, device_config in config[CONF_DEVICES].items():
|
||||||
device = {}
|
device = {}
|
||||||
device['name'] = device_config[ATTR_NAME]
|
device['name'] = device_config[CONF_NAME]
|
||||||
device['ipaddr'] = ipaddr
|
device['ipaddr'] = ipaddr
|
||||||
light = FluxLight(device)
|
light = FluxLight(device)
|
||||||
if light.is_valid:
|
if light.is_valid:
|
||||||
lights.append(light)
|
lights.append(light)
|
||||||
light_ips.append(ipaddr)
|
light_ips.append(ipaddr)
|
||||||
|
|
||||||
if not config['automatic_add']:
|
if not config[CONF_AUTOMATIC_ADD]:
|
||||||
add_devices_callback(lights)
|
add_devices(lights)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Find the bulbs on the LAN
|
# Find the bulbs on the LAN
|
||||||
@ -69,7 +70,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
lights.append(light)
|
lights.append(light)
|
||||||
light_ips.append(ipaddr)
|
light_ips.append(ipaddr)
|
||||||
|
|
||||||
add_devices_callback(lights)
|
add_devices(lights)
|
||||||
|
|
||||||
|
|
||||||
class FluxLight(Light):
|
class FluxLight(Light):
|
||||||
@ -88,14 +89,13 @@ class FluxLight(Light):
|
|||||||
self._bulb = flux_led.WifiLedBulb(self._ipaddr)
|
self._bulb = flux_led.WifiLedBulb(self._ipaddr)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
self.is_valid = False
|
self.is_valid = False
|
||||||
_LOGGER.error("Failed to connect to bulb %s, %s",
|
_LOGGER.error(
|
||||||
self._ipaddr, self._name)
|
"Failed to connect to bulb %s, %s", self._ipaddr, self._name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return the ID of this light."""
|
"""Return the ID of this light."""
|
||||||
return "{}.{}".format(
|
return "{}.{}".format(self.__class__, self._ipaddr)
|
||||||
self.__class__, self._ipaddr)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -17,7 +17,7 @@ DEPENDENCIES = ['homematic']
|
|||||||
SUPPORT_HOMEMATIC = SUPPORT_BRIGHTNESS
|
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."""
|
"""Setup the Homematic light platform."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
@ -25,7 +25,7 @@ def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
|||||||
return homematic.setup_hmdevice_discovery_helper(
|
return homematic.setup_hmdevice_discovery_helper(
|
||||||
HMLight,
|
HMLight,
|
||||||
discovery_info,
|
discovery_info,
|
||||||
add_callback_devices
|
add_devices
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,12 +19,12 @@ PLATFORM_SCHEMA = rfxtrx.DEFAULT_SCHEMA
|
|||||||
SUPPORT_RFXTRX = SUPPORT_BRIGHTNESS
|
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."""
|
"""Setup the RFXtrx platform."""
|
||||||
import RFXtrx as rfxtrxmod
|
import RFXtrx as rfxtrxmod
|
||||||
|
|
||||||
lights = rfxtrx.get_devices_from_config(config, RfxtrxLight)
|
lights = rfxtrx.get_devices_from_config(config, RfxtrxLight)
|
||||||
add_devices_callback(lights)
|
add_devices(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."""
|
||||||
@ -34,7 +34,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
|
|
||||||
new_device = rfxtrx.get_new_device(event, config, RfxtrxLight)
|
new_device = rfxtrx.get_new_device(event, config, RfxtrxLight)
|
||||||
if new_device:
|
if new_device:
|
||||||
add_devices_callback([new_device])
|
add_devices([new_device])
|
||||||
|
|
||||||
rfxtrx.apply_received_command(event)
|
rfxtrx.apply_received_command(event)
|
||||||
|
|
||||||
|
@ -6,24 +6,23 @@ https://home-assistant.io/components/light.vera/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.light import (ATTR_BRIGHTNESS,
|
from homeassistant.components.light import (
|
||||||
SUPPORT_BRIGHTNESS, Light)
|
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (STATE_OFF, STATE_ON)
|
||||||
STATE_OFF, STATE_ON)
|
|
||||||
from homeassistant.components.vera import (
|
from homeassistant.components.vera import (
|
||||||
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)
|
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)
|
||||||
|
|
||||||
DEPENDENCIES = ['vera']
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DEPENDENCIES = ['vera']
|
||||||
|
|
||||||
SUPPORT_VERA = SUPPORT_BRIGHTNESS
|
SUPPORT_VERA = SUPPORT_BRIGHTNESS
|
||||||
|
|
||||||
|
|
||||||
# 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, discovery_info=None):
|
||||||
"""Setup Vera lights."""
|
"""Setup Vera lights."""
|
||||||
add_devices_callback(
|
add_devices(
|
||||||
VeraLight(device, VERA_CONTROLLER) for device in VERA_DEVICES['light'])
|
VeraLight(device, VERA_CONTROLLER) for device in VERA_DEVICES['light'])
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ SUPPORT_WEMO = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR |
|
|||||||
SUPPORT_TRANSITION | SUPPORT_XY_COLOR)
|
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."""
|
"""Setup WeMo bridges and register connected lights."""
|
||||||
import pywemo.discovery as discovery
|
import pywemo.discovery as discovery
|
||||||
|
|
||||||
@ -35,10 +35,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
device = discovery.device_from_description(location, mac)
|
device = discovery.device_from_description(location, mac)
|
||||||
|
|
||||||
if device:
|
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."""
|
"""Setup a WeMo link."""
|
||||||
lights = {}
|
lights = {}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ def setup_bridge(bridge, add_devices_callback):
|
|||||||
new_lights.append(lights[light_id])
|
new_lights.append(lights[light_id])
|
||||||
|
|
||||||
if new_lights:
|
if new_lights:
|
||||||
add_devices_callback(new_lights)
|
add_devices(new_lights)
|
||||||
|
|
||||||
update_lights()
|
update_lights()
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ class WemoLight(Light):
|
|||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return the ID of this light."""
|
"""Return the ID of this light."""
|
||||||
deviceid = self.device.uniqueID
|
deviceid = self.device.uniqueID
|
||||||
return "{}.{}".format(self.__class__, deviceid)
|
return '{}.{}'.format(self.__class__, deviceid)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -7,9 +7,9 @@ https://home-assistant.io/components/light.wink/
|
|||||||
import logging
|
import logging
|
||||||
import colorsys
|
import colorsys
|
||||||
|
|
||||||
from homeassistant.components.light import ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, \
|
from homeassistant.components.light import (
|
||||||
ATTR_RGB_COLOR, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, \
|
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_RGB_COLOR, SUPPORT_BRIGHTNESS,
|
||||||
SUPPORT_RGB_COLOR, Light
|
SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR, Light)
|
||||||
from homeassistant.components.wink import WinkDevice
|
from homeassistant.components.wink import WinkDevice
|
||||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||||
from homeassistant.util import color as color_util
|
from homeassistant.util import color as color_util
|
||||||
@ -21,8 +21,8 @@ REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2']
|
|||||||
SUPPORT_WINK = SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR
|
SUPPORT_WINK = SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup Wink lights."""
|
"""Setup the Wink lights."""
|
||||||
import pywink
|
import pywink
|
||||||
|
|
||||||
token = config.get(CONF_ACCESS_TOKEN)
|
token = config.get(CONF_ACCESS_TOKEN)
|
||||||
@ -36,8 +36,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
elif token is not None:
|
elif token is not None:
|
||||||
pywink.set_bearer_token(token)
|
pywink.set_bearer_token(token)
|
||||||
|
|
||||||
add_devices_callback(
|
add_devices(WinkLight(light) for light in pywink.get_bulbs())
|
||||||
WinkLight(light) for light in pywink.get_bulbs())
|
|
||||||
|
|
||||||
|
|
||||||
class WinkLight(WinkDevice, Light):
|
class WinkLight(WinkDevice, Light):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user