本文整理汇总了Python中voluptuous.In方法的典型用法代码示例。如果您正苦于以下问题:Python voluptuous.In方法的具体用法?Python voluptuous.In怎么用?Python voluptuous.In使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类voluptuous
的用法示例。
在下文中一共展示了voluptuous.In方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _init_schema
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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)),
}
}
示例2: _show_setup_form
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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 {},
)
示例3: async_step_base
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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)
示例4: async_step_user
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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
)
示例5: hacs_config_option_schema
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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,
}
示例6: async_step_esxi_options
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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),
}
),
)
示例7: _metadata_schema
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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),
})
示例8: _raise_alarm_schema
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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),
})})
示例9: _set_state_schema
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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),
})})
示例10: _add_causal_relationship_schema
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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),
})})
示例11: _mark_down_schema
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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),
})})
示例12: hacs_config_option_schema
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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,
}
示例13: get_config_flow_schema
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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 {}
示例14: _fetch_resources
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import In [as 别名]
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}