本文整理汇总了Python中voluptuous.Optional方法的典型用法代码示例。如果您正苦于以下问题:Python voluptuous.Optional方法的具体用法?Python voluptuous.Optional怎么用?Python voluptuous.Optional使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类voluptuous
的用法示例。
在下文中一共展示了voluptuous.Optional方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: async_step_user
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [as 别名]
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
)
示例2: fetch_all
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [as 别名]
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
"""
示例3: _show_setup_form
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [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 {},
)
示例4: async_step_init
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [as 别名]
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)),
}
),
)
示例5: async_step_init
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [as 别名]
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)
示例6: async_step_base
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [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)
示例7: async_step_yaml
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [as 别名]
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
)
示例8: schema
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [as 别名]
def schema(self):
if self.required:
return {self.name: self.schema_ext}
else:
return {voluptuous.Optional(self.name): self.schema_ext}
示例9: ResourceSchema
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [as 别名]
def ResourceSchema(schema):
base_schema = {
voluptuous.Optional('started_at'): utils.to_datetime,
voluptuous.Optional('ended_at'): utils.to_datetime,
voluptuous.Optional('user_id'): voluptuous.Any(None, six.text_type),
voluptuous.Optional('project_id'): voluptuous.Any(None, six.text_type),
voluptuous.Optional('metrics'): MetricsSchema,
}
base_schema.update(schema)
return base_schema
示例10: BackwardCompatibleMeasuresList
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [as 别名]
def BackwardCompatibleMeasuresList(v):
v = voluptuous.Schema(
voluptuous.Any(MeasuresListSchema,
{voluptuous.Optional("archive_policy_name"):
six.text_type,
voluptuous.Optional("unit"):
six.text_type,
"measures": MeasuresListSchema}),
required=True)(v)
if isinstance(v, dict):
return v
else:
# Old format
return {"measures": v}
示例11: async_step_user
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [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
)
示例12: validate_config
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [as 别名]
def validate_config(_config):
iptables_sql_schema = voluptuous.Schema({
"module": voluptuous.And(six.string_types[0],
vu.NoSpaceCharacter()),
voluptuous.Optional("db_name"): voluptuous.And(
six.string_types[0], vu.NoSpaceCharacter()),
}, required=True)
return iptables_sql_schema(_config)
示例13: validate_config
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [as 别名]
def validate_config(_config):
source_schema = voluptuous.Schema({
"module": voluptuous.And(six.string_types[0],
vu.NoSpaceCharacter()),
"params": {
"host": voluptuous.And(six.string_types[0],
vu.NoSpaceCharacter()),
"port": int,
"model": {
"name": voluptuous.And(six.string_types[0],
vu.NoSpaceCharacter()),
"params": {
"origin_types": voluptuous.And([
{
"origin_type": voluptuous.And(
six.string_types[0],
vu.NoSpaceCharacter()),
"weight": voluptuous.And(
voluptuous.Or(int, float),
voluptuous.Range(
min=0, min_included=False)),
}
], vu.NotEmptyArray()),
voluptuous.Optional("key_causes"): dict
}
},
"alerts_per_burst": voluptuous.And(
int, voluptuous.Range(min=1)),
"idle_time_between_bursts": voluptuous.And(
voluptuous.Or(int, float),
voluptuous.Range(min=0, min_included=False))
}
}, required=True)
return source_schema(_config)
示例14: validate_config
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [as 别名]
def validate_config(_config):
base_schema = voluptuous.Schema({
"module": voluptuous.And(
six.string_types[0],
lambda i: not any(c.isspace() for c in i)),
voluptuous.Optional("db_name"): voluptuous.And(
six.string_types[0],
lambda i: not any(c.isspace() for c in i)),
}, required=True)
return base_schema(_config)
示例15: async_step_user
# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Optional [as 别名]
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)
del schema["frontend_repo"]
del schema["frontend_repo_url"]
return self.async_show_form(step_id="user", data_schema=vol.Schema(schema))