def _validator_codes(val_validator: Callable[[Any], TValidated], val_default: Any, code_validator: Callable[[Any], TCodeIndex]): schema_validator = vol.Schema({ vol.Optional(CONF_DEFAULT, default=val_default): val_validator, code_validator: val_validator, }) if val_validator is cv.boolean: schema_validator = vol.Any( schema_validator, vol.All( [vol.Any(vol.Equal(CONF_DEFAULT), code_validator)], vol.Any( vol.All( vol.Contains(CONF_DEFAULT), lambda x: { **dict.fromkeys(x, False), CONF_DEFAULT: True }), lambda x: { **dict.fromkeys(x, True), CONF_DEFAULT: False }), )) return vol.All(schema_validator, vol.Coerce(_SubValidated))
def _validator_multi(val_validator: Callable[[Any], TValidated], val_defaults: Mapping[str, TValidated], idx_keys: Collection[str]): if idx_keys is None: idx_keys = tuple(ENTITY_CODES_VALIDATORS.keys()) elif not isinstance(idx_keys, tuple): idx_keys = tuple(idx_keys) single_validator = _validator_single(val_validator, idx_keys) multi_validator = vol.Schema({ vol.Optional(key, default=val_defaults[key]): val_validator for key in idx_keys }) if val_validator is cv.boolean: multi_validator = vol.Any( multi_validator, vol.All( [vol.Any(vol.Equal(CONF_DEFAULT), vol.In(idx_keys))], vol.Any( vol.All( vol.Contains(CONF_DEFAULT), lambda x: {key: (key not in x) for key in idx_keys}), lambda x: {key: (key in x) for key in idx_keys}))) return vol.All(vol.Any(single_validator, lambda x: x), multi_validator)
def _lazy_filter_schema(value: Any): global FILTER_SCHEMA if FILTER_SCHEMA is not None: return FILTER_SCHEMA(value) platforms = lazy_load_platforms_base_class() singular_validator = vol.Any( vol.All(vol.Any(vol.Equal(["*"]), vol.Equal(True)), lambda x: ["*"]), vol.All(vol.Any(vol.Equal([]), vol.Equal(False)), lambda x: []), ) multiple_validator = vol.Any( vol.All(vol.Equal(True), lambda x: ["*"]), vol.All(vol.Equal(False), lambda x: []), vol.All(cv.ensure_list, [cv.string]), ) FILTER_SCHEMA = vol.Schema({ vol.Optional(cls.CONFIG_KEY, default=lambda: ["*"]): (singular_validator if cls.SINGULAR_FILTER else multiple_validator) for base_cls in platforms.values() for cls in base_cls.__subclasses__() }) return FILTER_SCHEMA(value)
async def async_setup_entry(hass, config_entry): """Set up VocalBox as config entry.""" vocalbox = VocalBox(hass, config_entry.data[CONF_EMAIL], config_entry.data[CONF_PASSWORD]) coordinator = DataUpdateCoordinator( hass, _LOGGER, name=DOMAIN, update_method=vocalbox.async_fetch_datas, update_interval=SCAN_INTERVAL, ) await coordinator.async_refresh() if not coordinator.last_update_success: raise PlatformNotReady if coordinator.data is None: return False hass.data[DOMAIN] = coordinator hass.async_create_task( hass.config_entries.async_forward_entry_setup(config_entry, "binary_sensor")) service_clean_schema = vol.Schema({ vol.Required(ATTR_ID): vol.Any(cv.positive_int, vol.Equal("all")), vol.Required(ATTR_TYPE): vol.All(cv.string, vol.In(VALUES_TYPE)), }) async def async_vocalbox_clean(call) -> None: # pylint: disable=unused-argument """Handle restart service call.""" try: await vocalbox.async_delete_datas(call.data[ATTR_ID], call.data[ATTR_TYPE]) await coordinator.async_refresh() except VocalboxError as error: _LOGGER.error(error) hass.services.async_register(DOMAIN, SERVICE_CLEAN, async_vocalbox_clean, service_clean_schema) return True
vol.Optional(ATTR_INIT, default=True): vol.Boolean(), vol.Optional(ATTR_ADVANCED, default=False): vol.Boolean(), vol.Optional(ATTR_STAGE, default=AddonStages.STABLE): vol.Coerce(AddonStages), vol.Optional(ATTR_PORTS): DOCKER_PORTS, vol.Optional(ATTR_PORTS_DESCRIPTION): DOCKER_PORTS_DESCRIPTION, vol.Optional(ATTR_WEBUI): vol.Match(r"^(?:https?|\[PROTO:\w+\]):\/\/\[HOST\]:\[PORT:\d+\].*$"), vol.Optional(ATTR_INGRESS, default=False): vol.Boolean(), vol.Optional(ATTR_INGRESS_PORT, default=8099): vol.Any(network_port, vol.Equal(0)), vol.Optional(ATTR_INGRESS_ENTRY): vol.Coerce(str), vol.Optional(ATTR_PANEL_ICON, default="mdi:puzzle"): vol.Coerce(str), vol.Optional(ATTR_PANEL_TITLE): vol.Coerce(str), vol.Optional(ATTR_PANEL_ADMIN, default=True): vol.Boolean(), vol.Optional(ATTR_HOMEASSISTANT): vol.Maybe(vol.Coerce(str)), vol.Optional(ATTR_HOST_NETWORK, default=False): vol.Boolean(), vol.Optional(ATTR_HOST_PID, default=False): vol.Boolean(), vol.Optional(ATTR_HOST_IPC, default=False):
vol.Optional(ATTR_URL): vol.Url(), vol.Required(ATTR_STARTUP): vol.All(_simple_startup, vol.In(STARTUP_ALL)), vol.Required(ATTR_BOOT): vol.In([BOOT_AUTO, BOOT_MANUAL]), vol.Optional(ATTR_PORTS): DOCKER_PORTS, vol.Optional(ATTR_PORTS_DESCRIPTION): DOCKER_PORTS_DESCRIPTION, vol.Optional(ATTR_WEBUI): vol.Match(r"^(?:https?|\[PROTO:\w+\]):\/\/\[HOST\]:\[PORT:\d+\].*$"), vol.Optional(ATTR_INGRESS, default=False): vol.Boolean(), vol.Optional(ATTR_INGRESS_PORT, default=8099): vol.Any(NETWORK_PORT, vol.Equal(0)), vol.Optional(ATTR_INGRESS_ENTRY): vol.Coerce(str), vol.Optional(ATTR_PANEL_ICON, default="mdi:puzzle"): vol.Coerce(str), vol.Optional(ATTR_PANEL_TITLE): vol.Coerce(str), vol.Optional(ATTR_PANEL_ADMIN, default=True): vol.Boolean(), vol.Optional(ATTR_HOMEASSISTANT): vol.Maybe(vol.Coerce(str)), vol.Optional(ATTR_HOST_NETWORK, default=False): vol.Boolean(), vol.Optional(ATTR_HOST_PID, default=False): vol.Boolean(), vol.Optional(ATTR_HOST_IPC, default=False):
ATTR_FORMATTER = "formatter" ATTR_INVERSE = "inverse" ATTR_FEATURE = "feature" ATTR_ADDITIONAL_ATTRIBUTES = "additional_attributes" ATTR_DEFAULT = "default" DEFAULT_NAME_FORMAT = "{device_name} {type_name}" MIN_POLLING_INTERVAL = timedelta(seconds=10) DEFAULT_POLLING_INTERVAL = timedelta(minutes=1) DEFAULT_EXECUTION_DELAY = timedelta(seconds=15) _LOGGER = logging.getLogger(__name__) _PLATFORM_OPTION_SCHEMA = vol.Any(cv.boolean, vol.All(cv.ensure_list, [cv.string])) _DEVICE_INDEX_SCHEMA = vol.Any(vol.Equal(ATTR_DEFAULT), cv.string) _PLATFORM_CONFIG_SCHEMA = vol.Any( vol.All(_PLATFORM_OPTION_SCHEMA, lambda x: {ATTR_DEFAULT: x}), {_DEVICE_INDEX_SCHEMA: _PLATFORM_OPTION_SCHEMA}) PANDORA_ACCOUNT_SCHEMA = vol.Schema({ vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string, vol.Optional(CONF_USER_AGENT): cv.string, vol.Optional(CONF_NAME_FORMAT, default=DEFAULT_NAME_FORMAT): cv.string, vol.Optional(CONF_POLLING_INTERVAL, default=DEFAULT_POLLING_INTERVAL): vol.All(cv.time_period, vol.Clamp(min=MIN_POLLING_INTERVAL)),
def register_services(hass): """Register services for the component.""" service_reset_schema = vol.Schema( { vol.Required(ATTR_GW_ID): vol.All( cv.string, vol.In(hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS]) ) } ) service_set_clock_schema = vol.Schema( { vol.Required(ATTR_GW_ID): vol.All( cv.string, vol.In(hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS]) ), vol.Optional(ATTR_DATE, default=date.today()): cv.date, vol.Optional(ATTR_TIME, default=datetime.now().time()): cv.time, } ) service_set_control_setpoint_schema = vol.Schema( { vol.Required(ATTR_GW_ID): vol.All( cv.string, vol.In(hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS]) ), vol.Required(ATTR_TEMPERATURE): vol.All( vol.Coerce(float), vol.Range(min=0, max=90) ), } ) service_set_hot_water_ovrd_schema = vol.Schema( { vol.Required(ATTR_GW_ID): vol.All( cv.string, vol.In(hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS]) ), vol.Required(ATTR_DHW_OVRD): vol.Any( vol.Equal("A"), vol.All(vol.Coerce(int), vol.Range(min=0, max=1)) ), } ) service_set_gpio_mode_schema = vol.Schema( vol.Any( vol.Schema( { vol.Required(ATTR_GW_ID): vol.All( cv.string, vol.In(hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS]) ), vol.Required(ATTR_ID): vol.Equal("A"), vol.Required(ATTR_MODE): vol.All( vol.Coerce(int), vol.Range(min=0, max=6) ), } ), vol.Schema( { vol.Required(ATTR_GW_ID): vol.All( cv.string, vol.In(hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS]) ), vol.Required(ATTR_ID): vol.Equal("B"), vol.Required(ATTR_MODE): vol.All( vol.Coerce(int), vol.Range(min=0, max=7) ), } ), ) ) service_set_led_mode_schema = vol.Schema( { vol.Required(ATTR_GW_ID): vol.All( cv.string, vol.In(hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS]) ), vol.Required(ATTR_ID): vol.In("ABCDEF"), vol.Required(ATTR_MODE): vol.In("RXTBOFHWCEMP"), } ) service_set_max_mod_schema = vol.Schema( { vol.Required(ATTR_GW_ID): vol.All( cv.string, vol.In(hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS]) ), vol.Required(ATTR_LEVEL): vol.All( vol.Coerce(int), vol.Range(min=-1, max=100) ), } ) service_set_oat_schema = vol.Schema( { vol.Required(ATTR_GW_ID): vol.All( cv.string, vol.In(hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS]) ), vol.Required(ATTR_TEMPERATURE): vol.All( vol.Coerce(float), vol.Range(min=-40, max=99) ), } ) service_set_sb_temp_schema = vol.Schema( { vol.Required(ATTR_GW_ID): vol.All( cv.string, vol.In(hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS]) ), vol.Required(ATTR_TEMPERATURE): vol.All( vol.Coerce(float), vol.Range(min=0, max=30) ), } ) async def reset_gateway(call): """Reset the OpenTherm Gateway.""" gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]] mode_rst = gw_vars.OTGW_MODE_RESET status = await gw_dev.gateway.set_mode(mode_rst) gw_dev.status = status async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status) hass.services.async_register( DOMAIN, SERVICE_RESET_GATEWAY, reset_gateway, service_reset_schema ) async def set_control_setpoint(call): """Set the control setpoint on the OpenTherm Gateway.""" gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]] gw_var = gw_vars.DATA_CONTROL_SETPOINT value = await gw_dev.gateway.set_control_setpoint(call.data[ATTR_TEMPERATURE]) gw_dev.status.update({gw_var: value}) async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status) hass.services.async_register( DOMAIN, SERVICE_SET_CONTROL_SETPOINT, set_control_setpoint, service_set_control_setpoint_schema, ) async def set_dhw_ovrd(call): """Set the domestic hot water override on the OpenTherm Gateway.""" gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]] gw_var = gw_vars.OTGW_DHW_OVRD value = await gw_dev.gateway.set_hot_water_ovrd(call.data[ATTR_DHW_OVRD]) gw_dev.status.update({gw_var: value}) async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status) hass.services.async_register( DOMAIN, SERVICE_SET_HOT_WATER_OVRD, set_dhw_ovrd, service_set_hot_water_ovrd_schema, ) async def set_device_clock(call): """Set the clock on the OpenTherm Gateway.""" gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]] attr_date = call.data[ATTR_DATE] attr_time = call.data[ATTR_TIME] await gw_dev.gateway.set_clock(datetime.combine(attr_date, attr_time)) hass.services.async_register( DOMAIN, SERVICE_SET_CLOCK, set_device_clock, service_set_clock_schema ) async def set_gpio_mode(call): """Set the OpenTherm Gateway GPIO modes.""" gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]] gpio_id = call.data[ATTR_ID] gpio_mode = call.data[ATTR_MODE] mode = await gw_dev.gateway.set_gpio_mode(gpio_id, gpio_mode) gpio_var = getattr(gw_vars, f"OTGW_GPIO_{gpio_id}") gw_dev.status.update({gpio_var: mode}) async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status) hass.services.async_register( DOMAIN, SERVICE_SET_GPIO_MODE, set_gpio_mode, service_set_gpio_mode_schema ) async def set_led_mode(call): """Set the OpenTherm Gateway LED modes.""" gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]] led_id = call.data[ATTR_ID] led_mode = call.data[ATTR_MODE] mode = await gw_dev.gateway.set_led_mode(led_id, led_mode) led_var = getattr(gw_vars, f"OTGW_LED_{led_id}") gw_dev.status.update({led_var: mode}) async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status) hass.services.async_register( DOMAIN, SERVICE_SET_LED_MODE, set_led_mode, service_set_led_mode_schema ) async def set_max_mod(call): """Set the max modulation level.""" gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]] gw_var = gw_vars.DATA_SLAVE_MAX_RELATIVE_MOD level = call.data[ATTR_LEVEL] if level == -1: # Backend only clears setting on non-numeric values. level = "-" value = await gw_dev.gateway.set_max_relative_mod(level) gw_dev.status.update({gw_var: value}) async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status) hass.services.async_register( DOMAIN, SERVICE_SET_MAX_MOD, set_max_mod, service_set_max_mod_schema ) async def set_outside_temp(call): """Provide the outside temperature to the OpenTherm Gateway.""" gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]] gw_var = gw_vars.DATA_OUTSIDE_TEMP value = await gw_dev.gateway.set_outside_temp(call.data[ATTR_TEMPERATURE]) gw_dev.status.update({gw_var: value}) async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status) hass.services.async_register( DOMAIN, SERVICE_SET_OAT, set_outside_temp, service_set_oat_schema ) async def set_setback_temp(call): """Set the OpenTherm Gateway SetBack temperature.""" gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]] gw_var = gw_vars.OTGW_SB_TEMP value = await gw_dev.gateway.set_setback_temp(call.data[ATTR_TEMPERATURE]) gw_dev.status.update({gw_var: value}) async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status) hass.services.async_register( DOMAIN, SERVICE_SET_SB_TEMP, set_setback_temp, service_set_sb_temp_schema )
} COLOR_SCHEMA = vol.Or( vol.All(vol.Length(min=3, max=3), vol.ExactSequence((cv.byte, cv.byte, cv.byte)), vol.Coerce(tuple)), vol.All(vol.Length(min=4, max=4), vol.ExactSequence((cv.byte, cv.byte, cv.byte, cv.byte)), vol.Coerce(tuple)) ) PERCENT_SCHEMA = vol.All(vol.Coerce(float), vol.Range(min=0, max=100)) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_HOST): cv.string, vol.Required(CONF_TOKEN): vol.All(str, vol.Length(min=32, max=32)), vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string, vol.Optional(CONF_COUNTRY, default=None): vol.Or(vol.In(CONF_AVAILABLE_COUNTRIES), vol.Equal(None)), vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_AUTO_UPDATE, default=True): cv.boolean, vol.Optional(CONF_COLORS, default={}): vol.Schema({ vol.In(CONF_AVAILABLE_COLORS): COLOR_SCHEMA }), vol.Optional(CONF_ROOM_COLORS, default={}): vol.Schema({ cv.positive_int: COLOR_SCHEMA }), vol.Optional(CONF_DRAW, default=[]): vol.All(cv.ensure_list, [vol.In(CONF_AVAILABLE_DRAWABLES)]), vol.Optional(CONF_MAP_TRANSFORM, default={CONF_SCALE: 1, CONF_ROTATE: 0, CONF_TRIM: DEFAULT_TRIMS}): vol.Schema({ vol.Optional(CONF_SCALE, default=1): vol.All(vol.Coerce(float), vol.Range(min=0)), vol.Optional(CONF_ROTATE, default=0): vol.In([0, 90, 180, 270]), vol.Optional(CONF_TRIM, default=DEFAULT_TRIMS): vol.Schema({ vol.Optional(CONF_LEFT, default=0): PERCENT_SCHEMA,
vol.Optional(ATTR_TIME, default=datetime.now().time()): cv.time, }) SERVICE_SET_CONTROL_SETPOINT = 'set_control_setpoint' SERVICE_SET_CONTROL_SETPOINT_SCHEMA = vol.Schema({ vol.Required(ATTR_TEMPERATURE): vol.All(vol.Coerce(float), vol.Range(min=0, max=90)), }) SERVICE_SET_GPIO_MODE = 'set_gpio_mode' SERVICE_SET_GPIO_MODE_SCHEMA = vol.Schema( vol.Any( vol.Schema({ vol.Required(ATTR_ID): vol.Equal('A'), vol.Required(ATTR_MODE): vol.All(vol.Coerce(int), vol.Range(min=0, max=6)), }), vol.Schema({ vol.Required(ATTR_ID): vol.Equal('B'), vol.Required(ATTR_MODE): vol.All(vol.Coerce(int), vol.Range(min=0, max=7)), }), )) SERVICE_SET_LED_MODE = 'set_led_mode' SERVICE_SET_LED_MODE_SCHEMA = vol.Schema({ vol.Required(ATTR_ID): vol.In('ABCDEF'),
vol.Required(ATTR_VERSION): vol.Coerce(str), vol.Required(ATTR_SLUG): vol.Coerce(str), vol.Required(ATTR_DESCRIPTON): vol.Coerce(str), vol.Required(ATTR_ARCH): [vol.In(ARCH_ALL)], vol.Optional(ATTR_MACHINE): [vol.In(MACHINE_ALL)], vol.Optional(ATTR_URL): vol.Url(), vol.Required(ATTR_STARTUP): vol.All(_simple_startup, vol.In(STARTUP_ALL)), vol.Required(ATTR_BOOT): vol.In([BOOT_AUTO, BOOT_MANUAL]), vol.Optional(ATTR_PORTS): DOCKER_PORTS, vol.Optional(ATTR_PORTS_DESCRIPTION): DOCKER_PORTS_DESCRIPTION, vol.Optional(ATTR_WEBUI): vol.Match(r"^(?:https?|\[PROTO:\w+\]):\/\/\[HOST\]:\[PORT:\d+\].*$"), vol.Optional(ATTR_INGRESS, default=False): vol.Boolean(), vol.Optional(ATTR_INGRESS_PORT, default=8099): vol.Any(NETWORK_PORT, vol.Equal(0)), vol.Optional(ATTR_INGRESS_ENTRY): vol.Coerce(str), vol.Optional(ATTR_PANEL_ICON, default="mdi:puzzle"): vol.Coerce(str), vol.Optional(ATTR_PANEL_TITLE): vol.Coerce(str), vol.Optional(ATTR_PANEL_ADMIN, default=True): vol.Boolean(), vol.Optional(ATTR_HOMEASSISTANT): vol.Maybe(vol.Coerce(str)), vol.Optional(ATTR_HOST_NETWORK, default=False): vol.Boolean(), vol.Optional(ATTR_HOST_PID, default=False): vol.Boolean(), vol.Optional(ATTR_HOST_IPC, default=False): vol.Boolean(), vol.Optional(ATTR_HOST_DBUS, default=False): vol.Boolean(), vol.Optional(ATTR_DEVICES): [vol.Match(r"^(.*):(.*):([rwm]{1,3})$")], vol.Optional(ATTR_AUTO_UART, default=False): vol.Boolean(), vol.Optional(ATTR_TMPFS): vol.Match(r"^size=(\d)*[kmg](,uid=\d{1,4})?(,rw)?$"), vol.Optional(ATTR_MAP, default=list): [vol.Match(RE_VOLUME)], vol.Optional(ATTR_ENVIRONMENT): {vol.Match(r"\w*"): vol.Coerce(str)},
vol.Required(ATTR_STARTUP): vol.All(_simple_startup, vol.Coerce(AddonStartup)), vol.Required(ATTR_BOOT): vol.Coerce(AddonBoot), vol.Optional(ATTR_INIT, default=True): vol.Boolean(), vol.Optional(ATTR_ADVANCED, default=False): vol.Boolean(), vol.Optional(ATTR_STAGE, default=AddonStage.STABLE): vol.Coerce(AddonStage), vol.Optional(ATTR_PORTS): docker_ports, vol.Optional(ATTR_PORTS_DESCRIPTION): docker_ports_description, vol.Optional(ATTR_WATCHDOG): vol.Match( r"^(?:https?|\[PROTO:\w+\]|tcp):\/\/\[HOST\]:\[PORT:\d+\].*$" ), vol.Optional(ATTR_WEBUI): vol.Match( r"^(?:https?|\[PROTO:\w+\]):\/\/\[HOST\]:\[PORT:\d+\].*$" ), vol.Optional(ATTR_INGRESS, default=False): vol.Boolean(), vol.Optional(ATTR_INGRESS_PORT, default=8099): vol.Any( network_port, vol.Equal(0) ), vol.Optional(ATTR_INGRESS_ENTRY): vol.Coerce(str), vol.Optional(ATTR_PANEL_ICON, default="mdi:puzzle"): vol.Coerce(str), vol.Optional(ATTR_PANEL_TITLE): vol.Coerce(str), vol.Optional(ATTR_PANEL_ADMIN, default=True): vol.Boolean(), vol.Optional(ATTR_OPENPEERPOWER): vol.Maybe(version_tag), vol.Optional(ATTR_HOST_NETWORK, default=False): vol.Boolean(), vol.Optional(ATTR_HOST_PID, default=False): vol.Boolean(), vol.Optional(ATTR_HOST_IPC, default=False): vol.Boolean(), vol.Optional(ATTR_HOST_DBUS, default=False): vol.Boolean(), vol.Optional(ATTR_DEVICES): [vol.Match(r"^(.*):(.*):([rwm]{1,3})$")], vol.Optional(ATTR_AUTO_UART, default=False): vol.Boolean(), vol.Optional(ATTR_UDEV, default=False): vol.Boolean(), vol.Optional(ATTR_TMPFS): vol.Match(r"^size=(\d)*[kmg](,uid=\d{1,4})?(,rw)?$"), vol.Optional(ATTR_MAP, default=list): [vol.Match(RE_VOLUME)],
PERCENT_SCHEMA = vol.All(vol.Coerce(float), vol.Range(min=0, max=100)) POSITIVE_FLOAT_SCHEMA = vol.All(vol.Coerce(float), vol.Range(min=0)) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Required(CONF_TOKEN): vol.All(str, vol.Length(min=32, max=32)), vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string, vol.Optional(CONF_COUNTRY, default=None): vol.Or(vol.In(CONF_AVAILABLE_COUNTRIES), vol.Equal(None)), vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_AUTO_UPDATE, default=True): cv.boolean, vol.Optional(CONF_COLORS, default={}): vol.Schema({vol.In(CONF_AVAILABLE_COLORS): COLOR_SCHEMA}), vol.Optional(CONF_ROOM_COLORS, default={}): vol.Schema({cv.positive_int: COLOR_SCHEMA}), vol.Optional(CONF_DRAW, default=[]): vol.All(cv.ensure_list, [vol.In(CONF_AVAILABLE_DRAWABLES)]), vol.Optional(CONF_MAP_TRANSFORM, default={ CONF_SCALE: 1, CONF_ROTATE: 0, CONF_TRIM: DEFAULT_TRIMS
vol.Optional(cv.string, lambda x: {CONF_NUMBER: x}), DRIVING_LICENSE_SCHEMA ], ), vol.Optional(CONF_TRACK_FSSP_PROFILES, default=None): vol.All(cv.ensure_list, [FSSP_PROFILE_SCHEMA]), vol.Optional(CONF_NAME_FORMAT, default=lambda: _lazy_name_formats_schema({})): _lazy_name_formats_schema, vol.Optional(CONF_SCAN_INTERVAL, default=lambda: _lazy_scan_intervals_schema({})): _lazy_scan_intervals_schema, vol.Optional(CONF_FILTER, default=lambda: _lazy_filter_schema({})): _lazy_filter_schema, vol.Optional(CONF_TOKEN, default=None): vol.Any(vol.Equal(None), cv.string), }, extra=vol.ALLOW_EXTRA, ) CONFIG_SCHEMA = vol.Schema( { DOMAIN: vol.All( cv.ensure_list, [ OPTIONAL_ENTRY_SCHEMA.extend( { vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string, },
SERVICE_SET_CLOCK = 'set_clock' SERVICE_SET_CLOCK_SCHEMA = vol.Schema({ vol.Optional(ATTR_DATE, default=date.today()): cv.date, vol.Optional(ATTR_TIME, default=datetime.now().time()): cv.time, }) SERVICE_SET_CONTROL_SETPOINT = 'set_control_setpoint' SERVICE_SET_CONTROL_SETPOINT_SCHEMA = vol.Schema({ vol.Required(ATTR_TEMPERATURE): vol.All(vol.Coerce(float), vol.Range(min=0, max=90)), }) SERVICE_SET_GPIO_MODE = 'set_gpio_mode' SERVICE_SET_GPIO_MODE_SCHEMA = vol.Schema(vol.Any( vol.Schema({ vol.Required(ATTR_ID): vol.Equal('A'), vol.Required(ATTR_MODE): vol.All(vol.Coerce(int), vol.Range(min=0, max=6)), }), vol.Schema({ vol.Required(ATTR_ID): vol.Equal('B'), vol.Required(ATTR_MODE): vol.All(vol.Coerce(int), vol.Range(min=0, max=7)), }), )) SERVICE_SET_LED_MODE = 'set_led_mode' SERVICE_SET_LED_MODE_SCHEMA = vol.Schema({ vol.Required(ATTR_ID): vol.In('ABCDEF'), vol.Required(ATTR_MODE): vol.In('RXTBOFHWCEMP'), })
vol.Any( vol.All(cv.ensure_list, [cv.string]), { cv.string: vol.Any(vol.All(cv.ensure_list, [cv.string]), vol.All(cv.boolean, True)) }), }), _adapt_old_config_entry_schema, ) # Outer configuration schema (per-domain) CONFIG_SCHEMA = vol.Schema( { DOMAIN: vol.Any( vol.Equal({}), vol.All(cv.ensure_list, [vol.Any(CONFIG_ENTRY_SCHEMA, OLD_CONFIG_ENTRY_SCHEMA)], vol.Length(min=1))) }, extra=vol.ALLOW_EXTRA, ) @callback def _find_existing_entry( hass: HomeAssistantType, username: str) -> Optional[config_entries.ConfigEntry]: existing_entries = hass.config_entries.async_entries(DOMAIN) for config_entry in existing_entries: if config_entry.data[CONF_USERNAME] == username: