def test_entity_domain(): """Test entity domain validation.""" schema = vol.Schema(cv.entity_domain("sensor")) for value in ( "invalid_entity", "cover.demo", "cover.demo,sensor.another_entity", "", ): with pytest.raises(vol.MultipleInvalid): schema(value) assert schema("sensor.LIGHT") == "sensor.light" schema = vol.Schema(cv.entity_domain(("sensor", "binary_sensor"))) for value in ("invalid_entity", "cover.demo"): with pytest.raises(vol.MultipleInvalid): schema(value) assert schema("sensor.LIGHT") == "sensor.light" assert schema("binary_sensor.LIGHT") == "binary_sensor.light"
SERVICE_TURN_OFF, SERVICE_TURN_ON, ) from openpeerpower.core import Context, OpenPeerPower from openpeerpower.helpers import entity_registry import openpeerpower.helpers.config_validation as cv from . import DOMAIN ACTION_TYPES = {"turn_on", "turn_off"} ACTION_SCHEMA = cv.DEVICE_ACTION_BASE_SCHEMA.extend({ vol.Required(CONF_TYPE): vol.In(ACTION_TYPES), vol.Required(CONF_ENTITY_ID): cv.entity_domain(DOMAIN), }) async def async_get_actions(opp: OpenPeerPower, device_id: str) -> list[dict]: """List device actions for Fan devices.""" registry = await entity_registry.async_get_registry(opp) actions = [] # Get all the integrations entities for this device for entry in entity_registry.async_entries_for_device(registry, device_id): if entry.domain != DOMAIN: continue actions.append({ CONF_DEVICE_ID: device_id,
HOMEKIT_NOTIFY_ID, TYPE_FAUCET, TYPE_OUTLET, TYPE_SHOWER, TYPE_SPRINKLER, TYPE_SWITCH, TYPE_VALVE, ) _LOGGER = logging.getLogger(__name__) BASIC_INFO_SCHEMA = vol.Schema({ vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_LINKED_BATTERY_SENSOR): cv.entity_domain(sensor.DOMAIN), vol.Optional(CONF_LOW_BATTERY_THRESHOLD, default=DEFAULT_LOW_BATTERY_THRESHOLD): cv.positive_int, }) FEATURE_SCHEMA = BASIC_INFO_SCHEMA.extend( {vol.Optional(CONF_FEATURE_LIST, default=None): cv.ensure_list}) CODE_SCHEMA = BASIC_INFO_SCHEMA.extend( {vol.Optional(ATTR_CODE, default=None): vol.Any(None, cv.string)}) MEDIA_PLAYER_SCHEMA = vol.Schema({ vol.Required(CONF_FEATURE): vol.All( cv.string,
} ) FILTER_TIME_THROTTLE_SCHEMA = FILTER_SCHEMA.extend( { vol.Required(CONF_FILTER_NAME): FILTER_NAME_TIME_THROTTLE, vol.Required(CONF_FILTER_WINDOW_SIZE): vol.All( cv.time_period, cv.positive_timedelta ), } ) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_ENTITY_ID): vol.Any( cv.entity_domain(SENSOR_DOMAIN), cv.entity_domain(BINARY_SENSOR_DOMAIN), cv.entity_domain(INPUT_NUMBER_DOMAIN), ), vol.Optional(CONF_NAME): cv.string, vol.Required(CONF_FILTERS): vol.All( cv.ensure_list, [ vol.Any( FILTER_OUTLIER_SCHEMA, FILTER_LOWPASS_SCHEMA, FILTER_TIME_SMA_SCHEMA, FILTER_THROTTLE_SCHEMA, FILTER_TIME_THROTTLE_SCHEMA, FILTER_RANGE_SCHEMA, )
) from openpeerpower.core import OpenPeerPower, State, callback import openpeerpower.helpers.config_validation as cv from openpeerpower.helpers.entity_platform import AddEntitiesCallback from openpeerpower.helpers.event import async_track_state_change_event from openpeerpower.helpers.typing import ConfigType, DiscoveryInfoType # mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs DEFAULT_NAME = "Light Switch" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Required(CONF_ENTITY_ID): cv.entity_domain(switch.DOMAIN), }) async def async_setup_platform( opp: OpenPeerPower, config: ConfigType, async_add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Initialize Light Switch platform.""" registry = await opp.helpers.entity_registry.async_get_registry() wrapped_switch = registry.async_get(config[CONF_ENTITY_ID]) unique_id = wrapped_switch.unique_id if wrapped_switch else None
ATTR_CONFIDENCE = "confidence" ATTR_FACES = "faces" ATTR_GENDER = "gender" ATTR_GLASSES = "glasses" ATTR_MOTION = "motion" ATTR_TOTAL_FACES = "total_faces" CONF_SOURCE = "source" CONF_CONFIDENCE = "confidence" DEFAULT_TIMEOUT = 10 DEFAULT_CONFIDENCE = 80 SOURCE_SCHEMA = vol.Schema({ vol.Required(CONF_ENTITY_ID): cv.entity_domain("camera"), vol.Optional(CONF_NAME): cv.string, }) PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({ vol.Optional(CONF_SOURCE): vol.All(cv.ensure_list, [SOURCE_SCHEMA]), vol.Optional(CONF_CONFIDENCE, default=DEFAULT_CONFIDENCE): vol.All(vol.Coerce(float), vol.Range(min=0, max=100)), }) PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE.extend(PLATFORM_SCHEMA.schema) async def async_setup(opp, config): """Set up the image processing."""
STATE_UNKNOWN, ) from openpeerpower.core import OppJob, callback from openpeerpower.helpers import config_validation as cv from openpeerpower.helpers.event import ( async_track_point_in_time, async_track_state_change_event, async_track_time_change, ) import openpeerpower.util.dt as dt_util # mypy: allow-untyped-defs, no-check-untyped-defs _TIME_TRIGGER_SCHEMA = vol.Any( cv.time, vol.All(str, cv.entity_domain(("input_datetime", "sensor"))), msg="Expected HH:MM, HH:MM:SS or Entity ID with domain 'input_datetime' or 'sensor'", ) TRIGGER_SCHEMA = vol.Schema( { vol.Required(CONF_PLATFORM): "time", vol.Required(CONF_AT): vol.All(cv.ensure_list, [_TIME_TRIGGER_SCHEMA]), } ) async def async_attach_trigger(opp, config, action, automation_info): """Listen for state changes based on configuration.""" trigger_id = automation_info.get("trigger_id") if automation_info else None entities = {}
CONF_TYPE, CONF_ZONE, ) from openpeerpower.core import CALLBACK_TYPE, OpenPeerPower from openpeerpower.helpers import config_validation as cv, entity_registry from openpeerpower.helpers.typing import ConfigType from . import DOMAIN TRIGGER_TYPES: Final[set[str]] = {"enters", "leaves"} TRIGGER_SCHEMA: Final = TRIGGER_BASE_SCHEMA.extend( { vol.Required(CONF_ENTITY_ID): cv.entity_id, vol.Required(CONF_TYPE): vol.In(TRIGGER_TYPES), vol.Required(CONF_ZONE): cv.entity_domain(DOMAIN_ZONE), } ) async def async_get_triggers(opp: OpenPeerPower, device_id: str) -> list[dict]: """List device triggers for Device Tracker devices.""" registry = await entity_registry.async_get_registry(opp) triggers = [] # Get all the integrations entities for this device for entry in entity_registry.async_entries_for_device(registry, device_id): if entry.domain != DOMAIN: continue triggers.append(
SERVICE_TURN_OFF, SERVICE_TURN_ON, ) from openpeerpower.core import Context, OpenPeerPower from openpeerpower.helpers import entity_registry import openpeerpower.helpers.config_validation as cv from . import DOMAIN # TODO specify your supported action types. ACTION_TYPES = {"turn_on", "turn_off"} ACTION_SCHEMA = cv.DEVICE_ACTION_BASE_SCHEMA.extend( { vol.Required(CONF_TYPE): vol.In(ACTION_TYPES), vol.Required(CONF_ENTITY_ID): cv.entity_domain(DOMAIN), } ) async def async_get_actions(opp: OpenPeerPower, device_id: str) -> List[dict]: """List device actions for NEW_NAME devices.""" registry = await entity_registry.async_get_registry(opp) actions = [] # TODO Read this comment and remove it. # This example shows how to iterate over the entities of this device # that match this integration. If your actions instead rely on # calling services, do something like: # zha_device = await _async_get_zha_device(opp, device_id) # return zha_device.device_actions
from openpeerpower.helpers import condition, config_validation as cv from openpeerpower.helpers.config_validation import entity_domain # mypy: allow-untyped-defs, no-check-untyped-defs EVENT_ENTER = "enter" EVENT_LEAVE = "leave" DEFAULT_EVENT = EVENT_ENTER TRIGGER_SCHEMA = vol.Schema({ vol.Required(CONF_PLATFORM): "geo_location", vol.Required(CONF_SOURCE): cv.string, vol.Required(CONF_ZONE): entity_domain("zone"), vol.Required(CONF_EVENT, default=DEFAULT_EVENT): vol.Any(EVENT_ENTER, EVENT_LEAVE), }) def source_match(state, source): """Check if the state matches the provided source.""" return state and state.attributes.get("source") == source async def async_attach_trigger(opp, config, action, automation_info): """Listen for state changes based on configuration.""" source = config.get(CONF_SOURCE).lower() zone_entity_id = config.get(CONF_ZONE) trigger_event = config.get(CONF_EVENT)
VIDEO_CODEC_LIBX264, ) _LOGGER = logging.getLogger(__name__) MAX_PORT = 65535 VALID_VIDEO_CODECS = [ VIDEO_CODEC_LIBX264, VIDEO_CODEC_H264_OMX, AUDIO_CODEC_COPY ] VALID_AUDIO_CODECS = [AUDIO_CODEC_OPUS, VIDEO_CODEC_COPY] BASIC_INFO_SCHEMA = vol.Schema({ vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_LINKED_BATTERY_SENSOR): cv.entity_domain(sensor.DOMAIN), vol.Optional(CONF_LINKED_BATTERY_CHARGING_SENSOR): cv.entity_domain(binary_sensor.DOMAIN), vol.Optional(CONF_LOW_BATTERY_THRESHOLD, default=DEFAULT_LOW_BATTERY_THRESHOLD): cv.positive_int, }) FEATURE_SCHEMA = BASIC_INFO_SCHEMA.extend( {vol.Optional(CONF_FEATURE_LIST, default=None): cv.ensure_list}) CAMERA_SCHEMA = BASIC_INFO_SCHEMA.extend({ vol.Optional(CONF_STREAM_ADDRESS): vol.All(ipaddress.ip_address, cv.string), vol.Optional(CONF_STREAM_SOURCE): cv.string,