def test_platform_specific_config_validation(self): """Test platform that specifies config.""" platform_schema = PLATFORM_SCHEMA.extend({ 'valid': True, }, extra=vol.PREVENT_EXTRA) loader.set_component( 'switch.platform_a', MockPlatform('comp_b', platform_schema=platform_schema)) assert not bootstrap.setup_component(self.hass, 'switch', { 'switch': { 'platform': 'platform_a', 'invalid': True } }) assert not bootstrap.setup_component(self.hass, 'switch', { 'switch': { 'platform': 'platform_a', 'valid': True, 'invalid_extra': True, } }) assert bootstrap.setup_component(self.hass, 'switch', { 'switch': { 'platform': 'platform_a', 'valid': True } })
def test_validate_platform_config(self): """Test validating platform configuration.""" platform_schema = PLATFORM_SCHEMA.extend({ 'hello': str, }) loader.set_component( 'platform_conf', MockModule('platform_conf', platform_schema=platform_schema)) loader.set_component( 'platform_conf.whatever', MockPlatform('whatever')) assert not bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': None }) assert not bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': {} }) assert not bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'hello': 'world', 'invalid': 'extra', } }) assert not bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'whatever', 'hello': 'world', }, 'platform_conf 2': { 'invalid': True } }) assert not bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'not_existing', 'hello': 'world', } }) assert bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'whatever', 'hello': 'world', } }) assert bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': [{ 'platform': 'whatever', 'hello': 'world', }] })
def test_validate_platform_config_2(self, caplog): """Test component PLATFORM_SCHEMA_BASE prio over PLATFORM_SCHEMA.""" platform_schema = PLATFORM_SCHEMA.extend({ 'hello': str, }) platform_schema_base = PLATFORM_SCHEMA_BASE.extend({ 'hello': 'world', }) loader.set_component( self.hass, 'platform_conf', MockModule('platform_conf', platform_schema=platform_schema, platform_schema_base=platform_schema_base)) loader.set_component( self.hass, 'platform_conf.whatever', MockPlatform('whatever', platform_schema=platform_schema)) with assert_setup_component(1): assert setup.setup_component(self.hass, 'platform_conf', { # fail: no extra keys allowed in platform schema 'platform_conf': { 'platform': 'whatever', 'hello': 'world', 'invalid': 'extra', } }) assert caplog.text.count('Your configuration contains ' 'extra keys') == 1 self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('platform_conf') with assert_setup_component(1): assert setup.setup_component(self.hass, 'platform_conf', { # pass 'platform_conf': { 'platform': 'whatever', 'hello': 'world', }, # fail: key hello violates component platform_schema_base 'platform_conf 2': { 'platform': 'whatever', 'hello': 'there' } }) self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('platform_conf')
def test_platform_specific_config_validation(self): """Test platform that specifies config.""" platform_schema = PLATFORM_SCHEMA.extend({ 'valid': True, }, extra=vol.PREVENT_EXTRA) mock_setup = mock.MagicMock(spec_set=True) loader.set_component( self.hass, 'switch.platform_a', MockPlatform(platform_schema=platform_schema, setup_platform=mock_setup)) with assert_setup_component(0, 'switch'): assert setup.setup_component(self.hass, 'switch', { 'switch': { 'platform': 'platform_a', 'invalid': True } }) assert mock_setup.call_count == 0 self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('switch') with assert_setup_component(0): assert setup.setup_component(self.hass, 'switch', { 'switch': { 'platform': 'platform_a', 'valid': True, 'invalid_extra': True, } }) assert mock_setup.call_count == 0 self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('switch') with assert_setup_component(1): assert setup.setup_component(self.hass, 'switch', { 'switch': { 'platform': 'platform_a', 'valid': True } }) assert mock_setup.call_count == 1
'SS': 'Snow Showers', 'SU': 'Sunny', 'SW': 'Strong Winds', 'TL': 'Thundery Showers', 'WC': 'Windy, Cloudy', 'WD': 'Windy', 'WF': 'Windy, Fair', 'WR': 'Windy, Rain', 'WS': 'Windy, Showers', } INV_CONDITION_DETAILS = {v: k for k, v in CONDITION_DETAILS.items()} PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_AREA): cv.string, vol.Optional(CONF_RESOURCE, default=DEFAULT_RESOURCE): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, }) @asyncio.coroutine async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the Web scrape sensor.""" _LOGGER.info('SGNEAWEB loaded') name = config.get(CONF_NAME) resource = config.get(CONF_RESOURCE) area = config.get(CONF_AREA) method = 'GET' payload = None
ATTR_LAST_THUMBNAIL = "last_thumbnail" ATTR_DURATION = "duration" ATTR_TIME_ZONE = "time_zone" ATTR_WIFI = "wifi" ATTR_CORDED = "corded" CONF_FFMPEG_ARGUMENTS = "ffmpeg_arguments" POWERSAVE_MODE_MAPPING = { 1: "best_battery_life", 2: "optimized", 3: "best_video" } PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_FFMPEG_ARGUMENTS): cv.string, }) CAMERA_SERVICE_SCHEMA = vol.Schema( {vol.Required(ATTR_ENTITY_ID): cv.comp_entity_ids}) CAMERA_SERVICE_SNAPSHOT = CAMERA_SERVICE_SCHEMA.extend( {vol.Required(ATTR_FILENAME): cv.template}) SERVICE_REQUEST_SNAPSHOT = "camera_request_snapshot" SERVICE_REQUEST_SNAPSHOT_TO_FILE = "camera_request_snapshot_to_file" SERVICE_REQUEST_VIDEO_TO_FILE = "camera_request_video_to_file" SERVICE_STOP_ACTIVITY = "camera_stop_activity" SERVICE_RECORD_START = "camera_start_recording" SERVICE_RECORD_STOP = "camera_stop_recording" OLD_SERVICE_REQUEST_SNAPSHOT = "aarlo_request_snapshot" OLD_SERVICE_REQUEST_SNAPSHOT_TO_FILE = "aarlo_request_snapshot_to_file"
ATTR_MESSAGE = 'message' ATTR_LOCALE = 'locale' DEFAULT_LOCALE = 'en' DEFAULT_NAME = 'Fully Kiosk Browser' DEFAULT_PORT = 2323 DATA_ENTITIES = 'fully_kiosk_entities' MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=15) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, vol.Required(CONF_PASSWORD): cv.string }) NO_PARAMETERS_SCHEMA = vol.Schema({ vol.Optional(ATTR_ENTITY_ID): cv.entity_ids, }) SCHEMA_SERVICE_LOAD_START_URL = NO_PARAMETERS_SCHEMA SCHEMA_SERVICE_SCREENSAVER_START = NO_PARAMETERS_SCHEMA SCHEMA_SERVICE_SCREENSAVER_STOP = NO_PARAMETERS_SCHEMA SCHEMA_SERVICE_SAY = vol.Schema({ vol.Optional(ATTR_ENTITY_ID):
vol.Optional(CONF_VALUE_TEMPLATE, default=None): cv.template, vol.Optional(CONF_ICON_TEMPLATE, default=None): cv.template, vol.Optional(CONF_ENTITY_PICTURE_TEMPLATE, default=None): cv.template, vol.Optional(CONF_LEVEL_ACTION, default=None): cv.SCRIPT_SCHEMA, vol.Optional(CONF_LEVEL_TEMPLATE, default=None): cv.template, vol.Optional(CONF_FRIENDLY_NAME): cv.string, vol.Optional(CONF_ENTITY_ID): cv.entity_ids }) LIGHT_SCHEMA = vol.All( cv.deprecated(CONF_ENTITY_ID), LIGHT_SCHEMA, ) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_LIGHTS): vol.Schema({cv.slug: LIGHT_SCHEMA}), }) @asyncio.coroutine def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Set up the Template Lights.""" lights = [] for device, device_config in config[CONF_LIGHTS].items(): friendly_name = device_config.get(CONF_FRIENDLY_NAME, device) state_template = device_config[CONF_VALUE_TEMPLATE] icon_template = device_config.get(CONF_ICON_TEMPLATE) entity_picture_template = device_config.get( CONF_ENTITY_PICTURE_TEMPLATE) on_action = device_config[CONF_ON_ACTION]
ATTR_DOMINENTPOL = 'dominentpol' ATTR_HUMIDITY = 'humidity' ATTR_NITROGEN_DIOXIDE = 'nitrogen_dioxide' ATTR_OZONE = 'ozone' ATTR_PARTICLE = 'particle' ATTR_PRESSURE = 'pressure' ATTR_TIME = 'time' ATTRIBUTION = 'Data provided by the World Air Quality Index project' CONF_LOCATIONS = 'locations' MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=10) SENSOR_TYPES = {'aqi': ['AQI', '0-300+', 'mdi:cloud']} PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Required(CONF_LOCATIONS): cv.ensure_list}) def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the requested World Air Quality Index locations.""" import pwaqi dev = [] for location_name in config.get(CONF_LOCATIONS): station_ids = pwaqi.findStationCodesByCity(location_name) _LOGGER.error('The following stations were returned: %s', station_ids) for station in station_ids: dev.append(WaqiSensor(WaqiData(station), station)) add_devices(dev)
"co2": [ATTR_CARBON_DIOXIDE, CONCENTRATION_PARTS_PER_MILLION, "mdi:molecule-co2"], "voc": [ ATTR_VOLATILE_ORGANIC_COMPOUNDS, CONCENTRATION_PARTS_PER_BILLION, "mdi:cloud", ], "allpollu": [ATTR_FOOBOT_INDEX, PERCENTAGE, "mdi:percent"], } SCAN_INTERVAL = timedelta(minutes=10) PARALLEL_UPDATES = 1 TIMEOUT = 10 PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Required(CONF_TOKEN): cv.string, vol.Required(CONF_USERNAME): cv.string} ) async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the devices associated with the account.""" token = config.get(CONF_TOKEN) username = config.get(CONF_USERNAME) client = FoobotClient( token, username, async_get_clientsession(hass), timeout=TIMEOUT ) dev = [] try: devices = await client.get_devices() _LOGGER.debug("The following devices were found: %s", devices)
ATTR_OZONE = 'ozone' ATTR_PARTICLE = 'particle' ATTR_PRESSURE = 'pressure' ATTR_TIME = 'time' ATTRIBUTION = 'Data provided by the World Air Quality Index project' CONF_LOCATIONS = 'locations' MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=10) SENSOR_TYPES = { 'aqi': ['AQI', '0-300+', 'mdi:cloud'] } PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_LOCATIONS): cv.ensure_list }) def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the requested World Air Quality Index locations.""" import pwaqi dev = [] for location_name in config.get(CONF_LOCATIONS): station_ids = pwaqi.findStationCodesByCity(location_name) _LOGGER.error('The following stations were returned: %s', station_ids) for station in station_ids: dev.append(WaqiSensor(WaqiData(station), station)) add_devices(dev)
class DOMAIN_TYPE: WEATHER = 1 CLIMATE = 2 OTHER = 3 _LOGGER = logging.getLogger(__name__) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_ENTITY_ID): cv.entity_id, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_AVERAGE_INTERVAL): cv.time_period, vol.Optional(CONF_VALUE_DELTA, default=0): vol.Any(int, float), vol.Optional(CONF_UPDATE_INTERVAL): cv.time_period, vol.Optional(CONF_PRECISION, default=1): int, }) # pylint: disable=unused-argument async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up platform.""" name = config.get(CONF_NAME)
vol.Required(CONF_OFF_ACTION): cv.SCRIPT_SCHEMA, vol.Optional(CONF_VALUE_TEMPLATE): cv.template, vol.Optional(CONF_ICON_TEMPLATE): cv.template, vol.Optional(CONF_ENTITY_PICTURE_TEMPLATE): cv.template, vol.Optional(CONF_AVAILABILITY_TEMPLATE): cv.template, vol.Optional(CONF_LEVEL_ACTION): cv.SCRIPT_SCHEMA, vol.Optional(CONF_LEVEL_TEMPLATE): cv.template, vol.Optional(CONF_FRIENDLY_NAME): cv.string, vol.Optional(CONF_ENTITY_ID): cv.entity_ids, vol.Optional(CONF_TEMPERATURE_TEMPLATE): cv.template, vol.Optional(CONF_TEMPERATURE_ACTION): cv.SCRIPT_SCHEMA, vol.Optional(CONF_COLOR_TEMPLATE): cv.template, vol.Optional(CONF_COLOR_ACTION): cv.SCRIPT_SCHEMA, }) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Required(CONF_LIGHTS): cv.schema_with_slug_keys(LIGHT_SCHEMA)}) async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the Template Lights.""" lights = [] for device, device_config in config[CONF_LIGHTS].items(): friendly_name = device_config.get(CONF_FRIENDLY_NAME, device) state_template = device_config.get(CONF_VALUE_TEMPLATE) icon_template = device_config.get(CONF_ICON_TEMPLATE) entity_picture_template = device_config.get(
ATTR_SULFUR_DIOXIDE = 'sulfur_dioxide' ATTR_TIME = 'time' ATTRIBUTION = 'Data provided by the World Air Quality Index project' CONF_LOCATIONS = 'locations' CONF_STATIONS = 'stations' CONF_API_TOKEN = 'token' MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=10) SENSOR_TYPES = {'aqi': ['AQI', '0-300+', 'mdi:cloud']} PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_STATIONS): cv.ensure_list, vol.Required(CONF_API_TOKEN): cv.string, vol.Required(CONF_LOCATIONS): cv.ensure_list, }) def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the requested World Air Quality Index locations.""" import pwaqi dev = [] token = config.get(CONF_API_TOKEN) station_filter = config.get(CONF_STATIONS) for location_name in config.get(CONF_LOCATIONS): station_ids = pwaqi.findStationCodesByCity(location_name, token) _LOGGER.info("The following stations were returned: %s", station_ids)
ATTR_ENTITY_ID, CONF_NAME, CONF_TOKEN, CONF_ENTITY_ID, ) import time import wideq DEPENDENCIES = ['smartthinq'] LGE_AIRPURIFIER_DEVICES = 'lge_AirPurifier_devices' CONF_MAC = 'mac' PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_NAME): cv.string, vol.Required(CONF_MAC): cv.string, }) # For Air Purifier #----------------------------------------------------------- SUPPORT_SET_SPEED = 1 CONF_AIRFAST_MODE = 'airfast_mode' CONF_AIRREMOVAL_MODE = 'airremoval_mode' ATTR_SPEED_OFF = '꺼짐' ATTR_AIRREMOVAL_MODE = 'airremoval_mode' ATTR_AIRFAST_MODE = 'airfast_mode' ATTR_SPEED = 'speed' ATTR_SPEED_LIST = 'speed_list'
import homeassistant.helpers.config_validation as cv from homeassistant.components.lock import LockEntity from homeassistant.helpers.config_validation import (PLATFORM_SCHEMA) _LOGGER = logging.getLogger(__name__) CONF_NAME = "name" CONF_INITIAL_VALUE = "initial_value" CONF_INITIAL_AVAILABILITY = "initial_availability" DEFAULT_INITIAL_VALUE = "locked" DEFAULT_INITIAL_AVAILABILITY = True PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_NAME): cv.string, vol.Optional(CONF_INITIAL_VALUE, default=DEFAULT_INITIAL_VALUE): cv.string, vol.Optional(CONF_INITIAL_AVAILABILITY, default=DEFAULT_INITIAL_AVAILABILITY): cv.boolean, }) async def async_setup_platform(_hass, config, async_add_entities, _discovery_info=None): locks = [VirtualLock(config)] async_add_entities(locks, True) class VirtualLock(LockEntity): """Representation of a Virtual lock.""" def __init__(self, config): """Initialize the Virtual lock device.""" self._name = config.get(CONF_NAME)
from homeassistant.helpers.config_validation import (PLATFORM_SCHEMA) from homeassistant.helpers.event import track_point_in_time _LOGGER = logging.getLogger(__name__) ALLOW_OFF = False ON_FOR_DEFAULT = timedelta(seconds=1) CONF_NAME = "name" CONF_ON_FOR = "on_for" CONF_ALLOW_OFF = "allow_off" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_NAME): cv.string, vol.Optional(CONF_ON_FOR, default=ON_FOR_DEFAULT): vol.All(cv.time_period, cv.positive_timedelta), vol.Optional(CONF_ALLOW_OFF, default=ALLOW_OFF): cv.boolean, }) async def async_setup_platform(_hass, config, async_add_entities, _discovery_info=None): switches = [] switches.append(MomentarySwitch(config)) async_add_entities(switches, True) class MomentarySwitch(SwitchDevice):
import aiohttp import asyncio import homeassistant.util as util from aiohttp.hdrs import AUTHORIZATION from datetime import timedelta, datetime from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.const import CONF_NAME, CONF_ENTITY_ID, STATE_OFF, STATE_ON, STATE_UNKNOWN from homeassistant.helpers.entity import Entity from homeassistant.helpers.config_validation import PLATFORM_SCHEMA MIN_TIME_BETWEEN_SCANS = timedelta(seconds=15) MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_ENTITY_ID): cv.string, vol.Required(CONF_NAME): cv.string, }) _LOGGER = logging.getLogger(__name__) def setup_platform(hass, config, add_devices, discovery_info=None): entity_id = config.get(CONF_ENTITY_ID) name = config.get(CONF_NAME) add_devices([ItWillRain(hass, entity_id, name)]) class ItWillRain(Entity): """Representation of a Sensor.""" def __init__(self, hass, entity_id, name):
CONF_LEVEL_TEMPLATE = 'level_template' LIGHT_SCHEMA = vol.Schema({ vol.Required(CONF_ON_ACTION): cv.SCRIPT_SCHEMA, vol.Required(CONF_OFF_ACTION): cv.SCRIPT_SCHEMA, vol.Optional(CONF_VALUE_TEMPLATE): cv.template, vol.Optional(CONF_ICON_TEMPLATE): cv.template, vol.Optional(CONF_ENTITY_PICTURE_TEMPLATE): cv.template, vol.Optional(CONF_LEVEL_ACTION): cv.SCRIPT_SCHEMA, vol.Optional(CONF_LEVEL_TEMPLATE): cv.template, vol.Optional(CONF_FRIENDLY_NAME): cv.string, vol.Optional(CONF_ENTITY_ID): cv.entity_ids }) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_LIGHTS): cv.schema_with_slug_keys(LIGHT_SCHEMA), }) async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the Template Lights.""" lights = [] for device, device_config in config[CONF_LIGHTS].items(): friendly_name = device_config.get(CONF_FRIENDLY_NAME, device) state_template = device_config.get(CONF_VALUE_TEMPLATE) icon_template = device_config.get(CONF_ICON_TEMPLATE) entity_picture_template = device_config.get( CONF_ENTITY_PICTURE_TEMPLATE) on_action = device_config[CONF_ON_ACTION]
def test_validate_platform_config(self): """Test validating platform configuration.""" platform_schema = PLATFORM_SCHEMA.extend({ 'hello': str, }) loader.set_component( 'platform_conf', MockModule('platform_conf', platform_schema=platform_schema)) loader.set_component('platform_conf.whatever', MockPlatform('whatever')) with assert_setup_component(0): assert setup.setup_component( self.hass, 'platform_conf', {'platform_conf': { 'hello': 'world', 'invalid': 'extra', }}) self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('platform_conf') with assert_setup_component(1): assert setup.setup_component( self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'whatever', 'hello': 'world', }, 'platform_conf 2': { 'invalid': True } }) self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('platform_conf') with assert_setup_component(0): assert setup.setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'not_existing', 'hello': 'world', } }) self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('platform_conf') with assert_setup_component(1): assert setup.setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'whatever', 'hello': 'world', } }) self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('platform_conf') with assert_setup_component(1): assert setup.setup_component(self.hass, 'platform_conf', { 'platform_conf': [{ 'platform': 'whatever', 'hello': 'world', }] }) self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('platform_conf') # Any falsey platform config will be ignored (None, {}, etc) with assert_setup_component(0) as config: assert setup.setup_component(self.hass, 'platform_conf', {'platform_conf': None}) assert 'platform_conf' in self.hass.config.components assert not config['platform_conf'] # empty assert setup.setup_component(self.hass, 'platform_conf', {'platform_conf': {}}) assert 'platform_conf' in self.hass.config.components assert not config['platform_conf'] # empty
CONF_VISIBILITY_TEMPLATE = "visibility_template" CONF_FORECAST_TEMPLATE = "forecast_template" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_NAME): cv.string, vol.Required(CONF_CONDITION_TEMPLATE): cv.template, vol.Required(CONF_TEMPERATURE_TEMPLATE): cv.template, vol.Required(CONF_HUMIDITY_TEMPLATE): cv.template, vol.Optional(CONF_ATTRIBUTION_TEMPLATE): cv.template, vol.Optional(CONF_PRESSURE_TEMPLATE): cv.template, vol.Optional(CONF_WIND_SPEED_TEMPLATE): cv.template, vol.Optional(CONF_WIND_BEARING_TEMPLATE): cv.template, vol.Optional(CONF_OZONE_TEMPLATE): cv.template, vol.Optional(CONF_VISIBILITY_TEMPLATE): cv.template, vol.Optional(CONF_FORECAST_TEMPLATE): cv.template, vol.Optional(CONF_UNIQUE_ID): cv.string, }) async def async_setup_platform(
DEFAULT_INITIAL_VALUE = "on" DEFAULT_INITIAL_BRIGHTNESS = 255 DEFAULT_SUPPORT_COLOR = False DEFAULT_INITIAL_COLOR = [0,100] DEFAULT_SUPPORT_COLOR_TEMP = False DEFAULT_INITIAL_COLOR_TEMP = 240 DEFAULT_SUPPORT_WHITE_VALUE = False DEFAULT_INITIAL_WHITE_VALUE = 240 PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_NAME): cv.string, vol.Optional(CONF_INITIAL_VALUE, default=DEFAULT_INITIAL_VALUE): cv.string, vol.Optional(CONF_INITIAL_BRIGHTNESS, default=DEFAULT_INITIAL_BRIGHTNESS): cv.byte, vol.Optional(CONF_SUPPORT_COLOR, default=DEFAULT_SUPPORT_COLOR): cv.boolean, vol.Optional(CONF_INITIAL_COLOR, default=DEFAULT_INITIAL_COLOR): cv.ensure_list, vol.Optional(CONF_SUPPORT_COLOR_TEMP, default=DEFAULT_SUPPORT_COLOR_TEMP): cv.boolean, vol.Optional(CONF_INITIAL_COLOR_TEMP, default=DEFAULT_INITIAL_COLOR_TEMP): cv.byte, vol.Optional(CONF_SUPPORT_WHITE_VALUE, default=DEFAULT_SUPPORT_WHITE_VALUE): cv.boolean, vol.Optional(CONF_INITIAL_WHITE_VALUE, default=DEFAULT_INITIAL_WHITE_VALUE): cv.byte, }) async def async_setup_platform(_hass, config, async_add_entities, _discovery_info=None): lights = [VirtualLight(config)] async_add_entities(lights, True) class VirtualLight(LightEntity): def __init__(self, config):
CLIMATE_IP_DATA = 'climate_ip_data' ENTITIES = 'entities' DEFAULT_CLIMATE_IP_TEMP_MIN = 16 DEFAULT_CLIMATE_IP_TEMP_MAX = 32 DEFAULT_UPDATE_DELAY = 1.5 SERVICE_SET_CUSTOM_OPERATION = 'climate_ip_set_property' _LOGGER = logging.getLogger(__name__) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_IP_ADDRESS): cv.string, vol.Optional(CONF_TOKEN): cv.string, vol.Optional(CONF_MAC): cv.string, vol.Optional(CONFIG_DEVICE_FRIENDLY_NAME): cv.string, vol.Optional(CONFIG_DEVICE_NAME): cv.string, vol.Optional(CONF_CERT, default=DEFAULT_CONF_CERT_FILE): cv.string, vol.Optional(CONF_CONFIG_FILE, default=DEFAULT_CONF_CONFIG_FILE): cv.string, vol.Optional(CONF_TEMPERATURE_UNIT, default=DEFAULT_CONF_TEMP_UNIT): cv.string, vol.Optional(CONF_CONTROLLER, default=DEFAULT_CONF_CONTROLLER): cv.string, vol.Optional(CONF_DEBUG, default=False): cv.boolean, vol.Optional(CONFIG_DEVICE_POLL, default=""): cv.string, vol.Optional(CONFIG_DEVICE_UPDATE_DELAY, default=DEFAULT_UPDATE_DELAY): cv.string, }) async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): _LOGGER.setLevel(logging.INFO if config.get('debug', False) else logging.ERROR) _LOGGER.info("climate_ip: async setup platform") try: device_controller = create_controller(config.get(CONF_CONTROLLER), config, _LOGGER) except:
# "water_strong_w", # timeout # "water_temp_t", # timeout # "water_temp_w", # timeout # "fw_ver", # => [1021] ] } STATE_OCCUPIED = "occupied" SUCCESS = ["ok"] PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_HOST): cv.string, vol.Required(CONF_TOKEN): vol.All(cv.string, vol.Length(min=32, max=32)), vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_MODEL): vol.In([MODEL_TOILETLID_XJX_TOILET_PRO]), }, extra=vol.ALLOW_EXTRA, ) SERVICE_SEND_COMMAND = "send_command" SERVICE_SELF_CLEAN_ON = "self_clean_on" SERVICE_SELF_CLEAN_OFF = "self_clean_off" SERVICE_LED_OFF = "led_on" SERVICE_LED_ON = "led_off" ATTR_COMMAND = "command" ATTR_PARAMS = "params" TOILETLID_SERVICE_SCHEMA = vol.Schema( {vol.Optional(ATTR_ENTITY_ID): cv.entity_ids})
| SUPPORT_VOLUME_STEP | SUPPORT_TURN_ON | SUPPORT_PAUSE | SUPPORT_SELECT_SOURCE) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string, vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string, vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean, vol.Optional(CONF_USE_CHANNEL_ICON, default=DEFAULT_USE_CHANNEL_ICON): cv.boolean, vol.Optional(CONF_DEEP_STANDBY, default=DEFAULT_DEEP_STANDBY): cv.boolean, vol.Optional(CONF_MAC_ADDRESS, default=DEFAULT_MAC_ADDRESS): cv.string, vol.Optional(CONF_SOURCE_BOUQUET, default=DEFAULT_SOURCE_BOUQUET): cv.string, }) def setup_platform(hass, config, add_devices, discovery_info=None): """Set up of an enigma2 media player.""" if discovery_info:
FUEL_TYPES = [ "Benzina", "Benzina speciale", "Diesel", "Diesel speciale", "GPL", "Metano", ] SCAN_INTERVAL = timedelta(minutes=120) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_STATION): cv.string, vol.Optional(CONF_NAME, None): cv.string, vol.Optional(CONF_TYPES, None): vol.All(cv.ensure_list, [vol.In(FUEL_TYPES)]), } ) def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the PrezziBenzina sensor platform.""" station = config[CONF_STATION] name = config.get(CONF_NAME) types = config.get(CONF_TYPES) client = PrezziBenzinaPy() dev = [] info = client.get_by_id(station)
DEFAULT_COMMAND_TEMPLATE = "{{action}}" DEFAULT_TRIGGER_TIME = timedelta(seconds=60) DEFAULT_HOME = 'home' DEFAULT_NIGHT = 'night' DEFAULT_ALARM_VOLUME = '8' PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_CODE): cv.string, vol.Optional(CONF_CODE_ARM_REQUIRED, default=True): cv.boolean, vol.Optional(CONF_CODE_DISARM_REQUIRED, default=True): cv.boolean, vol.Optional(CONF_COMMAND_TEMPLATE, default=DEFAULT_COMMAND_TEMPLATE): cv.template, vol.Optional(CONF_HOME_MODE_NAME, default=DEFAULT_HOME): cv.string, vol.Optional(CONF_AWAY_MODE_NAME, default=ARMED): cv.string, vol.Optional(CONF_NIGHT_MODE_NAME, default=DEFAULT_NIGHT): cv.string, vol.Optional(CONF_ALARM_VOLUME, default=DEFAULT_ALARM_VOLUME): cv.string, vol.Optional(CONF_TRIGGER_TIME, default=DEFAULT_TRIGGER_TIME): vol.All(cv.time_period, cv.positive_timedelta), }) ATTR_MODE = 'mode' ATTR_VOLUME = 'volume' ATTR_DURATION = 'duration' ATTR_TIME_ZONE = 'time_zone'
PRESET_MODES = [ PRESET_NONE, PRESET_COMFORT, PRESET_ECO, PRESET_AWAY ] HVAC_MODES = [ HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_AUTO ] MIN_TEMPERATURE = 7 MAX_TEMPERATURE = 40 _LOGGER = logging.getLogger(__name__) # Validation of the user's configuration PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_IP_ADDRESS, default='discover'): cv.string, }) def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Awesome heater platform.""" # Assign configuration variables. The configuration check takes care they are # present. host = config.get(CONF_HOST) ip = config.get(CONF_IP_ADDRESS) # Setup connection with devices/cloud if ip == 'discover': _LOGGER.info("discovering and connecting to %s", host) hub = nobo(serial=host) else:
import tplinkrouter import logging import re import voluptuous as vol from homeassistant.helpers.entity import Entity from homeassistant.helpers.config_validation import (PLATFORM_SCHEMA) from homeassistant.const import (CONF_HOST, CONF_PASSWORD, CONF_USERNAME) import homeassistant.helpers.config_validation as cv _LOGGER = logging.getLogger(__name__) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string }) def setup_platform(_hass, config, add_entities, _discovery_info=None): router = tplinkrouter.C50(config.get(CONF_HOST), config.get(CONF_USERNAME), config.get(CONF_PASSWORD), _LOGGER) sensors = [] for d in router.get_clients().values(): sensors.append(TPLinkClient(router, d, _hass)) add_entities(sensors) class TPLinkClient(Entity): """TP-Link Router Client Sensor""" def __init__(self, router, device, hass): self.router = router
def check_period_keys(conf): """Ensure maximum 2 of CONF_PERIOD_KEYS are provided.""" count = sum(param in conf for param in CONF_PERIOD_KEYS) if (count == 1 and CONF_DURATION not in conf) or count > 2: raise vol.Invalid("You must provide none, only " + CONF_DURATION + " or maximum 2 of the following: " ", ".join(CONF_PERIOD_KEYS)) return conf PLATFORM_SCHEMA = vol.All( PLATFORM_SCHEMA.extend({ vol.Required(CONF_ENTITIES): cv.entity_ids, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_START): cv.template, vol.Optional(CONF_END): cv.template, vol.Optional(CONF_DURATION): cv.time_period, vol.Optional(CONF_PRECISION, default=2): int, vol.Optional(CONF_PROCESS_UNDEF_AS): float, }), check_period_keys, ) # pylint: disable=unused-argument async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up platform.""" # Print startup message
from . import COMPONENT_ATTRIBUTION, COMPONENT_DATA, COMPONENT_BRAND, COMPONENT_DOMAIN _LOGGER = logging.getLogger(__name__) DEPENDENCIES = [COMPONENT_DOMAIN] # sensor_type [ description, class, attribute ] SENSOR_TYPES = { 'sound': ['Sound', 'sound', 'audioDetected'], 'motion': ['Motion', 'motion', 'motionDetected'], 'ding': ['Ding', 'occupancy', 'buttonPressed'], 'cry': ['Cry', 'sound', 'babyCryDetection'], } PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_MONITORED_CONDITIONS, default=list(SENSOR_TYPES)): vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]), }) async def async_setup_platform(hass, config, async_add_entities, _discovery_info=None): """Set up an Arlo IP sensor.""" arlo = hass.data.get(COMPONENT_DATA) if not arlo: return sensors = [] for sensor_type in config.get(CONF_MONITORED_CONDITIONS): for camera in arlo.cameras:
'pm': [ATTR_PM2_5, 'µg/m3', 'mdi:cloud'], 'tmp': [ATTR_TEMPERATURE, TEMP_CELSIUS, 'mdi:thermometer'], 'hum': [ATTR_HUMIDITY, '%', 'mdi:water-percent'], 'co2': [ATTR_CARBON_DIOXIDE, 'ppm', 'mdi:periodic-table-co2'], 'voc': [ATTR_VOLATILE_ORGANIC_COMPOUNDS, 'ppb', 'mdi:cloud'], 'allpollu': [ATTR_FOOBOT_INDEX, '%', 'mdi:percent']} SCAN_INTERVAL = timedelta(minutes=10) PARALLEL_UPDATES = 1 TIMEOUT = 10 PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_TOKEN): cv.string, vol.Required(CONF_USERNAME): cv.string, }) async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the devices associated with the account.""" from foobot_async import FoobotClient token = config.get(CONF_TOKEN) username = config.get(CONF_USERNAME) client = FoobotClient(token, username, async_get_clientsession(hass), timeout=TIMEOUT) dev = []
def test_validate_platform_config(self, caplog): """Test validating platform configuration.""" platform_schema = PLATFORM_SCHEMA.extend({ 'hello': str, }) platform_schema_base = PLATFORM_SCHEMA_BASE.extend({ }) loader.set_component( self.hass, 'platform_conf', MockModule('platform_conf', platform_schema_base=platform_schema_base)) loader.set_component( self.hass, 'platform_conf.whatever', MockPlatform('whatever', platform_schema=platform_schema)) with assert_setup_component(1): assert setup.setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'whatever', 'hello': 'world', 'invalid': 'extra', } }) assert caplog.text.count('Your configuration contains ' 'extra keys') == 1 self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('platform_conf') with assert_setup_component(2): assert setup.setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'whatever', 'hello': 'world', }, 'platform_conf 2': { 'platform': 'whatever', 'invalid': True } }) assert caplog.text.count('Your configuration contains ' 'extra keys') == 2 self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('platform_conf') with assert_setup_component(0): assert setup.setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'not_existing', 'hello': 'world', } }) self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('platform_conf') with assert_setup_component(1): assert setup.setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'whatever', 'hello': 'world', } }) self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('platform_conf') with assert_setup_component(1): assert setup.setup_component(self.hass, 'platform_conf', { 'platform_conf': [{ 'platform': 'whatever', 'hello': 'world', }] }) self.hass.data.pop(setup.DATA_SETUP) self.hass.config.components.remove('platform_conf') # Any falsey platform config will be ignored (None, {}, etc) with assert_setup_component(0) as config: assert setup.setup_component(self.hass, 'platform_conf', { 'platform_conf': None }) assert 'platform_conf' in self.hass.config.components assert not config['platform_conf'] # empty assert setup.setup_component(self.hass, 'platform_conf', { 'platform_conf': {} }) assert 'platform_conf' in self.hass.config.components assert not config['platform_conf'] # empty
TOGGLE_FOR_DEFAULT = timedelta(seconds=1) CONF_NAME = "name" CONF_MODE = "mode" CONF_ON_FOR = "on_for" CONF_ALLOW_OFF = "allow_off" CONF_TOGGLE_FOR = "toggle_for" CONF_CANCELLABLE = "cancellable" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_NAME): cv.string, vol.Optional(CONF_MODE, default=MODE): cv.string, vol.Optional(CONF_ON_FOR, default=TOGGLE_FOR_DEFAULT): vol.All(cv.time_period, cv.positive_timedelta), vol.Optional(CONF_ALLOW_OFF, default=CANCELLABLE): cv.boolean, vol.Optional(CONF_TOGGLE_FOR, default=TOGGLE_FOR_DEFAULT): vol.All(cv.time_period, cv.positive_timedelta), vol.Optional(CONF_CANCELLABLE, default=CANCELLABLE): cv.boolean, }) async def async_setup_platform(_hass, config, async_add_entities, _discovery_info=None): switches = [MomentarySwitch(config)] async_add_entities(switches, True)
DEFAULT_DEEP_STANDBY = False DEFAULT_MAC_ADDRESS = '' DEFAULT_SOURCE_BOUQUET = '' SUPPORTED_ENIGMA2 = SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \ SUPPORT_TURN_OFF | SUPPORT_NEXT_TRACK | SUPPORT_STOP | \ SUPPORT_PREVIOUS_TRACK | SUPPORT_VOLUME_STEP | \ SUPPORT_TURN_ON | SUPPORT_PAUSE | SUPPORT_SELECT_SOURCE PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string, vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string, vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean, vol.Optional(CONF_USE_CHANNEL_ICON, default=DEFAULT_USE_CHANNEL_ICON): cv.boolean, vol.Optional(CONF_DEEP_STANDBY, default=DEFAULT_DEEP_STANDBY): cv.boolean, vol.Optional(CONF_MAC_ADDRESS, default=DEFAULT_MAC_ADDRESS): cv.string, vol.Optional(CONF_SOURCE_BOUQUET, default=DEFAULT_SOURCE_BOUQUET): cv.string, }) def setup_platform(hass, config, add_devices, discovery_info=None): """Set up of an enigma2 media player.""" if discovery_info: # Discovery gives us the streaming service port (8001) # which is not useful as OpenWebif never runs on that port. # So use the default port instead. config[CONF_PORT] = DEFAULT_PORT
ATTR_PRESSURE = 'pressure' ATTR_SULFUR_DIOXIDE = 'sulfur_dioxide' ATTR_TIME = 'time' ATTRIBUTION = 'Data provided by the World Air Quality Index project' CONF_LOCATIONS = 'locations' CONF_STATIONS = 'stations' MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=10) SENSOR_TYPES = { 'aqi': ['AQI', '0-300+', 'mdi:cloud'] } PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_STATIONS): cv.ensure_list, vol.Required(CONF_LOCATIONS): cv.ensure_list, }) def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the requested World Air Quality Index locations.""" import pwaqi dev = [] station_filter = config.get(CONF_STATIONS) for location_name in config.get(CONF_LOCATIONS): station_ids = pwaqi.findStationCodesByCity(location_name) _LOGGER.info("The following stations were returned: %s", station_ids) for station in station_ids: waqi_sensor = WaqiSensor(WaqiData(station), station) if (not station_filter) or \
from datetime import timedelta, datetime, timezone from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.const import CONF_NAME, STATE_UNKNOWN from homeassistant.helpers.entity import Entity from homeassistant.helpers.config_validation import PLATFORM_SCHEMA TIMEOUT = 10 MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10) MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=5) CONF_STOP_ID = 'stop_id' CONF_DIRECTION = 'direction' PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_STOP_ID): cv.string, vol.Required(CONF_DIRECTION): cv.string, vol.Required(CONF_NAME): cv.string }) _LOGGER = logging.getLogger(__name__) def addSecs(tm, secs): fulldate = tm + timedelta(seconds=secs) return fulldate def setup_platform(hass, config, add_devices, discovery_info=None): stop_id = config.get(CONF_STOP_ID) direction = config.get(CONF_DIRECTION) name = config.get(CONF_NAME)
) from homeassistant.const import STATE_OFF from homeassistant.helpers.config_validation import (PLATFORM_SCHEMA) _LOGGER = logging.getLogger(__name__) CONF_NAME = "name" CONF_SPEED = "speed" CONF_OSCILLATE = "oscillate" CONF_DIRECTION = "direction" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_NAME): cv.string, vol.Optional(CONF_SPEED, default=False): cv.boolean, vol.Optional(CONF_OSCILLATE, default=False): cv.boolean, vol.Optional(CONF_DIRECTION, default=False): cv.boolean, }) async def async_setup_platform(_hass, config, async_add_entities, _discovery_info=None): """Set up the Demo config entry.""" fans = [VirtualFan(config)] async_add_entities(fans, True)
def test_validate_platform_config(self): """Test validating platform configuration.""" platform_schema = PLATFORM_SCHEMA.extend({ 'hello': str, }) loader.set_component( 'platform_conf', MockModule('platform_conf', platform_schema=platform_schema)) loader.set_component( 'platform_conf.whatever', MockPlatform('whatever')) with assert_setup_component(0): assert bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'hello': 'world', 'invalid': 'extra', } }) self.hass.config.components.remove('platform_conf') with assert_setup_component(1): assert bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'whatever', 'hello': 'world', }, 'platform_conf 2': { 'invalid': True } }) self.hass.config.components.remove('platform_conf') with assert_setup_component(0): assert bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'not_existing', 'hello': 'world', } }) self.hass.config.components.remove('platform_conf') with assert_setup_component(1): assert bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'platform': 'whatever', 'hello': 'world', } }) self.hass.config.components.remove('platform_conf') with assert_setup_component(1): assert bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': [{ 'platform': 'whatever', 'hello': 'world', }] }) self.hass.config.components.remove('platform_conf') # Any falsey platform config will be ignored (None, {}, etc) with assert_setup_component(0) as config: assert bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': None }) assert 'platform_conf' in self.hass.config.components assert not config['platform_conf'] # empty assert bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': {} }) assert 'platform_conf' in self.hass.config.components assert not config['platform_conf'] # empty
vol.Required(CONF_OFF_ACTION): cv.SCRIPT_SCHEMA, vol.Optional(CONF_SET_SPEED_ACTION): cv.SCRIPT_SCHEMA, vol.Optional(CONF_SET_OSCILLATING_ACTION): cv.SCRIPT_SCHEMA, vol.Optional(CONF_SET_DIRECTION_ACTION): cv.SCRIPT_SCHEMA, vol.Optional( CONF_SPEED_LIST, default=[SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH] ): cv.ensure_list, vol.Optional(CONF_ENTITY_ID): cv.entity_ids }) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_FANS): vol.Schema({cv.slug: FAN_SCHEMA}), }) async def async_setup_platform( hass, config, async_add_devices, discovery_info=None ): """Set up the Template Fans.""" fans = [] for device, device_config in config[CONF_FANS].items(): friendly_name = device_config.get(CONF_FRIENDLY_NAME, device) state_template = device_config[CONF_VALUE_TEMPLATE] speed_template = device_config.get(CONF_SPEED_TEMPLATE) oscillating_template = device_config.get(
CONF_SIREN_DURATION = "siren_duration" CONF_SIREN_VOLUME = "siren_volume" CONF_SIREN_ALLOW_OFF = "siren_allow_off" CONF_SNAPSHOT = "snapshot" CONF_SNAPSHOT_TIMEOUT = "snapshot_timeout" CONF_DOORBELL_SILENCE = "doorbell_silence" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_SIRENS, default=SIRENS_DEFAULT): cv.boolean, vol.Optional(CONF_ALL_SIRENS, default=ALL_SIRENS_DEFAULT): cv.boolean, vol.Optional(CONF_SIREN_DURATION, default=SIREN_DURATION_DEFAULT): vol.All(cv.time_period, cv.positive_timedelta), vol.Optional(CONF_SIREN_VOLUME, default=SIREN_VOLUME_DEFAULT): cv.string, vol.Optional(CONF_SIREN_ALLOW_OFF, default=SIREN_ALLOW_OFF_DEFAULT): cv.boolean, vol.Optional(CONF_SNAPSHOT, default=SNAPSHOTS_DEFAULT): cv.boolean, vol.Optional(CONF_SNAPSHOT_TIMEOUT, default=SNAPSHOT_TIMEOUT_DEFAULT): vol.All(cv.time_period, cv.positive_timedelta), vol.Optional(CONF_DOORBELL_SILENCE, default=SILENT_MODE_DEFAULT): cv.boolean, }) async def async_setup_platform(hass, config, async_add_entities, _discovery_info=None): arlo = hass.data.get(COMPONENT_DATA)
_LOGGER = logging.getLogger(__name__) DOMAIN = 'miio_yeelink' SCAN_INTERVAL = timedelta(seconds=60) DEFAULT_NAME = 'Xiaomi Yeelink' CONF_MODEL = 'model' SPEED_FIERCE = 'fierce' SUPPORTED_DOMAINS = ['light', 'fan'] PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_HOST): cv.string, vol.Required(CONF_TOKEN): vol.All(cv.string, vol.Length(min=32, max=32)), vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_MODEL, default=''): cv.string, vol.Optional(CONF_MODE, default=''): cv.string, } ) XIAOMI_MIIO_SERVICE_SCHEMA = vol.Schema( { vol.Optional(ATTR_ENTITY_ID): cv.entity_ids, }, ) SERVICE_TO_METHOD_BASE = { 'send_command': { 'method': 'async_command', 'schema': XIAOMI_MIIO_SERVICE_SCHEMA.extend(
CONF_LEVEL_TEMPLATE = 'level_template' LIGHT_SCHEMA = vol.Schema({ vol.Required(CONF_ON_ACTION): cv.SCRIPT_SCHEMA, vol.Required(CONF_OFF_ACTION): cv.SCRIPT_SCHEMA, vol.Optional(CONF_VALUE_TEMPLATE): cv.template, vol.Optional(CONF_ICON_TEMPLATE): cv.template, vol.Optional(CONF_ENTITY_PICTURE_TEMPLATE): cv.template, vol.Optional(CONF_LEVEL_ACTION): cv.SCRIPT_SCHEMA, vol.Optional(CONF_LEVEL_TEMPLATE): cv.template, vol.Optional(CONF_FRIENDLY_NAME): cv.string, vol.Optional(CONF_ENTITY_ID): cv.entity_ids }) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_LIGHTS): vol.Schema({cv.slug: LIGHT_SCHEMA}), }) async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the Template Lights.""" lights = [] for device, device_config in config[CONF_LIGHTS].items(): friendly_name = device_config.get(CONF_FRIENDLY_NAME, device) state_template = device_config.get(CONF_VALUE_TEMPLATE) icon_template = device_config.get(CONF_ICON_TEMPLATE) entity_picture_template = device_config.get( CONF_ENTITY_PICTURE_TEMPLATE) on_action = device_config[CONF_ON_ACTION]
ICON = 'mdi:fuel' FUEL_TYPES = [ 'Benzina', "Benzina speciale", 'Diesel', "Diesel speciale", 'GPL', 'Metano', ] SCAN_INTERVAL = timedelta(minutes=120) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_STATION): cv.string, vol.Optional(CONF_NAME, None): cv.string, vol.Optional(CONF_TYPES, None): vol.All(cv.ensure_list, [vol.In(FUEL_TYPES)]), }) async def async_setup_platform( hass, config, async_add_entities, discovery_info=None): """Set up the PrezziBenzina sensor platform.""" from prezzibenzina import PrezziBenzinaPy station = config[CONF_STATION] name = config.get(CONF_NAME) types = config.get(CONF_TYPES) client = PrezziBenzinaPy() dev = []