1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-15 01:32:19 +01:00

[config] Use `cv.UNDEFINED instead of adhoc _UNDEF` objects (#8725)

This commit is contained in:
Jesse Hills
2025-05-09 20:18:52 +12:00
committed by GitHub
parent e1732c4945
commit 8399d894c1
12 changed files with 82 additions and 102 deletions

View File

@@ -309,22 +309,20 @@ SENSOR_SCHEMA = (
)
)
_UNDEF = object()
def sensor_schema(
class_: MockObjClass = _UNDEF,
class_: MockObjClass = cv.UNDEFINED,
*,
unit_of_measurement: str = _UNDEF,
icon: str = _UNDEF,
accuracy_decimals: int = _UNDEF,
device_class: str = _UNDEF,
state_class: str = _UNDEF,
entity_category: str = _UNDEF,
unit_of_measurement: str = cv.UNDEFINED,
icon: str = cv.UNDEFINED,
accuracy_decimals: int = cv.UNDEFINED,
device_class: str = cv.UNDEFINED,
state_class: str = cv.UNDEFINED,
entity_category: str = cv.UNDEFINED,
) -> cv.Schema:
schema = {}
if class_ is not _UNDEF:
if class_ is not cv.UNDEFINED:
# Not optional.
schema[cv.GenerateID()] = cv.declare_id(class_)
@@ -336,7 +334,7 @@ def sensor_schema(
(CONF_STATE_CLASS, state_class, validate_state_class),
(CONF_ENTITY_CATEGORY, entity_category, sensor_entity_category),
]:
if default is not _UNDEF:
if default is not cv.UNDEFINED:
schema[cv.Optional(key, default=default)] = validator
return SENSOR_SCHEMA.extend(schema)
@@ -811,7 +809,9 @@ async def setup_sensor_core_(var, config):
mqtt_ = cg.new_Pvariable(mqtt_id, var)
await mqtt.register_mqtt_component(mqtt_, config)
if (expire_after := config.get(CONF_EXPIRE_AFTER, _UNDEF)) is not _UNDEF:
if (
expire_after := config.get(CONF_EXPIRE_AFTER, cv.UNDEFINED)
) is not cv.UNDEFINED:
if expire_after is None:
cg.add(mqtt_.disable_expire_after())
else: