def test_entities_domain():
    """Test entities domain validation."""
    schema = vol.Schema(cv.entities_domain('sensor'))

    options = (
        None,
        '',
        'invalid_entity',
        ['sensor.light', 'cover.demo'],
        ['sensor.light', 'sensor_invalid'],
    )

    for value in options:
        with pytest.raises(vol.MultipleInvalid):
            schema(value)

    options = ('sensor.light', ['SENSOR.light'],
               ['sensor.light', 'sensor.demo'])
    for value in options:
        schema(value)

    assert schema('sensor.LIGHT, sensor.demo ') == [
        'sensor.light', 'sensor.demo'
    ]
    assert schema(['sensor.light',
                   'SENSOR.demo']) == ['sensor.light', 'sensor.demo']
def test_entities_domain():
    """Test entities domain validation."""
    schema = vol.Schema(cv.entities_domain('sensor'))

    options = (
        None,
        '',
        'invalid_entity',
        ['sensor.light', 'cover.demo'],
        ['sensor.light', 'sensor_invalid'],
    )

    for value in options:
        with pytest.raises(vol.MultipleInvalid):
            schema(value)

    options = (
        'sensor.light',
        ['SENSOR.light'],
        ['sensor.light', 'sensor.demo']
    )
    for value in options:
        schema(value)

    assert schema('sensor.LIGHT, sensor.demo ') == [
        'sensor.light', 'sensor.demo'
    ]
    assert schema(['sensor.light', 'SENSOR.demo']) == [
        'sensor.light', 'sensor.demo'
    ]
Ejemplo n.º 3
0
def test_entities_domain():
    """Test entities domain validation."""
    schema = vol.Schema(cv.entities_domain("sensor"))

    options = (
        None,
        "",
        "invalid_entity",
        ["sensor.light", "cover.demo"],
        ["sensor.light", "sensor_invalid"],
    )

    for value in options:
        with pytest.raises(vol.MultipleInvalid):
            schema(value)

    options = ("sensor.light", ["SENSOR.light"],
               ["sensor.light", "sensor.demo"])
    for value in options:
        schema(value)

    assert schema("sensor.LIGHT, sensor.demo ") == [
        "sensor.light", "sensor.demo"
    ]
    assert schema(["sensor.light",
                   "SENSOR.demo"]) == ["sensor.light", "sensor.demo"]
Ejemplo n.º 4
0
async def async_setup_platform(hass,
                               config,
                               async_add_entities,
                               discovery_info=None):
    """Set up the sensor platform."""
    if discovery_info is None:
        return

    access_token = discovery_info.get(CONF_ACCESS_TOKEN)
    conf_entities = discovery_info.get(CONF_ENTITIES)

    # validate the entities exist
    monitored_entities = entities_exist(hass, conf_entities)

    # ensure we've got at least one entity to monitor
    if not len(monitored_entities):
        _LOGGER.error("No valid entities to monitor")
        return False

    # validate entities are part of media_player domain
    try:
        validate_entities = entities_domain('media_player')
        validate_entities(conf_entities)
    except vol.Invalid as e:
        _LOGGER.error(e)
        return False
    else:
        _LOGGER.debug(f"Monitoring media players: {monitored_entities}")

    # create sensors, one for each monitored entity
    genius = GeniusLyrics(access_token)
    sensors = []
    for media_player in monitored_entities:
        # create sensor
        genius_sensor = GeniusLyricsSensor(hass, genius, media_player)
        # hook media_player to sensor
        async_track_state_change(hass, media_player,
                                 genius_sensor.handle_state_change)
        # add new sensor to list
        sensors.append(genius_sensor)

    # add new sensors
    async_add_entities(sensors)

    # platform setup successfully
    return True
Ejemplo n.º 5
0
SUPPORT_STREAM: Final = 2

RTSP_PREFIXES = {"rtsp://", "rtsps://"}

DEFAULT_CONTENT_TYPE: Final = "image/jpeg"
ENTITY_IMAGE_URL: Final = "/api/camera_proxy/{0}?token={1}"

TOKEN_CHANGE_INTERVAL: Final = timedelta(minutes=5)
_RND: Final = SystemRandom()

MIN_STREAM_INTERVAL: Final = 0.5  # seconds

CAMERA_SERVICE_SNAPSHOT: Final = {vol.Required(ATTR_FILENAME): cv.template}

CAMERA_SERVICE_PLAY_STREAM: Final = {
    vol.Required(ATTR_MEDIA_PLAYER): cv.entities_domain(DOMAIN_MP),
    vol.Optional(ATTR_FORMAT, default="hls"): vol.In(OUTPUT_FORMATS),
}

CAMERA_SERVICE_RECORD: Final = {
    vol.Required(CONF_FILENAME): cv.template,
    vol.Optional(CONF_DURATION, default=30): vol.Coerce(int),
    vol.Optional(CONF_LOOKBACK, default=0): vol.Coerce(int),
}

WS_TYPE_CAMERA_THUMBNAIL: Final = "camera_thumbnail"
SCHEMA_WS_CAMERA_THUMBNAIL: Final = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend(
    {
        vol.Required("type"): WS_TYPE_CAMERA_THUMBNAIL,
        vol.Required("entity_id"): cv.entity_id,
    })
Ejemplo n.º 6
0
CONF_USER_ID = 'user_id'

DOMAIN = 'person'

STORAGE_KEY = DOMAIN
STORAGE_VERSION = 1
SAVE_DELAY = 10
# Device tracker states to ignore
IGNORE_STATES = (STATE_UNKNOWN, STATE_UNAVAILABLE)

PERSON_SCHEMA = vol.Schema({
    vol.Required(CONF_ID): cv.string,
    vol.Required(CONF_NAME): cv.string,
    vol.Optional(CONF_USER_ID): cv.string,
    vol.Optional(CONF_DEVICE_TRACKERS, default=[]): vol.All(
        cv.ensure_list, cv.entities_domain(DEVICE_TRACKER_DOMAIN)),
})

CONFIG_SCHEMA = vol.Schema({
    vol.Optional(DOMAIN): vol.Any(vol.All(cv.ensure_list, [PERSON_SCHEMA]), {})
}, extra=vol.ALLOW_EXTRA)

_UNDEF = object()


@bind_hass
async def async_create_person(hass, name, *, user_id=None,
                              device_trackers=None):
    """Create a new person."""
    await hass.data[DOMAIN].async_create_person(
        name=name,
Ejemplo n.º 7
0
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.typing import ConfigType

from . import GroupEntity
from .util import attribute_equal, reduce_attribute

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

DEFAULT_NAME = "Cover Group"

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


async def async_setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    async_add_entities: AddEntitiesCallback,
    discovery_info: dict[str, Any] | None = None,
) -> None:
    """Set up the Group Cover platform."""
    async_add_entities([
Ejemplo n.º 8
0
from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, entity_registry as er
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from . import GroupEntity

DEFAULT_NAME = "Binary Sensor Group"

CONF_ALL = "all"
REG_KEY = f"{BINARY_SENSOR_DOMAIN}_registry"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_ENTITIES):
    cv.entities_domain(BINARY_SENSOR_DOMAIN),
    vol.Optional(CONF_NAME, default=DEFAULT_NAME):
    cv.string,
    vol.Optional(CONF_UNIQUE_ID):
    cv.string,
    vol.Optional(CONF_DEVICE_CLASS):
    DEVICE_CLASSES_SCHEMA,
    vol.Optional(CONF_ALL):
    cv.boolean,
})


async def async_setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    async_add_entities: AddEntitiesCallback,
Ejemplo n.º 9
0
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import color as color_util

from . import GroupEntity

# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
# mypy: no-check-untyped-defs

DEFAULT_NAME = "Light Group"

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

SUPPORT_GROUP_LIGHT = (SUPPORT_EFFECT | SUPPORT_FLASH | SUPPORT_TRANSITION
                       | SUPPORT_WHITE_VALUE)


async def async_setup_platform(hass: HomeAssistant,
                               config: ConfigType,
                               async_add_entities,
                               discovery_info=None) -> None:
    """Initialize light.group platform."""
    async_add_entities(
        [LightGroup(cast(str, config.get(CONF_NAME)), config[CONF_ENTITIES])])

Ejemplo n.º 10
0
from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, entity_registry as er
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from . import GroupEntity

DEFAULT_NAME = "Binary Sensor Group"

CONF_ALL = "all"
REG_KEY = f"{BINARY_SENSOR_DOMAIN}_registry"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {
        vol.Required(CONF_ENTITIES): cv.entities_domain(BINARY_SENSOR_DOMAIN),
        vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
        vol.Optional(CONF_UNIQUE_ID): cv.string,
        vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
        vol.Optional(CONF_ALL): cv.boolean,
    }
)


async def async_setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    async_add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the Binary Sensor Group platform."""
Ejemplo n.º 11
0
ENTITY_IMAGE_URL = "/api/camera_proxy/{0}?token={1}"

TOKEN_CHANGE_INTERVAL = timedelta(minutes=5)
_RND = SystemRandom()

MIN_STREAM_INTERVAL = 0.5  # seconds

CAMERA_SERVICE_SCHEMA = vol.Schema(
    {vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids})

CAMERA_SERVICE_SNAPSHOT = CAMERA_SERVICE_SCHEMA.extend(
    {vol.Required(ATTR_FILENAME): cv.template})

CAMERA_SERVICE_PLAY_STREAM = CAMERA_SERVICE_SCHEMA.extend({
    vol.Required(ATTR_MEDIA_PLAYER):
    cv.entities_domain(DOMAIN_MP),
    vol.Optional(ATTR_FORMAT, default="hls"):
    vol.In(OUTPUT_FORMATS),
})

CAMERA_SERVICE_RECORD = CAMERA_SERVICE_SCHEMA.extend({
    vol.Required(CONF_FILENAME):
    cv.template,
    vol.Optional(CONF_DURATION, default=30):
    vol.Coerce(int),
    vol.Optional(CONF_LOOKBACK, default=0):
    vol.Coerce(int),
})

WS_TYPE_CAMERA_THUMBNAIL = "camera_thumbnail"
SCHEMA_WS_CAMERA_THUMBNAIL = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({
Ejemplo n.º 12
0
from homeassistant.helpers.event import async_track_state_change
from homeassistant.helpers.typing import HomeAssistantType, ConfigType

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = "Climate Group"

CONF_EXCLUDE = "exclude"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Optional(CONF_NAME, default=DEFAULT_NAME):
    cv.string,
    vol.Optional(CONF_TEMPERATURE_UNIT, default=TEMP_CELSIUS):
    cv.string,
    vol.Required(CONF_ENTITIES):
    cv.entities_domain(climate.DOMAIN),
    vol.Optional(CONF_EXCLUDE, default=[]):
    vol.All(
        cv.ensure_list,
        [
            vol.In([
                PRESET_ACTIVITY,
                PRESET_AWAY,
                PRESET_BOOST,
                PRESET_COMFORT,
                PRESET_ECO,
                PRESET_HOME,
                PRESET_SLEEP,
            ])
        ],
    ),
Ejemplo n.º 13
0
from homeassistant.helpers.typing import ConfigType, HomeAssistantType

from homeassistant.components.light import (
    ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, ATTR_EFFECT_LIST,
    ATTR_FLASH, ATTR_HS_COLOR, ATTR_MAX_MIREDS, ATTR_MIN_MIREDS,
    ATTR_TRANSITION, ATTR_WHITE_VALUE, PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS,
    SUPPORT_COLOR, SUPPORT_COLOR_TEMP, SUPPORT_EFFECT, SUPPORT_FLASH,
    SUPPORT_TRANSITION, SUPPORT_WHITE_VALUE)

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = 'Light Group'

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

SUPPORT_GROUP_LIGHT = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_EFFECT
                       | SUPPORT_FLASH | SUPPORT_COLOR | SUPPORT_TRANSITION
                       | SUPPORT_WHITE_VALUE)


async def async_setup_platform(hass: HomeAssistantType, config: ConfigType,
                               async_add_entities,
                               discovery_info=None) -> None:
    """Initialize light.group platform."""
    async_add_entities([LightGroup(config.get(CONF_NAME),
                                   config[CONF_ENTITIES])])

Ejemplo n.º 14
0
    SUPPORT_COLOR,
    SUPPORT_COLOR_TEMP,
    SUPPORT_EFFECT,
    SUPPORT_FLASH,
    SUPPORT_TRANSITION,
    SUPPORT_WHITE_VALUE,
)

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = "Light Group"

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

SUPPORT_GROUP_LIGHT = (
    SUPPORT_BRIGHTNESS
    | SUPPORT_COLOR_TEMP
    | SUPPORT_EFFECT
    | SUPPORT_FLASH
    | SUPPORT_COLOR
    | SUPPORT_TRANSITION
    | SUPPORT_WHITE_VALUE
)


async def async_setup_platform(
Ejemplo n.º 15
0
)
from homeassistant.core import State, callback
from homeassistant.helpers.event import async_track_state_change
from homeassistant.helpers.typing import HomeAssistantType, ConfigType

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = "Climate Group"

CONF_EXCLUDE = "exclude"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {
        vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
        vol.Optional(CONF_TEMPERATURE_UNIT, default=TEMP_CELSIUS): cv.string,
        vol.Required(CONF_ENTITIES): cv.entities_domain(climate.DOMAIN),
        vol.Optional(CONF_EXCLUDE, default=[]): vol.All(
            cv.ensure_list,
            [
                vol.In(
                    [
                        PRESET_ACTIVITY,
                        PRESET_AWAY,
                        PRESET_BOOST,
                        PRESET_COMFORT,
                        PRESET_ECO,
                        PRESET_HOME,
                        PRESET_SLEEP,
                    ]
                )
            ],
Ejemplo n.º 16
0
STARTUP_VERSION = """
-------------------------------------------------------------------
{name}
Version: {version}
This is a custom integration
If you have any issues with this you need to open an issue here:
{issue_link}
-------------------------------------------------------------------
"""

PERSON_SCHEMA = vol.Schema({
    vol.Required(CONF_NAME):
    cv.string,
    vol.Optional(CONF_DEVICES, default=[]):
    vol.All(cv.ensure_list, cv.entities_domain(VALID_ENTITY_DOMAINS)),
})

CONFIG_SCHEMA = vol.Schema(
    {
        DOMAIN:
        vol.Schema({
            vol.Optional(CONF_CREATE_SENSORS, default=[]):
            vol.All(cv.ensure_list, [vol.In(VALID_CREATE_SENSORS)]),
            vol.Optional(CONF_HOURS_EXTENDED_AWAY,
                         default=DEFAULT_HOURS_EXTENDED_AWAY):
            cv.string,
            vol.Optional(CONF_MINUTES_JUST_ARRIVED,
                         default=DEFAULT_MINUTES_JUST_ARRIVED):
            cv.string,
            vol.Optional(CONF_MINUTES_JUST_LEFT,
Ejemplo n.º 17
0
TOKEN_CHANGE_INTERVAL = timedelta(minutes=5)
_RND = SystemRandom()

FALLBACK_STREAM_INTERVAL = 1  # seconds
MIN_STREAM_INTERVAL = 0.5  # seconds

CAMERA_SERVICE_SCHEMA = vol.Schema({
    vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
})

CAMERA_SERVICE_SNAPSHOT = CAMERA_SERVICE_SCHEMA.extend({
    vol.Required(ATTR_FILENAME): cv.template
})

CAMERA_SERVICE_PLAY_STREAM = CAMERA_SERVICE_SCHEMA.extend({
    vol.Required(ATTR_MEDIA_PLAYER): cv.entities_domain(DOMAIN_MP),
    vol.Optional(ATTR_FORMAT, default='hls'): vol.In(OUTPUT_FORMATS),
})

WS_TYPE_CAMERA_THUMBNAIL = 'camera_thumbnail'
SCHEMA_WS_CAMERA_THUMBNAIL = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({
    vol.Required('type'): WS_TYPE_CAMERA_THUMBNAIL,
    vol.Required('entity_id'): cv.entity_id
})


@attr.s
class Image:
    """Represent an image."""

    content_type = attr.ib(type=str)