How to use the homeassistant.helpers.config_validation.string function in homeassistant

To help you get started, we’ve selected a few homeassistant 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 XKNX / xknx / home-assistant-plugin / custom_components / xknx / switch.py View on Github external
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
from homeassistant.const import CONF_ADDRESS, CONF_NAME
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv

from . import ATTR_DISCOVER_DEVICES, DATA_XKNX

CONF_STATE_ADDRESS = "state_address"

DEFAULT_NAME = "KNX Switch"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {
        vol.Required(CONF_ADDRESS): cv.string,
        vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
        vol.Optional(CONF_STATE_ADDRESS): cv.string,
    }
)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
    """Set up switch(es) for KNX platform."""
    if discovery_info is not None:
        async_add_entities_discovery(hass, discovery_info, async_add_entities)
    else:
        async_add_entities_config(hass, config, async_add_entities)


@callback
def async_add_entities_discovery(hass, discovery_info, async_add_entities):
    """Set up switches for KNX platform configured via xknx.yaml."""
    entities = []
github mcfrojd / hassio_lovelace_multiremote / custom_components / androidtv / media_player.py View on Github external
"spotify": "Spotify",
    "tvlauncher": "Homescreen",
    "youtube": "Youtube",
    "zatto": "Zattoo"
}

SUPPORT_ANDROIDTV = (SUPPORT_NEXT_TRACK | SUPPORT_PAUSE |
                     SUPPORT_PLAY | SUPPORT_PREVIOUS_TRACK |
                     SUPPORT_TURN_OFF | SUPPORT_TURN_ON |
                     SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_STEP |
                     SUPPORT_STOP)

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): vol.All(cv.port, cv.string),
    vol.Optional(CONF_ADBKEY): has_adb_files,
    vol.Optional(CONF_APPS, default=DEFAULT_APPS): dict,
    vol.Optional(CONF_ADB_SERVER_IP): cv.string,
    vol.Optional(
        CONF_ADB_SERVER_PORT, default=DEFAULT_ADB_SERVER_PORT): cv.port
})

ACTION_SERVICE = 'androidtv_action'
INTENT_SERVICE = 'androidtv_intent'
KEY_SERVICE = 'androidtv_key'

SERVICE_ACTION_SCHEMA = vol.Schema({
    vol.Required(ATTR_ENTITY_ID): cv.entity_ids,
    vol.Required('action'): vol.In(ACTIONS),
})
github home-assistant / home-assistant / homeassistant / components / snapcast / media_player.py View on Github external
DATA_KEY = "snapcast"

SUPPORT_SNAPCAST_CLIENT = (
    SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_SET | SUPPORT_SELECT_SOURCE
)
SUPPORT_SNAPCAST_GROUP = (
    SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_SET | SUPPORT_SELECT_SOURCE
)

GROUP_PREFIX = "snapcast_group_"
GROUP_SUFFIX = "Snapcast Group"
CLIENT_PREFIX = "snapcast_client_"
CLIENT_SUFFIX = "Snapcast Client"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_PORT): cv.port}
)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
    """Set up the Snapcast platform."""

    host = config.get(CONF_HOST)
    port = config.get(CONF_PORT, CONTROL_PORT)

    async def async_service_handle(service_event, service, data):
        """Handle dispatched services."""
        entity_ids = data.get(ATTR_ENTITY_ID)
        devices = [
            device for device in hass.data[DATA_KEY] if device.entity_id in entity_ids
        ]
        for device in devices:
github home-assistant / home-assistant / homeassistant / components / startca / sensor.py View on Github external
"grace_download": ["Grace Download", GIGABYTES, "mdi:download"],
    "grace_upload": ["Grace Upload", GIGABYTES, "mdi:upload"],
    "grace_total": ["Grace Total", GIGABYTES, "mdi:download"],
    "total_download": ["Total Download", GIGABYTES, "mdi:download"],
    "total_upload": ["Total Upload", GIGABYTES, "mdi:download"],
    "used_remaining": ["Remaining", GIGABYTES, "mdi:download"],
}

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {
        vol.Required(CONF_MONITORED_VARIABLES): vol.All(
            cv.ensure_list, [vol.In(SENSOR_TYPES)]
        ),
        vol.Required(CONF_API_KEY): cv.string,
        vol.Required(CONF_TOTAL_BANDWIDTH): cv.positive_int,
        vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
    }
)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
    """Set up the sensor platform."""
    websession = async_get_clientsession(hass)
    apikey = config.get(CONF_API_KEY)
    bandwidthcap = config.get(CONF_TOTAL_BANDWIDTH)

    ts_data = StartcaData(hass.loop, websession, apikey, bandwidthcap)
    ret = await ts_data.async_update()
    if ret is False:
        _LOGGER.error("Invalid Start.ca API key: %s", apikey)
        return
github home-assistant / home-assistant / homeassistant / components / todoist / calendar.py View on Github external
OVERDUE,
    PRIORITY,
    PROJECT_ID,
    PROJECT_NAME,
    PROJECTS,
    SERVICE_NEW_TASK,
    START,
    SUMMARY,
    TASKS,
)

_LOGGER = logging.getLogger(__name__)

NEW_TASK_SERVICE_SCHEMA = vol.Schema(
    {
        vol.Required(CONTENT): cv.string,
        vol.Optional(PROJECT_NAME, default="inbox"): vol.All(cv.string, vol.Lower),
        vol.Optional(LABELS): cv.ensure_list_csv,
        vol.Optional(PRIORITY): vol.All(vol.Coerce(int), vol.Range(min=1, max=4)),
        vol.Exclusive(DUE_DATE_STRING, "due_date"): cv.string,
        vol.Optional(DUE_DATE_LANG): vol.All(cv.string, vol.In(DUE_DATE_VALID_LANGS)),
        vol.Exclusive(DUE_DATE, "due_date"): cv.string,
    }
)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {
        vol.Required(CONF_TOKEN): cv.string,
        vol.Optional(CONF_EXTRA_PROJECTS, default=[]): vol.All(
            cv.ensure_list,
            vol.Schema(
                [
github home-assistant / home-assistant / homeassistant / components / apcupsd / __init__.py View on Github external
DATA = None
DEFAULT_HOST = "localhost"
DEFAULT_PORT = 3551
DOMAIN = "apcupsd"

KEY_STATUS = "STATUS"

MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)

VALUE_ONLINE = "ONLINE"

CONFIG_SCHEMA = vol.Schema(
    {
        DOMAIN: vol.Schema(
            {
                vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
                vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
            }
        )
    },
    extra=vol.ALLOW_EXTRA,
)


def setup(hass, config):
    """Use config values to set up a function enabling status retrieval."""
    global DATA
    conf = config[DOMAIN]
    host = conf.get(CONF_HOST)
    port = conf.get(CONF_PORT)

    DATA = APCUPSdData(host, port)
github briis / smartweather / sensor.py View on Github external
'precipitation_rate': ['Rain rate', 'mm/h', 'mdi:weather-pouring', None, 'in/h'],
    'precipitation_last_1hr': ['Rain last hour', 'mm', 'mdi:weather-rainy', None, 'in'],
    'precipitation_yesterday': ['Rain yesterday', 'mm', 'mdi:weather-rainy', None, 'in'],
    'humidity': ['Humidity', '%', 'mdi:water-percent', DEVICE_CLASS_HUMIDITY, None],
    'pressure': ['Pressure', 'hPa', 'mdi:gauge', DEVICE_CLASS_PRESSURE, 'inHg'],
    'uv': ['UV', UNIT_UV_INDEX,'mdi:weather-sunny', None, None],
    'solar_radiation': ['Solar Radiation', 'W/m2', 'mdi:solar-power', None, None],
    'illuminance': ['Illuminance', 'Lx', 'mdi:brightness-5', DEVICE_CLASS_ILLUMINANCE, None],
    'lightning_count': ['Lightning Count', None, 'mdi:weather-lightning', None, None]
}


PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_MONITORED_CONDITIONS, default=list(SENSOR_TYPES)):
        vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
    vol.Optional(CONF_WIND_UNIT, default='ms'): cv.string,
    vol.Optional(CONF_NAME, default=DATA_SMARTWEATHER): cv.string
})


def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the SmartWeather sensor platform."""
    unit_system = 'metric' if hass.config.units.is_metric else 'imperial'

    name = config.get(CONF_NAME)
    data = hass.data[DATA_SMARTWEATHER]
    wind_unit = config.get(CONF_WIND_UNIT)

    if data.data.timestamp is None:
        return

    sensors = []
github home-assistant / home-assistant / homeassistant / components / switch / gc100.py View on Github external
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.gc100/
"""
import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.components.gc100 import DATA_GC100, CONF_PORTS
from homeassistant.components.switch import (PLATFORM_SCHEMA)
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.const import DEVICE_DEFAULT_NAME

DEPENDENCIES = ['gc100']

_SWITCH_SCHEMA = vol.Schema({
    cv.string: cv.string,
})

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_PORTS): vol.All(cv.ensure_list, [_SWITCH_SCHEMA])
})


def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the GC100 devices."""
    switches = []
    ports = config.get(CONF_PORTS)
    for port in ports:
        for port_addr, port_name in port.items():
            switches.append(GC100Switch(
                port_name, port_addr, hass.data[DATA_GC100]))
    add_entities(switches, True)
github home-assistant / home-assistant / homeassistant / components / cmus / media_player.py View on Github external
SUPPORT_CMUS = (
    SUPPORT_PAUSE
    | SUPPORT_VOLUME_SET
    | SUPPORT_TURN_OFF
    | SUPPORT_TURN_ON
    | SUPPORT_PREVIOUS_TRACK
    | SUPPORT_NEXT_TRACK
    | SUPPORT_PLAY_MEDIA
    | SUPPORT_SEEK
    | SUPPORT_PLAY
)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {
        vol.Inclusive(CONF_HOST, "remote"): cv.string,
        vol.Inclusive(CONF_PASSWORD, "remote"): cv.string,
        vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
        vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
    }
)


def setup_platform(hass, config, add_entities, discover_info=None):
    """Set up the CMUS platform."""

    host = config.get(CONF_HOST)
    password = config.get(CONF_PASSWORD)
    port = config.get(CONF_PORT)
    name = config.get(CONF_NAME)

    try:
        cmus_remote = CmusDevice(host, password, port, name)