Python voluptuous.Optional() Examples
The following are 30
code examples of voluptuous.Optional().
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_flow.py From SmartHouse with MIT License | 6 votes |
def async_step_init(self, user_input=None): """Handle options flow.""" if user_input is not None: return self.async_create_entry(title="", data=user_input) data_schema = vol.Schema( { vol.Optional( CONF_QUEUE_DELAY, default=self.config_entry.options.get( CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY ), ): vol.All(vol.Coerce(float), vol.Clamp(min=0)) } ) return self.async_show_form(step_id="init", data_schema=data_schema)
Example #2
Source File: __init__.py From cloudkitty with Apache License 2.0 | 6 votes |
def fetch_all(self, metric_name, start, end, project_id=None, q_filter=None): """Fetches information about a specific metric for a given period. This method must respect the ``groupby`` and ``metadata`` arguments provided in the metric conf at initialization. (Available in ``self.conf['groupby']`` and ``self.conf['metadata']``). Returns a list of cloudkitty.dataframe.DataPoint objects. :param metric_name: Name of the metric to fetch :type metric_name: str :param start: start of the period :type start: datetime.datetime :param end: end of the period :type end: datetime.datetime :param project_id: ID of the scope for which data should be collected :type project_id: str :param q_filter: Optional filters :type q_filter: dict """
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 homeassistant-zigate with MIT License | 6 votes |
def async_step_user(self, user_input=None): if self._async_current_entries(): return self.async_abort(reason="single_instance_allowed") if self.hass.data.get(DOMAIN): return self.async_abort(reason="single_instance_allowed") errors = {} fields = OrderedDict() fields[vol.Optional(CONF_PORT)] = str if user_input is not None: print(user_input) return self.async_create_entry(title=user_input.get(CONF_PORT, 'Auto'), data=user_input) return self.async_show_form( step_id="user", data_schema=vol.Schema(fields), errors=errors )
Example #5
Source File: config_flow.py From unifiprotect with MIT License | 6 votes |
def async_step_init(self, user_input=None): """Manage the options.""" if user_input is not None: return self.async_create_entry(title="", data=user_input) return self.async_show_form( step_id="init", data_schema=vol.Schema( { vol.Optional( CONF_SNAPSHOT_DIRECT, default=self.config_entry.options.get( CONF_SNAPSHOT_DIRECT, False ), ): bool, vol.Optional( CONF_SCAN_INTERVAL, default=self.config_entry.options.get( CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL ), ): vol.All(vol.Coerce(int), vol.Range(min=2, max=20)), } ), )
Example #6
Source File: config_flow.py From ShellyForHASS with MIT License | 6 votes |
def async_step_yaml(self, user_input=None): if not user_input: schema = vol.Schema({ vol.Optional("convert", default=False): bool }) return self.async_show_form(step_id="yaml", data_schema=schema) system_options = {} if user_input["convert"]: system_options = self.instance.conf data = {} data[CONF_OBJECT_ID_PREFIX] = \ system_options.get(CONF_OBJECT_ID_PREFIX, "shelly") self.instance.hass.config_entries.async_update_entry( self.config_entry, data=data ) return self.async_create_entry( title="Shelly smart home", data=system_options )
Example #7
Source File: create_schema.py From visonic with Apache License 2.0 | 6 votes |
def create_parameters3(options): # Log file parameters return { vol.Optional(CONF_LOG_EVENT, default=create_default(options, CONF_LOG_EVENT, False)) : bool, vol.Optional(CONF_LOG_DONE, default=create_default(options, CONF_LOG_DONE, False)) : bool, vol.Optional(CONF_LOG_REVERSE, default=create_default(options, CONF_LOG_REVERSE, False)) : bool, vol.Optional(CONF_LOG_CSV_TITLE, default=create_default(options, CONF_LOG_CSV_TITLE, False)) : bool, vol.Optional(CONF_LOG_XML_FN, default=create_default(options, CONF_LOG_XML_FN, "")) : str, vol.Optional(CONF_LOG_CSV_FN, default=create_default(options, CONF_LOG_CSV_FN, "")) : str, vol.Optional(CONF_LOG_MAX_ENTRIES, default=create_default(options, CONF_LOG_MAX_ENTRIES, 10000)) : int }
Example #8
Source File: create_schema.py From visonic with Apache License 2.0 | 6 votes |
def create_parameters2(options): # Panel settings - can be modified/edited return { vol.Optional(CONF_MOTION_OFF_DELAY, default=create_default(options, CONF_MOTION_OFF_DELAY, 120) ) : int, vol.Optional(CONF_SIREN_SOUNDING, default=create_default(options, CONF_SIREN_SOUNDING,["intruder"])) : cv.multi_select(available_siren_values), vol.Optional(CONF_OVERRIDE_CODE, default=create_default(options, CONF_OVERRIDE_CODE, "") ) : str, vol.Optional(CONF_ARM_CODE_AUTO, default=create_default(options, CONF_ARM_CODE_AUTO, False)) : bool, vol.Optional(CONF_FORCE_KEYPAD, default=create_default(options, CONF_FORCE_KEYPAD, False)) : bool, vol.Optional(CONF_INSTANT_ARM_AWAY, default=create_default(options, CONF_INSTANT_ARM_AWAY, False)) : bool, vol.Optional(CONF_INSTANT_ARM_HOME, default=create_default(options, CONF_INSTANT_ARM_HOME, False)) : bool, vol.Optional(CONF_ENABLE_REMOTE_ARM, default=create_default(options, CONF_ENABLE_REMOTE_ARM, False)) : bool, vol.Optional(CONF_ENABLE_REMOTE_DISARM, default=create_default(options, CONF_ENABLE_REMOTE_DISARM, False)) : bool, vol.Optional(CONF_ENABLE_SENSOR_BYPASS, default=create_default(options, CONF_ENABLE_SENSOR_BYPASS, False)) : bool }
Example #9
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 #10
Source File: create_schema.py From visonic with Apache License 2.0 | 6 votes |
def create_parameters1(options): # Panel settings - can only be set on creation return { vol.Required(CONF_LANGUAGE, default=create_default(options, CONF_LANGUAGE, "EN") ) : str, vol.Optional(CONF_EXCLUDE_SENSOR, default=create_default(options, CONF_EXCLUDE_SENSOR, "")) : str, vol.Optional(CONF_EXCLUDE_X10, default=create_default(options, CONF_EXCLUDE_X10, "")) : str, vol.Optional(CONF_DOWNLOAD_CODE, default=create_default(options, CONF_DOWNLOAD_CODE, "") ) : str, vol.Optional(CONF_FORCE_STANDARD, default=create_default(options, CONF_FORCE_STANDARD, False)) : bool, vol.Optional(CONF_FORCE_AUTOENROLL, default=create_default(options, CONF_FORCE_AUTOENROLL, False)) : bool, vol.Optional(CONF_AUTO_SYNC_TIME, default=create_default(options, CONF_AUTO_SYNC_TIME, True)) : bool }
Example #11
Source File: dueros.py From homeassistant-dueros with Apache License 2.0 | 5 votes |
def async_create_refresh_token78( user: models.User, client_id: Optional[str] = None, client_name: Optional[str] = None, client_icon: Optional[str] = None, token_type: str = models.TOKEN_TYPE_NORMAL, access_token_expiration: timedelta = ACCESS_TOKEN_EXPIRATION) \ -> models.RefreshToken: if access_token_expiration == ACCESS_TOKEN_EXPIRATION: access_token_expiration = timedelta(hours=_expire_hours) _LOGGER.info('Access token expiration: %d hours', _expire_hours) """Create a new token for a user.""" kwargs = { 'user': user, 'client_id': client_id, 'token_type': token_type, 'access_token_expiration': access_token_expiration } # type: Dict[str, Any] if client_name: kwargs['client_name'] = client_name if client_icon: kwargs['client_icon'] = client_icon refresh_token = models.RefreshToken(**kwargs) user.refresh_tokens[refresh_token.id] = refresh_token _hass.auth._store._async_schedule_save() return refresh_token
Example #12
Source File: config_flow.py From SmartHouse with MIT License | 5 votes |
def _show_config_form(self, user_input): """Show the configuration form to edit location data.""" # Defaults url = "" api_key = "" port = DEFAULT_PORT_NUMBER verify_ssl = True if user_input is not None: if "url" in user_input: url = user_input["url"] if "api_key" in user_input: api_key = user_input["api_key"] if "port" in user_input: port = user_input["port"] if "verify_ssl" in user_input: verify_ssl = user_input["verify_ssl"] data_schema = OrderedDict() data_schema[vol.Required("url", default=url)] = str data_schema[vol.Required("api_key", default=api_key)] = str data_schema[vol.Optional("port", default=port)] = int data_schema[vol.Optional("verify_ssl", default=verify_ssl)] = bool return self.async_show_form( step_id="user", data_schema=vol.Schema(data_schema), errors=self._errors )
Example #13
Source File: thermostat.py From hass-apps with Apache License 2.0 | 5 votes |
def filter_set_value(self, value: Temp) -> T.Optional[Temp]: """Preprocesses the given target temperature for setting on this thermostat. This algorithm will try best to achieve the closest possible temperature supported by this particular thermostat. The return value is either the temperature to set or None, if nothing has to be sent.""" if value.is_off: value = self.cfg["off_temp"] if not value.is_off: value = value + self.cfg["delta"] if isinstance(self.cfg["min_temp"], Temp) and value < self.cfg["min_temp"]: value = self.cfg["min_temp"] elif ( isinstance(self.cfg["max_temp"], Temp) and value > self.cfg["max_temp"] ): value = self.cfg["max_temp"] elif not self.cfg["supports_hvac_modes"]: self.log( "Not turning off because it doesn't support HVAC modes.", level="WARNING", ) self.log( "Consider defining an off_temp in the actor " "configuration for these cases.", level="WARNING", ) return None return value
Example #14
Source File: dueros.py From homeassistant-dueros with Apache License 2.0 | 5 votes |
def async_create_refresh_token77( user: models.User, client_id: Optional[str] = None) \ -> models.RefreshToken: """Create a new token for a user.""" _LOGGER.info('access token expiration: %d hours', _expire_hours) refresh_token = models.RefreshToken(user=user, client_id=client_id, access_token_expiration = timedelta(hours=_expire_hours)) user.refresh_tokens[refresh_token.id] = refresh_token _hass.auth._store._async_schedule_save() return refresh_token
Example #15
Source File: __init__.py From aligenie with MIT License | 5 votes |
def async_create_refresh_token78( user: models.User, client_id: Optional[str] = None, client_name: Optional[str] = None, client_icon: Optional[str] = None, token_type: str = models.TOKEN_TYPE_NORMAL, access_token_expiration: timedelta = ACCESS_TOKEN_EXPIRATION) \ -> models.RefreshToken: if access_token_expiration == ACCESS_TOKEN_EXPIRATION: access_token_expiration = timedelta(hours=_expire_hours) _LOGGER.info('Access token expiration: %d hours', _expire_hours) """Create a new token for a user.""" kwargs = { 'user': user, 'client_id': client_id, 'token_type': token_type, 'access_token_expiration': access_token_expiration } # type: Dict[str, Any] if client_name: kwargs['client_name'] = client_name if client_icon: kwargs['client_icon'] = client_icon refresh_token = models.RefreshToken(**kwargs) user.refresh_tokens[refresh_token.id] = refresh_token _hass.auth._store._async_schedule_save() return refresh_token
Example #16
Source File: __init__.py From aligenie with MIT License | 5 votes |
def async_create_refresh_token77( user: models.User, client_id: Optional[str] = None) \ -> models.RefreshToken: """Create a new token for a user.""" _LOGGER.info('access token expiration: %d hours', _expire_hours) refresh_token = models.RefreshToken(user=user, client_id=client_id, access_token_expiration = timedelta(hours=_expire_hours)) user.refresh_tokens[refresh_token.id] = refresh_token _hass.auth._store._async_schedule_save() return refresh_token
Example #17
Source File: stats.py From hass-apps with Apache License 2.0 | 5 votes |
def __init__(self, name: str, cfg: T.Dict, app: "SchedyApp") -> None: self.name = name self.cfg = cfg self.app = app self.rooms = [] # type: T.List[Room] self._last_state = None # type: T.Optional[T.Dict[str, StatisticalValueType]] self._update_timer = None # type: T.Optional[uuid.UUID]
Example #18
Source File: thermostat.py From hass-apps with Apache License 2.0 | 5 votes |
def collect_actor_value(self, actor: ActorBase) -> T.Optional[float]: """Collects the difference between target and current temperature.""" assert isinstance(actor, ThermostatActor) current = actor.current_temp target = actor.current_value if current is None or target is None or current.is_off or target.is_off: off_value = self.cfg["off_value"] if off_value is None: # thermostats that are off should be excluded return None return float(off_value) return float(target - current)
Example #19
Source File: config_flow.py From SmartHouse with MIT License | 5 votes |
def async_step_user(self, user_input=None): """Handle a flow initialized by the user.""" hacs = get_hacs() if user_input is not None: return self.async_create_entry(title="", data=user_input) if hacs.configuration.config_type == "yaml": schema = {vol.Optional("not_in_use", default=""): str} else: schema = hacs_config_option_schema(self.config_entry.options) return self.async_show_form(step_id="user", data_schema=vol.Schema(schema))
Example #20
Source File: configuration_schema.py From SmartHouse with MIT License | 5 votes |
def hacs_base_config_schema(config: dict = {}, config_flow: bool = False) -> dict: """Return a shcema configuration dict for HACS.""" if not config: config = { TOKEN: "xxxxxxxxxxxxxxxxxxxxxxxxxxx", SIDEPANEL_ICON: "mdi:alpha-c-box", SIDEPANEL_TITLE: "HACS", APPDAEMON: False, NETDAEMON: False, PYTHON_SCRIPT: False, THEME: False, } if config_flow: return { vol.Required(TOKEN, default=config.get(TOKEN)): str, vol.Optional(SIDEPANEL_TITLE, default=config.get(SIDEPANEL_TITLE)): str, vol.Optional(SIDEPANEL_ICON, default=config.get(SIDEPANEL_ICON)): str, vol.Optional(APPDAEMON, default=config.get(APPDAEMON)): bool, vol.Optional(NETDAEMON, default=config.get(NETDAEMON)): bool, } return { vol.Required(TOKEN, default=config.get(TOKEN)): str, vol.Optional(SIDEPANEL_TITLE, default=config.get(SIDEPANEL_TITLE)): str, vol.Optional(SIDEPANEL_ICON, default=config.get(SIDEPANEL_ICON)): str, vol.Optional(APPDAEMON, default=config.get(APPDAEMON)): bool, vol.Optional(NETDAEMON, default=config.get(NETDAEMON)): bool, vol.Optional(PYTHON_SCRIPT, default=config.get(PYTHON_SCRIPT)): bool, vol.Optional(THEME, default=config.get(THEME)): bool, }
Example #21
Source File: __init__.py From LedFx with MIT License | 5 votes |
def config_updated(self, config): """ Optional event for when an effect's config is updated. This should be used by the subclass only if they need to build up complex properties off the configuration, otherwise the config should just be referenced in the effect's loop directly """ pass
Example #22
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 #23
Source File: config_flow.py From wiserHomeAssistantPlatform with MIT License | 5 votes |
def async_step_init(self, user_input=None): """Handle options flow.""" if user_input is not None: return self.async_create_entry(title="", data=user_input) data_schema = vol.Schema( { vol.Optional( CONF_BOOST_TEMP, default=self.config_entry.options.get( CONF_BOOST_TEMP, DEFAULT_BOOST_TEMP ), ): int, vol.Optional( CONF_BOOST_TEMP_TIME, default=self.config_entry.options.get( CONF_BOOST_TEMP_TIME, DEFAULT_BOOST_TEMP_TIME ), ): int, vol.Optional( CONF_SCAN_INTERVAL, default=self.config_entry.options.get( CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL ), ): int, } ) return self.async_show_form(step_id="init", data_schema=data_schema)
Example #24
Source File: config_flow.py From ShellyForHASS with MIT License | 5 votes |
def v(self, id): default = self.instance.conf.get(id, "") return vol.Optional(id, default=default)
Example #25
Source File: config_flow.py From ShellyForHASS with MIT License | 5 votes |
def async_step_attributes(self, user_input=None): if not user_input: attribs = {} pos = self._step_cnt * 10 for attrib in list(ALL_ATTRIBUTES)[pos:pos+10]: default = attrib in self.instance.conf[CONF_ATTRIBUTES] attribs[vol.Optional(attrib, default=default)] = bool steps = "(" + str(self._step_cnt+1) +"/2)" return self.async_show_form( step_id="attributes", data_schema=vol.Schema(attribs), description_placeholders={"steps": steps} ) attribs = self._options.get("attributes", []) for attr, value in user_input.items(): if value: attribs.append(attr) self._options["attributes"] = attribs if self._step_cnt < 1: self._step_cnt += 1 return await self.async_step_attributes() else: self._step_cnt = 0 return await self.async_step_sensors()
Example #26
Source File: config_flow.py From ShellyForHASS with MIT License | 5 votes |
def async_step_sensors(self, user_input=None): if not user_input: sensors = {} pos = self._step_cnt * 10 for sensor in list(ALL_SENSORS)[pos:pos+10]: default = sensor in self.instance.conf[CONF_SENSORS] sensors[vol.Optional(sensor, default=default)] = bool steps = "(" + str(self._step_cnt+1) +"/2)" return self.async_show_form( step_id="sensors", data_schema=vol.Schema(sensors), description_placeholders={"steps": steps}) sensors = self._options.get("sensors", []) for sensor, value in user_input.items(): if value: sensors.append(sensor) self._options["sensors"] = sensors if self._step_cnt < 1: self._step_cnt += 1 return await self.async_step_sensors() else: return await self.async_step_final()
Example #27
Source File: sensor.py From thermal_comfort with MIT License | 5 votes |
def device_class(self) -> Optional[str]: """Return the device class of the sensor.""" return self._device_class
Example #28
Source File: config_flow.py From Anniversaries with MIT License | 5 votes |
def _show_user_form(self, user_input): name = "" date = "" one_time = DEFAULT_ONE_TIME half_anniversary = DEFAULT_HALF_ANNIVERSARY date_format = DEFAULT_DATE_FORMAT unit_of_measurement = DEFAULT_UNIT_OF_MEASUREMENT id_prefix = DEFAULT_ID_PREFIX if user_input is not None: if CONF_NAME in user_input: name = user_input[CONF_NAME] if CONF_DATE in user_input: date = user_input[CONF_DATE] if CONF_ONE_TIME in user_input: one_time = user_input[CONF_ONE_TIME] if CONF_HALF_ANNIVERSARY in user_input: half_anniversary = user_input[CONF_HALF_ANNIVERSARY] if CONF_DATE_FORMAT in user_input: date_format = user_input[CONF_DATE_FORMAT] if CONF_UNIT_OF_MEASUREMENT in user_input: unit_of_measurement = user_input[CONF_UNIT_OF_MEASUREMENT] if CONF_ID_PREFIX in user_input: id_prefix = user_input[CONF_ID_PREFIX] data_schema = OrderedDict() data_schema[vol.Required(CONF_NAME, default=name)] = str data_schema[vol.Required(CONF_DATE, default=date)] = str data_schema[vol.Required(CONF_ONE_TIME, default=one_time)] = bool data_schema[vol.Required(CONF_HALF_ANNIVERSARY, default=half_anniversary)] = bool data_schema[vol.Required(CONF_DATE_FORMAT, default=date_format)] = str data_schema[vol.Required(CONF_UNIT_OF_MEASUREMENT, default=unit_of_measurement)] = str data_schema[vol.Optional(CONF_ID_PREFIX, default=id_prefix)] = str return self.async_show_form(step_id="user", data_schema=vol.Schema(data_schema), errors=self._errors)
Example #29
Source File: test_voluptuous.py From pydantic with MIT License | 5 votes |
def __init__(self, allow_extra): self.schema = v.Schema( { v.Required('id'): int, v.Required('client_name'): v.All(str, v.Length(max=255)), v.Required('sort_index'): float, # v.Optional('client_email'): v.Maybe(v.Email), v.Optional('client_phone'): v.Maybe(v.All(str, v.Length(max=255))), v.Optional('location'): v.Maybe( v.Schema( { 'latitude': v.Maybe(float), 'longitude': v.Maybe(float) }, required=True ) ), v.Optional('contractor'): v.Maybe(v.All(v.Coerce(int), v.Range(min=1))), v.Optional('upstream_http_referrer'): v.Maybe(v.All(str, v.Length(max=1023))), v.Required('grecaptcha_response'): v.All(str, v.Length(min=20, max=1000)), v.Optional('last_updated'): v.Maybe(parse_datetime), v.Required('skills', default=[]): [ v.Schema( { v.Required('subject'): str, v.Required('subject_id'): int, v.Required('category'): str, v.Required('qual_level'): str, v.Required('qual_level_id'): int, v.Required('qual_level_ranking', default=0): float, } ) ], }, extra=allow_extra, )
Example #30
Source File: user_config.py From stestr with Apache License 2.0 | 5 votes |
def __init__(self, path): self.schema = vp.Schema({ vp.Optional('run'): { vp.Optional('concurrency'): int, vp.Optional('random'): bool, vp.Optional('no-subunit-trace'): bool, vp.Optional('color'): bool, vp.Optional('abbreviate'): bool, vp.Optional('slowest'): bool, vp.Optional('suppress-attachments'): bool, vp.Optional('all-attachments'): bool, }, vp.Optional('failing'): { vp.Optional('list'): bool, }, vp.Optional('last'): { vp.Optional('no-subunit-trace'): bool, vp.Optional('color'): bool, vp.Optional('suppress-attachments'): bool, vp.Optional('all-attachments'): bool, }, vp.Optional('load'): { vp.Optional('force-init'): bool, vp.Optional('subunit-trace'): bool, vp.Optional('color'): bool, vp.Optional('abbreviate'): bool, vp.Optional('suppress-attachments'): bool, vp.Optional('all-attachments'): bool, } }) with open(path, 'r') as fd: self.config = yaml.safe_load(fd.read()) if self.config is None: self.config = {} try: self.schema(self.config) except vp.MultipleInvalid as e: msg = ('Provided user config file {} is invalid ' 'because:\n{}'.format(path, str(e))) sys.exit(msg)