mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Remove device ID from config schema via YAML in helper template (#120708)
This commit is contained in:
parent
76bdc4f5c4
commit
0d48d5a5ec
@ -88,10 +88,15 @@ BINARY_SENSOR_SCHEMA = vol.Schema(
|
|||||||
vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
|
vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
|
||||||
vol.Required(CONF_STATE): cv.template,
|
vol.Required(CONF_STATE): cv.template,
|
||||||
vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string,
|
vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string,
|
||||||
vol.Optional(CONF_DEVICE_ID): selector.DeviceSelector(),
|
|
||||||
}
|
}
|
||||||
).extend(TEMPLATE_ENTITY_COMMON_SCHEMA.schema)
|
).extend(TEMPLATE_ENTITY_COMMON_SCHEMA.schema)
|
||||||
|
|
||||||
|
BINARY_SENSOR_CONFIG_SCHEMA = BINARY_SENSOR_SCHEMA.extend(
|
||||||
|
{
|
||||||
|
vol.Optional(CONF_DEVICE_ID): selector.DeviceSelector(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
LEGACY_BINARY_SENSOR_SCHEMA = vol.All(
|
LEGACY_BINARY_SENSOR_SCHEMA = vol.All(
|
||||||
cv.deprecated(ATTR_ENTITY_ID),
|
cv.deprecated(ATTR_ENTITY_ID),
|
||||||
vol.Schema(
|
vol.Schema(
|
||||||
@ -206,7 +211,7 @@ async def async_setup_entry(
|
|||||||
"""Initialize config entry."""
|
"""Initialize config entry."""
|
||||||
_options = dict(config_entry.options)
|
_options = dict(config_entry.options)
|
||||||
_options.pop("template_type")
|
_options.pop("template_type")
|
||||||
validated_config = BINARY_SENSOR_SCHEMA(_options)
|
validated_config = BINARY_SENSOR_CONFIG_SCHEMA(_options)
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[BinarySensorTemplate(hass, validated_config, config_entry.entry_id)]
|
[BinarySensorTemplate(hass, validated_config, config_entry.entry_id)]
|
||||||
)
|
)
|
||||||
@ -217,7 +222,7 @@ def async_create_preview_binary_sensor(
|
|||||||
hass: HomeAssistant, name: str, config: dict[str, Any]
|
hass: HomeAssistant, name: str, config: dict[str, Any]
|
||||||
) -> BinarySensorTemplate:
|
) -> BinarySensorTemplate:
|
||||||
"""Create a preview sensor."""
|
"""Create a preview sensor."""
|
||||||
validated_config = BINARY_SENSOR_SCHEMA(config | {CONF_NAME: name})
|
validated_config = BINARY_SENSOR_CONFIG_SCHEMA(config | {CONF_NAME: name})
|
||||||
return BinarySensorTemplate(hass, validated_config, None)
|
return BinarySensorTemplate(hass, validated_config, None)
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +88,6 @@ SENSOR_SCHEMA = vol.All(
|
|||||||
{
|
{
|
||||||
vol.Required(CONF_STATE): cv.template,
|
vol.Required(CONF_STATE): cv.template,
|
||||||
vol.Optional(ATTR_LAST_RESET): cv.template,
|
vol.Optional(ATTR_LAST_RESET): cv.template,
|
||||||
vol.Optional(CONF_DEVICE_ID): selector.DeviceSelector(),
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.extend(TEMPLATE_SENSOR_BASE_SCHEMA.schema)
|
.extend(TEMPLATE_SENSOR_BASE_SCHEMA.schema)
|
||||||
@ -97,6 +96,15 @@ SENSOR_SCHEMA = vol.All(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
SENSOR_CONFIG_SCHEMA = vol.All(
|
||||||
|
vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required(CONF_STATE): cv.template,
|
||||||
|
vol.Optional(CONF_DEVICE_ID): selector.DeviceSelector(),
|
||||||
|
}
|
||||||
|
).extend(TEMPLATE_SENSOR_BASE_SCHEMA.schema),
|
||||||
|
)
|
||||||
|
|
||||||
LEGACY_SENSOR_SCHEMA = vol.All(
|
LEGACY_SENSOR_SCHEMA = vol.All(
|
||||||
cv.deprecated(ATTR_ENTITY_ID),
|
cv.deprecated(ATTR_ENTITY_ID),
|
||||||
vol.Schema(
|
vol.Schema(
|
||||||
@ -230,7 +238,7 @@ async def async_setup_entry(
|
|||||||
"""Initialize config entry."""
|
"""Initialize config entry."""
|
||||||
_options = dict(config_entry.options)
|
_options = dict(config_entry.options)
|
||||||
_options.pop("template_type")
|
_options.pop("template_type")
|
||||||
validated_config = SENSOR_SCHEMA(_options)
|
validated_config = SENSOR_CONFIG_SCHEMA(_options)
|
||||||
async_add_entities([SensorTemplate(hass, validated_config, config_entry.entry_id)])
|
async_add_entities([SensorTemplate(hass, validated_config, config_entry.entry_id)])
|
||||||
|
|
||||||
|
|
||||||
@ -239,7 +247,7 @@ def async_create_preview_sensor(
|
|||||||
hass: HomeAssistant, name: str, config: dict[str, Any]
|
hass: HomeAssistant, name: str, config: dict[str, Any]
|
||||||
) -> SensorTemplate:
|
) -> SensorTemplate:
|
||||||
"""Create a preview sensor."""
|
"""Create a preview sensor."""
|
||||||
validated_config = SENSOR_SCHEMA(config | {CONF_NAME: name})
|
validated_config = SENSOR_CONFIG_SCHEMA(config | {CONF_NAME: name})
|
||||||
return SensorTemplate(hass, validated_config, None)
|
return SensorTemplate(hass, validated_config, None)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user