How to use the voluptuous.Required function in voluptuous

To help you get started, we’ve selected a few voluptuous examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github home-assistant / home-assistant / homeassistant / components / mychevy / __init__.py View on Github external
NOTIFICATION_ID = "mychevy_website_notification"
NOTIFICATION_TITLE = "MyChevy website status"

_LOGGER = logging.getLogger(__name__)

MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=30)
ERROR_SLEEP_TIME = timedelta(minutes=30)

CONF_COUNTRY = "country"
DEFAULT_COUNTRY = "us"

CONFIG_SCHEMA = vol.Schema(
    {
        DOMAIN: vol.Schema(
            {
                vol.Required(CONF_USERNAME): cv.string,
                vol.Required(CONF_PASSWORD): cv.string,
                vol.Optional(CONF_COUNTRY, default=DEFAULT_COUNTRY): vol.All(
                    cv.string, vol.In(["us", "ca"])
                ),
            }
        )
    },
    extra=vol.ALLOW_EXTRA,
)


class EVSensorConfig:
    """The EV sensor configuration."""

    def __init__(
        self, name, attr, unit_of_measurement=None, icon=None, extra_attrs=None
github home-assistant / home-assistant / homeassistant / components / sensor / metoffice.py View on Github external
'name': ['Station Name', None],
    'weather': ['Weather', None],
    'temperature': ['Temperature', TEMP_CELSIUS],
    'feels_like_temperature': ['Feels Like Temperature', TEMP_CELSIUS],
    'wind_speed': ['Wind Speed', 'mph'],
    'wind_direction': ['Wind Direction', None],
    'wind_gust': ['Wind Gust', 'mph'],
    'visibility': ['Visibility', None],
    'visibility_distance': ['Visibility Distance', 'km'],
    'uv': ['UV', None],
    'precipitation': ['Probability of Precipitation', '%'],
    'humidity': ['Humidity', '%']
}

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_API_KEY): cv.string,
    vol.Required(CONF_MONITORED_CONDITIONS, default=[]):
        vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
    vol.Inclusive(CONF_LATITUDE, 'coordinates',
                  'Latitude and longitude must exist together'): cv.latitude,
    vol.Inclusive(CONF_LONGITUDE, 'coordinates',
                  'Latitude and longitude must exist together'): cv.longitude,
})


def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Met Office sensor platform."""
    import datapoint as dp

    api_key = config.get(CONF_API_KEY)
    latitude = config.get(CONF_LATITUDE, hass.config.latitude)
github home-assistant / home-assistant / homeassistant / components / dyson / fan.py View on Github external
vol.Required(ATTR_NIGHT_MODE): cv.boolean,
    }
)

SET_AUTO_MODE_SCHEMA = vol.Schema(
    {
        vol.Required(ATTR_ENTITY_ID): cv.entity_id,
        vol.Required(ATTR_AUTO_MODE): cv.boolean,
    }
)

SET_ANGLE_SCHEMA = vol.Schema(
    {
        vol.Required(ATTR_ENTITY_ID): cv.entity_id,
        vol.Required(ATTR_ANGLE_LOW): cv.positive_int,
        vol.Required(ATTR_ANGLE_HIGH): cv.positive_int,
    }
)

SET_FLOW_DIRECTION_FRONT_SCHEMA = vol.Schema(
    {
        vol.Required(ATTR_ENTITY_ID): cv.entity_id,
        vol.Required(ATTR_FLOW_DIRECTION_FRONT): cv.boolean,
    }
)

SET_TIMER_SCHEMA = vol.Schema(
    {
        vol.Required(ATTR_ENTITY_ID): cv.entity_id,
        vol.Required(ATTR_TIMER): cv.positive_int,
    }
)
github nstrelow / ha_philips_android_tv / custom_components / philips_android_tv / media_player.py View on Github external
DEFAULT_DEVICE = 'default'
DEFAULT_HOST = '127.0.0.1'
DEFAULT_MAC = 'aa:aa:aa:aa:aa:aa'
DEFAULT_USER = 'user'
DEFAULT_PASS = 'pass'
DEFAULT_NAME = 'Philips TV'
BASE_URL = 'https://{0}:1926/6/{1}'
TIMEOUT = 5.0
CONNFAILCOUNT = 5

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_HOST, default=DEFAULT_HOST): cv.string,
    vol.Required(CONF_MAC, default=DEFAULT_MAC): cv.string,
    vol.Required(CONF_USERNAME, default=DEFAULT_USER): cv.string,
    vol.Required(CONF_PASSWORD, default=DEFAULT_PASS): cv.string,
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
    vol.Optional(CONF_FAV_ONLY, default=False): cv.boolean
})

# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Philips 2016+ TV platform."""
    name = config.get(CONF_NAME)
    host = config.get(CONF_HOST)
    mac = config.get(CONF_MAC)
    user = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)
    favorite_only = config.get(CONF_FAV_ONLY)
    tvapi = PhilipsTVBase(host, user, password, favorite_only)
    add_devices([PhilipsTV(tvapi, name, mac)])
github hhaim / hass / custom_components / wb_irrigation / __init__.py View on Github external
vol.Required(ATTR_VALUE): vol.Coerce(float),
})


# pylint: disable=no-value-for-parameter
CONFIG_SCHEMA = vol.Schema(
    {
        DOMAIN: vol.Schema({
           vol.Required(CONF_API_KEY): cv.string,
           vol.Required(CONF_NAME): cv.string,
           vol.Optional(CONF_LATITUDE): cv.latitude,
           vol.Optional(CONF_LONGITUDE): cv.longitude,
           vol.Optional(CONF_ELEVATION): vol.Coerce(int),
           vol.Optional(CONF_DEBUG,default=False): cv.boolean,
           vol.Optional(CONF_EXTERNAL_SENSOR_RAIN_1h):cv.string,
           vol.Required(CONF_RAIN_FACTOR): vol.Coerce(float),
           vol.Required(CONF_MAX_EV): vol.Coerce(float),
           vol.Required(CONF_MIN_EV): vol.Coerce(float),
           vol.Optional(CONF_TAPS): vol.All(
                    cv.ensure_list, [_TAP_SCHEMA]),
        }),
    },
    extra=vol.ALLOW_EXTRA,
)

DEPENDENCIES = ['discovery']

def  fix_name(cfg,name):
    return cfg[CONF_NAME]+"_"+name

async def async_setup(hass, config):
    """Set up the platform."""
github home-assistant / home-assistant / homeassistant / components / group / cover.py View on Github external
# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
# mypy: no-check-untyped-defs

_LOGGER = logging.getLogger(__name__)

KEY_OPEN_CLOSE = "open_close"
KEY_STOP = "stop"
KEY_POSITION = "position"

DEFAULT_NAME = "Cover Group"


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


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
    """Set up the Group Cover platform."""
    async_add_entities([CoverGroup(config[CONF_NAME], config[CONF_ENTITIES])])


class CoverGroup(CoverDevice):
    """Representation of a CoverGroup."""

    def __init__(self, name, entities):
        """Initialize a CoverGroup entity."""
        self._name = name
        self._is_closed = False
github regel / loudml / loudml / loudml / annotations.py View on Github external
from loudml.api import (
    Hook,
)

from voluptuous import (
    ALLOW_EXTRA,
    Optional,
    Required,
    Schema,
)


class AnnotationHook(Hook):
    CONFIG_SCHEMA = Schema({
        Required('type'): str,
        Optional('text'): str,
        # TODO: Add tags
    }, extra=ALLOW_EXTRA)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.text = self.config.get('text', '{desc}')
        assert self.source

    def on_anomaly_start(
        self,
        dt,
        score,
        predicted,
        observed,
        anomalies,
github ahodges9 / LedFx / ledfx / api / websocket.py View on Github external
import json
import logging
import asyncio
from aiohttp import web
import voluptuous as vol
from concurrent import futures
from ledfx.api import RestEndpoint
from ledfx.events import Event

_LOGGER = logging.getLogger(__name__)
MAX_PENDING_MESSAGES = 256

BASE_MESSAGE_SCHEMA = vol.Schema({
    vol.Required('id'): vol.Coerce(int),
    vol.Required('type'): str,
}, extra=vol.ALLOW_EXTRA)

# TODO: Have a more well defined registration and a more componetized solution.
# Could do something like have Device actually provide the handler for Device 
# related functionality. This would allow easy access to internal workings and
# events. 
websocket_handlers = {}
def websocket_handler(type):
    def function(func):
        websocket_handlers[type] = func
        return func
    return function

class WebsocketEndpoint(RestEndpoint):

    ENDPOINT_PATH = "/api/websocket"
github home-assistant / home-assistant / homeassistant / components / notify / nma.py View on Github external
import logging
import xml.etree.ElementTree as ET

import requests
import voluptuous as vol

from homeassistant.components.notify import (
    ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA, BaseNotificationService)
from homeassistant.const import CONF_API_KEY
import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)
_RESOURCE = 'https://www.notifymyandroid.com/publicapi/'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_API_KEY): cv.string,
})


def get_service(hass, config, discovery_info=None):
    """Get the NMA notification service."""
    parameters = {
        'apikey': config[CONF_API_KEY],
    }
    response = requests.get(
        '{}{}'.format(_RESOURCE, 'verify'), params=parameters, timeout=5)
    tree = ET.fromstring(response.content)

    if tree[0].tag == 'error':
        _LOGGER.error("Wrong API key supplied: %s", tree[0].text)
        return None
github home-assistant / home-assistant / homeassistant / components / satel_integra / __init__.py View on Github external
def is_alarm_code_necessary(value):
    """Check if alarm code must be configured."""
    if value.get(CONF_SWITCHABLE_OUTPUTS) and CONF_DEVICE_CODE not in value:
        raise vol.Invalid(
            "You need to specify alarm " " code to use switchable_outputs"
        )

    return value


CONFIG_SCHEMA = vol.Schema(
    {
        DOMAIN: vol.All(
            {
                vol.Required(CONF_HOST): cv.string,
                vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
                vol.Optional(CONF_DEVICE_CODE): cv.string,
                vol.Optional(CONF_DEVICE_PARTITIONS, default={}): {
                    vol.Coerce(int): PARTITION_SCHEMA
                },
                vol.Optional(CONF_ZONES, default={}): {vol.Coerce(int): ZONE_SCHEMA},
                vol.Optional(CONF_OUTPUTS, default={}): {vol.Coerce(int): ZONE_SCHEMA},
                vol.Optional(CONF_SWITCHABLE_OUTPUTS, default={}): {
                    vol.Coerce(int): EDITABLE_OUTPUT_SCHEMA
                },
            },
            is_alarm_code_necessary,
        )
    },
    extra=vol.ALLOW_EXTRA,
)