From 24d412938e8506d09cffe382b9a5c8cb599af9d8 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Thu, 1 Sep 2016 22:04:00 +0200 Subject: [PATCH] Use voluptuous for HDMI CEC & CONF_DEVICES constants (#3107) --- .../components/climate/eq3btsmart.py | 5 +-- .../components/device_tracker/mqtt.py | 3 +- homeassistant/components/hdmi_cec.py | 33 +++++++++---------- homeassistant/const.py | 1 + 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/climate/eq3btsmart.py b/homeassistant/components/climate/eq3btsmart.py index 01114972811..ee7fb7050f5 100644 --- a/homeassistant/components/climate/eq3btsmart.py +++ b/homeassistant/components/climate/eq3btsmart.py @@ -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 diff --git a/homeassistant/components/device_tracker/mqtt.py b/homeassistant/components/device_tracker/mqtt.py index 0998e227857..2318eb44dd1 100644 --- a/homeassistant/components/device_tracker/mqtt.py +++ b/homeassistant/components/device_tracker/mqtt.py @@ -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({ diff --git a/homeassistant/components/hdmi_cec.py b/homeassistant/components/hdmi_cec.py index 89cbe789c58..4fab7f84bd3 100644 --- a/homeassistant/components/hdmi_cec.py +++ b/homeassistant/components/hdmi_cec.py @@ -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): diff --git a/homeassistant/const.py b/homeassistant/const.py index ce46c62850b..5b23fb5395d 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -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'