예제 #1
0
    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
            }
        })
예제 #2
0
    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',
            }]
        })
예제 #3
0
    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')
예제 #4
0
    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
예제 #5
0
파일: sgneaweb.py 프로젝트: tyjtyj/sgneaweb
    '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
예제 #6
0
    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(
예제 #7
0
    vol.Required(CONF_ON_ACTION): cv.SCRIPT_SCHEMA,
    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_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(
예제 #8
0
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA
from homeassistant.helpers import template as template_helper
from homeassistant.util import dt as dt_util

from html.parser import HTMLParser

_LOGGER = logging.getLogger(__name__)

DOMAIN = 'edp_redy_local'
ATTR_LAST_COMMUNICATION = 'last_communication'
CONF_UPDATE_INTERVAL = 'update_interval'
DEFAULT_TIMEOUT = 10

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_HOST):
    cv.string,
    vol.Optional(CONF_UPDATE_INTERVAL, default=30):
    cv.positive_int,
})


@asyncio.coroutine
def async_setup_platform(hass,
                         config,
                         async_add_entities,
                         discovery_info=None):
    class RedyHTMLParser(HTMLParser):
        def __init__(self):
            super().__init__()
            self._json = ''

        def handle_data(self, data):
예제 #9
0
파일: waqi.py 프로젝트: sara0871/master.zip
    'so2': ATTR_SULFUR_DIOXIDE,
}

ATTRIBUTION = 'Data provided by the World Air Quality Index project'

CONF_LOCATIONS = 'locations'
CONF_STATIONS = 'stations'

SCAN_INTERVAL = timedelta(minutes=5)

TIMEOUT = 10

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Optional(CONF_STATIONS):
    cv.ensure_list,
    vol.Required(CONF_TOKEN):
    cv.string,
    vol.Required(CONF_LOCATIONS):
    cv.ensure_list,
})


@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Set up the requested World Air Quality Index locations."""
    import waqiasync

    token = config.get(CONF_TOKEN)
    station_filter = config.get(CONF_STATIONS)
    locations = config.get(CONF_LOCATIONS)

    client = waqiasync.WaqiClient(token,
예제 #10
0
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,
    vol.Optional(CONF_TEMPERATURE_UNIT):
    vol.In(temp_util.VALID_UNITS),
    vol.Optional(CONF_PRESSURE_UNIT):
    vol.In(pressure_util.VALID_UNITS),
    vol.Optional(CONF_WIND_SPEED_UNIT):
    vol.In(speed_util.VALID_UNITS),
    vol.Optional(CONF_VISIBILITY_UNIT):
    vol.In(distance_util.VALID_UNITS),
    vol.Optional(CONF_PRECIPITATION_UNIT):
    vol.In(distance_util.VALID_UNITS),
})
예제 #11
0
import logging
import string
import requests
from datetime import timedelta
import xml.etree.ElementTree as ET
import voluptuous as vol
from homeassistant.helpers.entity import Entity
from homeassistant.const import DEVICE_CLASS_POWER, ENERGY_KILO_WATT_HOUR, ATTR_DATE
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME

# Validation of the user's configuration
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_USERNAME): cv.string,
    vol.Required(CONF_PASSWORD): cv.string
})

SCAN_INTERVAL = timedelta(minutes=5)
_LOGGER = logging.getLogger(__name__)
# logging.basicConfig(level=logging.DEBUG)

DOMAIN = "bchydro"
URL_LOGIN = "******"
URL_ACCT_INFO = "https://app.bchydro.com/evportlet/web/global-data.html"
URL_GET_USAGE = "https://app.bchydro.com/evportlet/web/account-profile-data.html"

# This URL has more detail than URL_GET_USAGE but seems to require more headers to access.
# Not used at the moment, but ideally it will replace URL_GET_USAGE.
# URL_GET_CONSUMPTION = "https://app.bchydro.com/evportlet/web/consumption-data.html"
예제 #12
0
CONF_INITIAL_VALUE = "initial_value"
CONF_UNIQUE_ID = "unique_id"
CONF_ON_VAL = "on_val"
CONF_OFF_VAL = "off_val"
CONF_PULSE_LEN = "pulse_len"

DEFAULT_INITIAL_VALUE = "off"
DEFAULT_UNIQUE_ID = None
DEFAULT_ON_VAL = "0"
DEFAULT_ON_VAL = "0"
DEFAULT_PULSE_LEN = "230"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_NAME): cv.string,
    vol.Required(CONF_ON_VAL): cv.string,
    vol.Required(CONF_OFF_VAL): cv.string,
    vol.Required(CONF_PULSE_LEN): cv.string,
    vol.Optional(CONF_INITIAL_VALUE, default=DEFAULT_INITIAL_VALUE): cv.string,
    vol.Optional(CONF_UNIQUE_ID, default=DEFAULT_UNIQUE_ID): cv.string,
})


async def async_setup_platform(_hass, config, async_add_entities, _discovery_info=None):
    switches = [VirtualSwitch(config)]
    async_add_entities(switches, True)


class VirtualSwitch(SwitchEntity):
    """Representation of a Virtual switch."""

    def __init__(self, config):
        """Initialize the Virtual switch device."""
예제 #13
0
                     | 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:
예제 #14
0
        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_UNIQUE_ID):
        cv.string,
        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.positive_time_period,
        vol.Optional(CONF_PRECISION, default=DEFAULT_PRECISION):
        int,
        vol.Optional(CONF_PROCESS_UNDEF_AS):
        vol.Any(int, float),
    }),
    check_period_keys,
)


# pylint: disable=unused-argument
async def async_setup_platform(hass: HomeAssistant,
                               config,
예제 #15
0
    {
        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_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,
    }
)

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)
        availability_template = device_config.get(CONF_AVAILABILITY_TEMPLATE)
        level_template = device_config.get(CONF_LEVEL_TEMPLATE)
예제 #16
0
from aiohttp.hdrs import AUTHORIZATION
from datetime import timedelta, datetime
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.const import CONF_TOKEN, CONF_NAME, STATE_OFF, STATE_ON
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA

CONF_ACCOUNT_ID = 'account_id'
TIMEOUT = 10
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=15)
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)
ENDPOINT = "https://api.harvestapp.com/v2/time_entries"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_ACCOUNT_ID): cv.string,
    vol.Required(CONF_TOKEN): cv.string,
    vol.Required(CONF_NAME): cv.string
})

_LOGGER = logging.getLogger(__name__)


def setup_platform(hass, config, add_devices, discovery_info=None):
    account_id = config.get(CONF_ACCOUNT_ID)
    token = config.get(CONF_TOKEN)
    name = config.get(CONF_NAME)

    websession = async_get_clientsession(hass)

    add_devices([HarvestSensor(hass, websession, account_id, token, name)])
예제 #17
0
import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.components.switch import SwitchEntity
from homeassistant.helpers.config_validation import (PLATFORM_SCHEMA)

_LOGGER = logging.getLogger(__name__)

CONF_NAME = "name"
CONF_INITIAL_VALUE = "initial_value"

DEFAULT_INITIAL_VALUE = "off"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_NAME):
    cv.string,
    vol.Optional(CONF_INITIAL_VALUE, default=DEFAULT_INITIAL_VALUE):
    cv.string,
})


async def async_setup_platform(_hass,
                               config,
                               async_add_entities,
                               _discovery_info=None):
    switches = [VirtualSwitch(config)]
    async_add_entities(switches, True)


class VirtualSwitch(SwitchEntity):
    """Representation of a Virtual switch."""
    def __init__(self, config):
예제 #18
0
COLLECTIONS = {
    'R': 'Restabfallbehälter',
    'B': 'Bioabfallbehälter',
    'P': 'Papierbehälter',
    'G': 'Gelber Sack'
}

CONF_OFFSET = "offset"
CONF_TOWN = "town"
CONF_STREET = "street"
CONF_STREET_NR = "street_nr"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_TOWN): cv.string,
    vol.Required(CONF_STREET): cv.string,
    vol.Required(CONF_STREET_NR): cv.string,
    vol.Optional(CONF_OFFSET, default=timedelta(hours=6)): cv.time_period,
    vol.Optional(CONF_SCAN_INTERVAL, default=timedelta(hours=3)): cv.time_period
})


def setup_platform(hass, config, add_devices, discovery_info=None):
    scan_interval = config.get(CONF_SCAN_INTERVAL)

    _LOGGER.info('scan_interval: {}'.format(scan_interval))

    calendar_devices = []
    for collection in COLLECTIONS:
        device_data = {
            CONF_NAME: "{} - ZAKB".format(COLLECTIONS[collection]),
            CONF_DEVICE_ID: "zakb_{}".format(collection)
예제 #19
0
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]
예제 #20
0
ATTR_LAST_VIDEO = "last_video"
ATTR_VOLUME = "volume"
ATTR_LAST_THUMBNAIL = "last_thumbnail"
ATTR_DURATION = "duration"
ATTR_TIME_ZONE = "time_zone"

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,
})

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"
OLD_SERVICE_REQUEST_VIDEO_TO_FILE = "aarlo_request_video_to_file"
OLD_SERVICE_STOP_ACTIVITY = "aarlo_stop_activity"
OLD_SERVICE_SIREN_ON = "aarlo_siren_on"
OLD_SERVICE_SIREN_OFF = "aarlo_siren_off"
OLD_SERVICE_RECORD_START = "aarlo_start_recording"
예제 #21
0
_LOGGER = logging.getLogger(__name__)

SENSOR_TYPES = {
    'time': ['Updated ', None],
    'weather': ['Condition', None],
    'temperature': ['Temperature', 'C'],
    'wind': ['Wind speed', None],
    'pressure': ['Pressure', None],
    'visibility': ['Visibility', None],
    'precipitation': ['Precipitation', None],
    'sky': ['Sky', None],
}

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_AIRPORT_NAME): cv.string,
    vol.Required(CONF_AIRPORT_CODE): cv.string,
    vol.Optional(CONF_MONITORED_CONDITIONS, default=[]):
        vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),	
})

def setup_platform(hass, config, add_entities, discovery_info=None):
   airport = {'location': str(config.get(CONF_AIRPORT_NAME)), 'code': str(config.get(CONF_AIRPORT_CODE))}

   data = MetarData(airport)
   dev = []
   for variable in config[CONF_MONITORED_CONDITIONS]:
       dev.append(MetarSensor(airport, data, variable, SENSOR_TYPES[variable][1]))
   add_entities(dev, True)


class MetarSensor(Entity):
예제 #22
0
ARMED = 'armed'
DISARMED = 'disarmed'
ICON = 'mdi:security'

CONF_HOME_MODE_NAME = 'home_mode_name'
CONF_AWAY_MODE_NAME = 'away_mode_name'
CONF_NIGHT_MODE_NAME = 'night_mode_name'
CONF_ALARM_VOLUME = 'alarm_volume'

DEFAULT_TRIGGER_TIME = timedelta(seconds=60)
ALARM_VOLUME = '8'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Optional(CONF_HOME_MODE_NAME, default=ARMED): cv.string,
    vol.Optional(CONF_AWAY_MODE_NAME, default=ARMED): cv.string,
    vol.Optional(CONF_NIGHT_MODE_NAME, default=ARMED): cv.string,
    vol.Optional(CONF_ALARM_VOLUME, 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'

SERVICE_MODE = 'aarlo_set_mode'
SERVICE_SIREN_ON = 'aarlo_siren_on'
SERVICE_SIREN_OFF = 'aarlo_siren_off'
SERVICE_MODE_SCHEMA = vol.Schema({
    vol.Required(ATTR_ENTITY_ID): cv.comp_entity_ids,
    vol.Required(ATTR_MODE): cv.string,
예제 #23
0
    ),
    SensorEntityDescription(
        key="allpollu",
        name=ATTR_FOOBOT_INDEX,
        native_unit_of_measurement=PERCENTAGE,
        icon="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: HomeAssistant,
    config: ConfigType,
    async_add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the devices associated with the account."""
    token: str = config[CONF_TOKEN]
    username: str = config[CONF_USERNAME]

    client = FoobotClient(token,
                          username,
예제 #24
0
DEFAULT_INITIAL_AVAILABILITY = True

#  PRESET_MODE_AUTO = "auto"
#  PRESET_MODE_SMART = "smart"
#  PRESET_MODE_SLEEP = "sleep"
#  PRESET_MODE_ON = "on"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_NAME):
    cv.string,
    vol.Optional(CONF_SPEED, default=False):
    cv.boolean,
    vol.Optional(CONF_SPEED_COUNT, default=0):
    cv.positive_int,
    vol.Optional(CONF_OSCILLATE, default=False):
    cv.boolean,
    vol.Optional(CONF_DIRECTION, default=False):
    cv.boolean,
    vol.Optional(CONF_MODES, default=[]):
    vol.All(cv.ensure_list, [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):
    """Set up the Demo config entry."""
예제 #25
0
    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({})
        mock_integration(
            self.hass,
            MockModule("platform_conf",
                       platform_schema_base=platform_schema_base),
        )
        mock_entity_platform(
            self.hass,
            "platform_conf.whatever",
            MockPlatform(platform_schema=platform_schema),
        )

        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
예제 #26
0
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_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,
예제 #27
0
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.const import ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA
from . import ATTRIBUTION, DATA_UFP, DEFAULT_BRAND

_LOGGER = logging.getLogger(__name__)

DEPENDENCIES = ["unifiprotect"]

SCAN_INTERVAL = timedelta(seconds=3)

# sensor_type [ description, unit, icon ]
SENSOR_TYPES = {"motion": ["Motion", "motion", "motionDetected"]}

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 Unifi Protect binary sensor."""
    cameradata = hass.data.get(DATA_UFP)
    if not cameradata:
        return

    sensors = []
    for sensor_type in config.get(CONF_MONITORED_CONDITIONS):
        for camera in cameradata.cameras:
CONF_ALARM_VOLUME = 'alarm_volume'
CONF_COMMAND_TEMPLATE = "command_template"

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'

SERVICE_MODE = 'alarm_set_mode'
OLD_SERVICE_MODE = 'aarlo_set_mode'
OLD_SERVICE_SIREN_ON = 'aarlo_siren_on'
예제 #29
0
# Sensor types are defined like: Name, Name_API
SENSOR_TYPES_API = {
    'temperature': 'temp',
    'humidity': 'humid',
    'co2': 'co2',
    'chemicals': 'voc',
    'dust': 'dust',
    'pm25': 'pm25',
    'pm10': 'pm10',
}

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_TOKEN):
    cv.string,
    vol.Required(CONF_NAME):
    cv.string,
    vol.Optional(CONF_MONITORED_CONDITIONS, default=list(SENSOR_TYPES)):
    vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
    vol.Optional(CONF_REFRESH, default=60):
    cv.positive_int,
})


def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Awair sensor."""
    from pyawair.auth import AwairAuth
    from pyawair.objects import AwairDev

    _LOGGER.debug("Setting up the Awair platform")

    token = config.get(CONF_TOKEN)
    name = config.get(CONF_NAME)
예제 #30
0
파일: weather.py 프로젝트: Claret-Srl/core
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(hass,
예제 #31
0
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)
예제 #32
0
                '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 = []
예제 #33
0
    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
ATTR_MESSAGE = 'message'
ATTR_URL = 'url'

DEFAULT_NAME = 'WallPanel'
DEFAULT_PORT = 2971

MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=5)

SERVICE_LOAD_START_URL = 'load_start_url'
SERVICE_SAY = 'say'
SERVICE_SOUND_START = 'sound_play'

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
})

SCHEMA_SERVICE_LOAD_START_URL = vol.Schema({
    ATTR_ENTITY_ID: cv.entity_ids,
})
SCHEMA_SERVICE_SOUND_START = vol.Schema({
    ATTR_ENTITY_ID: cv.entity_ids,
    vol.Required(ATTR_URL): cv.string
})
SCHEMA_SERVICE_SAY = vol.Schema({
    ATTR_ENTITY_ID: cv.entity_ids,
    vol.Required(ATTR_MESSAGE): cv.string
})
예제 #35
0
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
예제 #36
0
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 \
예제 #37
0
SNAPSHOTS_DEFAULT = False
SNAPSHOT_TIMEOUT_DEFAULT = timedelta(seconds=60)

CONF_SIRENS = "siren"
CONF_ALL_SIRENS = "all_sirens"
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"

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),
})


async def async_setup_platform(hass, config, async_add_entities, _discovery_info=None):
    arlo = hass.data.get(COMPONENT_DATA)
    if not arlo:
        return

    devices = []
    adevices = []

    # See what cameras and bases have sirens.
예제 #38
0
from homeassistant.const import (CONF_NAME, CONF_ADDRESS, STATE_UNKNOWN)
import homeassistant.helpers.config_validation as cv

import voluptuous as vol

from custom_components.zigate.const import *
from pyzigate.zgt_parameters import *

CONF_DEFAULT_ATTR = 'default_state'
CONF_DEFAULT_UNIT = 'default_unit'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_NAME):
    cv.string,
    vol.Required(CONF_ADDRESS):
    cv.string,
    vol.Optional(CONF_DEFAULT_ATTR, default=None):
    cv.string,
    vol.Optional(CONF_DEFAULT_UNIT, default=None):
    cv.string,
})


def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the ZiGate sensors."""
    device = ZiGateSensor(hass, config.get(CONF_NAME),
                          config.get(CONF_ADDRESS),
                          config.get(CONF_DEFAULT_ATTR),
                          config.get(CONF_DEFAULT_UNIT))
    add_devices([device])

예제 #39
0
    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
예제 #40
0
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 = []
예제 #41
0
    def test_validate_platform_config(self):
        """Test validating platform configuration."""
        platform_schema = PLATFORM_SCHEMA.extend({
            'hello': str,
        })
        loader.set_component(
            self.hass, 'platform_conf',
            MockModule('platform_conf', platform_schema=platform_schema))

        loader.set_component(self.hass, '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
예제 #42
0
    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,
        }
    ),
    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
    _LOGGER.info("Version %s", VERSION)
    _LOGGER.info(
        "If you have ANY issues with this, please report them here: %s", ISSUE_URL
예제 #43
0
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]
예제 #44
0
    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': {
                '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',
            }
        })

        self.hass.config.components.remove('platform_conf')

        assert bootstrap._setup_component(self.hass, 'platform_conf', {
            'platform_conf': [{
                'platform': 'whatever',
                'hello': 'world',
            }]
        })

        self.hass.config.components.remove('platform_conf')

        # Any falsey paltform config will be ignored (None, {}, etc)
        assert bootstrap._setup_component(self.hass, 'platform_conf', {
            'platform_conf': None
        })

        self.hass.config.components.remove('platform_conf')

        assert bootstrap._setup_component(self.hass, 'platform_conf', {
            'platform_conf': {}
        })