mirror of
https://github.com/esphome/esphome.git
synced 2025-07-28 22:26:36 +00:00
[text_sensor] Fix schema generation (#8773)
This commit is contained in:
parent
c5654b4cb2
commit
6f8ee65919
@ -156,32 +156,24 @@ _TEXT_SENSOR_SCHEMA = (
|
|||||||
def text_sensor_schema(
|
def text_sensor_schema(
|
||||||
class_: MockObjClass = cv.UNDEFINED,
|
class_: MockObjClass = cv.UNDEFINED,
|
||||||
*,
|
*,
|
||||||
icon: str = cv.UNDEFINED,
|
|
||||||
entity_category: str = cv.UNDEFINED,
|
|
||||||
device_class: str = cv.UNDEFINED,
|
device_class: str = cv.UNDEFINED,
|
||||||
|
entity_category: str = cv.UNDEFINED,
|
||||||
|
icon: str = cv.UNDEFINED,
|
||||||
) -> cv.Schema:
|
) -> cv.Schema:
|
||||||
schema = _TEXT_SENSOR_SCHEMA
|
schema = {}
|
||||||
|
|
||||||
if class_ is not cv.UNDEFINED:
|
if class_ is not cv.UNDEFINED:
|
||||||
schema = schema.extend({cv.GenerateID(): cv.declare_id(class_)})
|
schema[cv.GenerateID()] = cv.declare_id(class_)
|
||||||
if icon is not cv.UNDEFINED:
|
|
||||||
schema = schema.extend({cv.Optional(CONF_ICON, default=icon): cv.icon})
|
for key, default, validator in [
|
||||||
if device_class is not cv.UNDEFINED:
|
(CONF_ICON, icon, cv.icon),
|
||||||
schema = schema.extend(
|
(CONF_DEVICE_CLASS, device_class, validate_device_class),
|
||||||
{
|
(CONF_ENTITY_CATEGORY, entity_category, cv.entity_category),
|
||||||
cv.Optional(
|
]:
|
||||||
CONF_DEVICE_CLASS, default=device_class
|
if default is not cv.UNDEFINED:
|
||||||
): validate_device_class
|
schema[cv.Optional(key, default=default)] = validator
|
||||||
}
|
|
||||||
)
|
return _TEXT_SENSOR_SCHEMA.extend(schema)
|
||||||
if entity_category is not cv.UNDEFINED:
|
|
||||||
schema = schema.extend(
|
|
||||||
{
|
|
||||||
cv.Optional(
|
|
||||||
CONF_ENTITY_CATEGORY, default=entity_category
|
|
||||||
): cv.entity_category
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return schema
|
|
||||||
|
|
||||||
|
|
||||||
# Remove before 2025.11.0
|
# Remove before 2025.11.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user