Use voluptuous for HDMI CEC & CONF_DEVICES constants (#3107)

pull/3116/head
Fabian Affolter 2016-09-01 22:04:00 +02:00 committed by Johann Kellerman
parent 748d7f4ecb
commit 24d412938e
4 changed files with 19 additions and 23 deletions

View File

@ -7,14 +7,12 @@ https://home-assistant.io/components/climate.eq3btsmart/
import logging
from homeassistant.components.climate import ClimateDevice
from homeassistant.const import TEMP_CELSIUS
from homeassistant.const import TEMP_CELSIUS, CONF_DEVICES
from homeassistant.util.temperature import convert
REQUIREMENTS = ['bluepy_devices==0.2.0']
CONF_MAC = 'mac'
CONF_DEVICES = 'devices'
CONF_ID = 'id'
_LOGGER = logging.getLogger(__name__)
@ -28,7 +26,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
devices.append(EQ3BTSmartThermostat(mac, name))
add_devices(devices)
return True
# pylint: disable=too-many-instance-attributes, import-error, abstract-method

View File

@ -9,13 +9,12 @@ import logging
import voluptuous as vol
import homeassistant.components.mqtt as mqtt
from homeassistant.const import CONF_DEVICES
from homeassistant.components.mqtt import CONF_QOS
import homeassistant.helpers.config_validation as cv
DEPENDENCIES = ['mqtt']
CONF_DEVICES = 'devices'
_LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = mqtt.MQTT_BASE_PLATFORM_SCHEMA.extend({

View File

@ -1,25 +1,28 @@
"""
CEC component.
Requires libcec + Python bindings.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/hdmi_cec/
"""
import logging
import voluptuous as vol
from homeassistant.const import EVENT_HOMEASSISTANT_START
from homeassistant.const import (EVENT_HOMEASSISTANT_START, CONF_DEVICES)
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
_CEC = None
DOMAIN = 'hdmi_cec'
SERVICE_SELECT_DEVICE = 'select_device'
SERVICE_POWER_ON = 'power_on'
SERVICE_STANDBY = 'standby'
CONF_DEVICES = 'devices'
_LOGGER = logging.getLogger(__name__)
ATTR_DEVICE = 'device'
DOMAIN = 'hdmi_cec'
MAX_DEPTH = 4
SERVICE_POWER_ON = 'power_on'
SERVICE_SELECT_DEVICE = 'select_device'
SERVICE_STANDBY = 'standby'
# pylint: disable=unnecessary-lambda
DEVICE_SCHEMA = vol.Schema({
@ -27,7 +30,6 @@ DEVICE_SCHEMA = vol.Schema({
cv.string)
})
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_DEVICES): DEVICE_SCHEMA
@ -56,17 +58,14 @@ def setup(hass, config):
"""Setup CEC capability."""
global _CEC
# cec is only available if libcec is properly installed
# and the Python bindings are accessible.
try:
import cec
except ImportError:
_LOGGER.error("libcec must be installed")
return False
# Parse configuration into a dict of device name
# to physical address represented as a list of
# four elements.
# Parse configuration into a dict of device name to physical address
# represented as a list of four elements.
flat = {}
for pair in parse_mapping(config[DOMAIN].get(CONF_DEVICES, {})):
flat[pair[0]] = pad_physical_address(pair[1])
@ -78,7 +77,7 @@ def setup(hass, config):
cfg.bMonitorOnly = 1
cfg.clientVersion = cec.LIBCEC_VERSION_CURRENT
# Set up CEC adapter.
# Setup CEC adapter.
_CEC = cec.ICECAdapter.Create(cfg)
def _power_on(call):

View File

@ -31,6 +31,7 @@ CONF_CODE = 'code'
CONF_CONDITION = 'condition'
CONF_CUSTOMIZE = 'customize'
CONF_DEVICE = 'device'
CONF_DEVICES = 'devices'
CONF_DISARM_AFTER_TRIGGER = 'disarm_after_trigger'
CONF_DISPLAY_OPTIONS = 'display_options'
CONF_ELEVATION = 'elevation'