Python voluptuous.In() Examples
The following are 14
code examples of voluptuous.In().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
voluptuous
, or try the search function
.
Example #1
Source File: config.py From spid-testenv2 with GNU Affero General Public License v3.0 | 7 votes |
def _init_schema(self): self._schema = { Required('key_file'): str, Required('cert_file'): str, Required('base_url'): Url(), 'host': str, 'port': Any(int, str), 'debug': bool, 'https': bool, 'https_cert_file': str, 'https_key_file': str, 'users_file': str, 'behind_reverse_proxy': bool, 'can_add_user': bool, 'storage': All(str, In(['file', 'postgres'])), 'db_url': str, 'endpoints': { 'single_logout_service': str, 'single_sign_on_service': str, }, 'metadata': { 'local': All([str], Length(min=0)), 'remote': All([str], Length(min=0)), } }
Example #2
Source File: config_flow.py From unifiprotect with MIT License | 6 votes |
def _show_setup_form(self, errors=None): """Show the setup form to the user.""" return self.async_show_form( step_id="user", data_schema=vol.Schema( { vol.Required(CONF_HOST): str, vol.Required(CONF_PORT, default=DEFAULT_PORT): int, vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str, vol.Optional( CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL ): vol.All(vol.Coerce(int), vol.Range(min=2, max=20)), vol.Optional(CONF_SNAPSHOT_DIRECT, default=False): bool, vol.Optional(CONF_IR_ON, default=TYPE_IR_AUTO): vol.In(TYPES_IR_ON), vol.Optional(CONF_IR_OFF, default=TYPE_IR_OFF): vol.In( TYPES_IR_OFF ), } ), errors=errors or {}, )
Example #3
Source File: config_flow.py From havcs with Apache License 2.0 | 6 votes |
def async_step_base(self, user_input=None): errors = {} if user_input is not None: self._mode = user_input.get('mode') self._device_config = 'ui' if user_input[CONF_DEVICE_CONFIG] else 'text' user_input.pop(CONF_DEVICE_CONFIG) self._platform=[key for key in user_input if user_input[key] is True] if not self._platform: errors['base'] = 'platform_validation' elif self._mode == 0: errors[CONF_MODE] = 'mode_validation' else: return await self.async_step_access() else: user_input = {} fields = OrderedDict() for platform in DEVICE_PLATFORM_DICT.keys(): fields[vol.Optional(platform, default = user_input.get(platform, False))] = bool fields[vol.Optional(CONF_MODE, default = user_input.get(CONF_MODE, 0))] = vol.In({0: '选择运行模式', 1: '模式1 - http(自建技能)', 2: '模式2 - http+proxy(自建技能)', 3: '模式3 - HAVCS服务(音箱APP技能)'}) fields[vol.Optional(CONF_DEVICE_CONFIG, default = user_input.get(CONF_DEVICE_CONFIG, True))] = bool return self.async_show_form( step_id='base', data_schema=vol.Schema(fields), errors=errors)
Example #4
Source File: config_flow.py From pyduofern with GNU General Public License v2.0 | 5 votes |
def async_step_user(self, user_input=None): errors = {} if user_input is not None: if len(user_input['code']) != 4: errors["base"] = "not_hex" else: try: if hex(int(user_input['code'], 16)).lower() != "0x" + user_input['code'].lower(): errors["base"] = "not_hex" except ValueError: errors["base"] = "not_hex" if not errors: return self.async_create_entry( title='duofern', data=user_input ) if os.path.isdir("/dev/serial/by-id"): serialdevs = set(os.listdir("/dev/serial/by-id/")) else: serialdevs=["could not find /dev/serial/by-id/, did you plug in your dufoern stick correctly?"] return self.async_show_form( step_id='user', data_schema=vol.Schema({ vol.Required('code'): str, vol.Optional('serial_port', default="/dev/serial/by-id/usb-Rademacher_DuoFern_USB-Stick_WR04ZFP4-if00-port0"): vol.In(serialdevs), vol.Optional('config_file', default=os.path.join(os.path.dirname(__file__), "../../duofern.json")): str }), errors=errors )
Example #5
Source File: configuration_schema.py From integration with MIT License | 5 votes |
def hacs_config_option_schema(options: dict = {}) -> dict: """Return a shcema for HACS configuration options.""" if not options: options = { APPDAEMON: False, COUNTRY: "ALL", DEBUG: False, EXPERIMENTAL: False, NETDAEMON: False, RELEASE_LIMIT: 5, SIDEPANEL_ICON: "hacs:hacs", SIDEPANEL_TITLE: "HACS", FRONTEND_REPO: "", FRONTEND_REPO_URL: "", } return { vol.Optional(SIDEPANEL_TITLE, default=options.get(SIDEPANEL_TITLE)): str, vol.Optional(SIDEPANEL_ICON, default=options.get(SIDEPANEL_ICON)): str, vol.Optional(RELEASE_LIMIT, default=options.get(RELEASE_LIMIT)): int, vol.Optional(COUNTRY, default=options.get(COUNTRY)): vol.In(LOCALE), vol.Optional(APPDAEMON, default=options.get(APPDAEMON)): bool, vol.Optional(NETDAEMON, default=options.get(NETDAEMON)): bool, vol.Optional(DEBUG, default=options.get(DEBUG)): bool, vol.Optional(EXPERIMENTAL, default=options.get(EXPERIMENTAL)): bool, vol.Optional(FRONTEND_REPO, default=options.get(FRONTEND_REPO)): str, vol.Optional(FRONTEND_REPO_URL, default=options.get(FRONTEND_REPO_URL)): str, }
Example #6
Source File: config_flow.py From esxi_stats with MIT License | 5 votes |
def async_step_esxi_options(self, user_input=None): """Manage ESXi Stats Options.""" if user_input is not None: self.options[CONF_HOST_STATE] = user_input[CONF_HOST_STATE] self.options[CONF_DS_STATE] = user_input[CONF_DS_STATE] self.options[CONF_LIC_STATE] = user_input[CONF_LIC_STATE] self.options[CONF_VM_STATE] = user_input[CONF_VM_STATE] return self.async_create_entry(title="", data=self.options) return self.async_show_form( step_id="esxi_options", data_schema=vol.Schema( { vol.Optional( CONF_HOST_STATE, default=self.config_entry.options.get( CONF_HOST_STATE, DEFAULT_HOST_STATE ), ): vol.In(VMHOST_STATES), vol.Optional( CONF_DS_STATE, default=self.config_entry.options.get( CONF_DS_STATE, DEFAULT_DS_STATE ), ): vol.In(DATASTORE_STATES), vol.Optional( CONF_LIC_STATE, default=self.config_entry.options.get( CONF_LIC_STATE, DEFAULT_LIC_STATE ), ): vol.In(LICENSE_STATES), vol.Optional( CONF_VM_STATE, default=self.config_entry.options.get( CONF_VM_STATE, DEFAULT_VM_STATE ), ): vol.In(VM_STATES), } ), )
Example #7
Source File: template_syntax_validator_v3.py From vitrage with Apache License 2.0 | 5 votes |
def _metadata_schema(): return Schema({ Required(TF.VERSION, msg=63): In( TemplateSchemaFactory.supported_versions()), Required(TF.NAME, msg=60): any_str, TF.DESCRIPTION: any_str, Required(TF.TYPE, msg=64): In(TemplateTypes.types(), msg=64), })
Example #8
Source File: template_syntax_validator_v3.py From vitrage with Apache License 2.0 | 5 votes |
def _raise_alarm_schema(template): return Schema({ Optional(ActionType.RAISE_ALARM): Schema({ Required(TF.SEVERITY, msg=126): any_str, Required(TF.TARGET, msg=10100): In(template.get(TF.ENTITIES, {}).keys(), msg=10101), Required(TF.ALARM_NAME, msg=10104): any_str, Optional(TF.CAUSING_ALARM): In(template.get(TF.ENTITIES, {}).keys(), msg=10107), })})
Example #9
Source File: template_syntax_validator_v3.py From vitrage with Apache License 2.0 | 5 votes |
def _set_state_schema(template): return Schema({ Optional(ActionType.SET_STATE): Schema({ Required(TF.STATE, msg=128): any_str, Required(TF.TARGET, msg=10100): In(template.get(TF.ENTITIES, {}).keys(), msg=10101), })})
Example #10
Source File: template_syntax_validator_v3.py From vitrage with Apache License 2.0 | 5 votes |
def _add_causal_relationship_schema(template): return Schema({ Optional(ActionType.ADD_CAUSAL_RELATIONSHIP): Schema({ Required(TF.SOURCE, msg=10102): In(template.get(TF.ENTITIES, {}).keys(), msg=10103), Required(TF.TARGET, msg=10100): In(template.get(TF.ENTITIES, {}).keys(), msg=10101), })})
Example #11
Source File: template_syntax_validator_v3.py From vitrage with Apache License 2.0 | 5 votes |
def _mark_down_schema(template): return Schema({ Optional(ActionType.MARK_DOWN): Schema({ Required(TF.TARGET, msg=10100): In(template.get(TF.ENTITIES, {}).keys(), msg=10101), })})
Example #12
Source File: configuration_schema.py From SmartHouse with MIT License | 5 votes |
def hacs_config_option_schema(options: dict = {}) -> dict: """Return a shcema for HACS configuration options.""" if not options: options = {COUNTRY: "ALL", DEBUG: False, RELEASE_LIMIT: 5, EXPERIMENTAL: False} return { vol.Optional(COUNTRY, default=options.get(COUNTRY)): vol.In(LOCALE), vol.Optional(RELEASE_LIMIT, default=options.get(RELEASE_LIMIT)): int, vol.Optional(EXPERIMENTAL, default=options.get(EXPERIMENTAL)): bool, vol.Optional(DEBUG, default=options.get(DEBUG)): bool, }
Example #13
Source File: config_schema.py From climate.programmable_thermostat with The Unlicense | 5 votes |
def get_config_flow_schema(config: dict = {}, config_flow_step: int = 0) -> dict: if not config: config = { CONF_NAME: DEFAULT_NAME, CONF_HEATER: "", CONF_COOLER: "", CONF_SENSOR: "", CONF_TARGET: "", CONF_MAX_TEMP: DEFAULT_MAX_TEMP, CONF_MIN_TEMP: DEFAULT_MIN_TEMP, CONF_TOLERANCE: DEFAULT_TOLERANCE, CONF_RELATED_CLIMATE: "", CONF_HVAC_OPTIONS: DEFAULT_HVAC_OPTIONS, CONF_AUTO_MODE: DEFAULT_AUTO_MODE, CONF_INITIAL_HVAC_MODE: "" } if config_flow_step==1: return { vol.Optional(CONF_NAME, default=config.get(CONF_NAME)): str, vol.Optional(CONF_HEATER, default=config.get(CONF_HEATER)): str, vol.Optional(CONF_COOLER, default=config.get(CONF_COOLER)): str, vol.Required(CONF_SENSOR, default=config.get(CONF_SENSOR)): str, vol.Required(CONF_TARGET, default=config.get(CONF_TARGET)): str } elif config_flow_step==2: return { vol.Optional(CONF_MAX_TEMP, default=config.get(CONF_MAX_TEMP)): int, vol.Optional(CONF_MIN_TEMP, default=config.get(CONF_MIN_TEMP)): int, vol.Optional(CONF_TOLERANCE, default=config.get(CONF_TOLERANCE)): float } elif config_flow_step==3: return { vol.Optional(CONF_RELATED_CLIMATE, default=config.get(CONF_RELATED_CLIMATE)): str, vol.Optional(CONF_HVAC_OPTIONS, default=config.get(CONF_HVAC_OPTIONS)): vol.In(range(MAX_HVAC_OPTIONS)), vol.Optional(CONF_AUTO_MODE, default=config.get(CONF_AUTO_MODE)): vol.In(AUTO_MODE_OPTIONS), vol.Optional(CONF_INITIAL_HVAC_MODE, default=config.get(CONF_INITIAL_HVAC_MODE)): vol.In(INITIAL_HVAC_MODE_OPTIONS) } return {}
Example #14
Source File: gnocchi.py From cloudkitty with Apache License 2.0 | 4 votes |
def _fetch_resources(self, metric_name, start, end, project_id=None, q_filter=None): """Get resources during the timeframe. :type metric_name: str :param start: Start of the timeframe. :param end: End of the timeframe if needed. :param project_id: Filter on a specific tenant/project. :type project_id: str :param q_filter: Append a custom filter. :type q_filter: list """ # Get gnocchi specific conf extra_args = self.conf[metric_name]['extra_args'] resource_type = extra_args['resource_type'] scope_key = CONF.collect.scope_key # Build query # FIXME(peschk_l): In order not to miss any resource whose metrics may # contain measures after its destruction, we scan resources over three # collect periods. delta = timedelta(seconds=CONF.collect.period) start = tzutils.substract_delta(start, delta) end = tzutils.add_delta(end, delta) query_parameters = self._generate_time_filter(start, end) if project_id: kwargs = {scope_key: project_id} query_parameters.append(self.gen_filter(**kwargs)) if q_filter: query_parameters.append(q_filter) sorts = [extra_args['resource_key'] + ':asc'] resources = [] marker = None while True: resources_chunk = self._conn.resource.search( resource_type=resource_type, query=self.extend_filter(*query_parameters), sorts=sorts, marker=marker) if len(resources_chunk) < 1: break resources += resources_chunk marker = resources_chunk[-1][extra_args['resource_key']] return {res[extra_args['resource_key']]: res for res in resources}