Move remaining SENSOR_SCHEMA to use sensor_schema() (#4471)

This commit is contained in:
Jesse Hills 2023-02-20 16:22:37 +13:00 committed by GitHub
parent 247916fe89
commit 50fbbf2d3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 79 additions and 61 deletions

View file

@ -16,13 +16,16 @@ ADC128S102Sensor = adc128s102_ns.class_(
)
CONF_ADC128S102_ID = "adc128s102_id"
CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend(
CONFIG_SCHEMA = (
sensor.sensor_schema(ADC128S102Sensor)
.extend(
{
cv.GenerateID(): cv.declare_id(ADC128S102Sensor),
cv.GenerateID(CONF_ADC128S102_ID): cv.use_id(ADC128S102),
cv.Required(CONF_CHANNEL): cv.int_range(min=0, max=7),
}
).extend(cv.polling_component_schema("60s"))
)
.extend(cv.polling_component_schema("60s"))
)
async def to_code(config):

View file

@ -10,7 +10,7 @@ CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.declare_id(CustomSensorConstructor),
cv.Required(CONF_LAMBDA): cv.returning_lambda,
cv.Required(CONF_SENSORS): cv.ensure_list(sensor.SENSOR_SCHEMA),
cv.Required(CONF_SENSORS): cv.ensure_list(sensor.sensor_schema()),
}
)

View file

@ -41,9 +41,9 @@ DeviceInformationTrigger = ezo_ns.class_(
LedTrigger = ezo_ns.class_("LedTrigger", automation.Trigger.template(cg.bool_))
CONFIG_SCHEMA = (
sensor.SENSOR_SCHEMA.extend(
sensor.sensor_schema(EZOSensor)
.extend(
{
cv.GenerateID(): cv.declare_id(EZOSensor),
cv.Optional(CONF_ON_CUSTOM): automation.validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(CustomTrigger),

View file

@ -48,9 +48,10 @@ def inherit_accuracy_decimals(decimals, config):
return decimals + 2
CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend(
CONFIG_SCHEMA = (
sensor.sensor_schema(IntegrationSensor)
.extend(
{
cv.GenerateID(): cv.declare_id(IntegrationSensor),
cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor),
cv.Required(CONF_TIME_UNIT): cv.enum(INTEGRATION_TIMES, lower=True),
cv.Optional(CONF_INTEGRATION_METHOD, default="trapezoid"): cv.enum(
@ -61,7 +62,9 @@ CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend(
"min_save_interval was removed in 2022.8.0. Please use the `preferences` -> `flash_write_interval` to adjust."
),
}
).extend(cv.COMPONENT_SCHEMA)
)
.extend(cv.COMPONENT_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = cv.All(

View file

@ -23,9 +23,11 @@ CONF_PROCESS_STD_DEV = "process_std_dev"
CONF_STD_DEV = "std_dev"
CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend(cv.COMPONENT_SCHEMA).extend(
CONFIG_SCHEMA = (
sensor.sensor_schema(KalmanCombinatorComponent)
.extend(cv.COMPONENT_SCHEMA)
.extend(
{
cv.GenerateID(): cv.declare_id(KalmanCombinatorComponent),
cv.Required(CONF_PROCESS_STD_DEV): cv.positive_float,
cv.Required(CONF_SOURCES): cv.ensure_list(
cv.Schema(
@ -35,9 +37,10 @@ CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend(cv.COMPONENT_SCHEMA).extend(
}
),
),
cv.Optional(CONF_STD_DEV): sensor.SENSOR_SCHEMA,
cv.Optional(CONF_STD_DEV): sensor.sensor_schema(),
}
)
)
# Inherit some sensor values from the first source, for both the state and the error value
properties_to_inherit = [

View file

@ -14,14 +14,17 @@ MCP3008Sensor = mcp3008_ns.class_(
CONF_REFERENCE_VOLTAGE = "reference_voltage"
CONF_MCP3008_ID = "mcp3008_id"
CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend(
CONFIG_SCHEMA = (
sensor.sensor_schema(MCP3008Sensor)
.extend(
{
cv.GenerateID(): cv.declare_id(MCP3008Sensor),
cv.GenerateID(CONF_MCP3008_ID): cv.use_id(MCP3008),
cv.Required(CONF_NUMBER): cv.int_,
cv.Optional(CONF_REFERENCE_VOLTAGE, default="3.3V"): cv.voltage,
}
).extend(cv.polling_component_schema("1s"))
)
.extend(cv.polling_component_schema("1s"))
)
async def to_code(config):

View file

@ -13,13 +13,16 @@ MCP3204Sensor = mcp3204_ns.class_(
)
CONF_MCP3204_ID = "mcp3204_id"
CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend(
CONFIG_SCHEMA = (
sensor.sensor_schema(MCP3204Sensor)
.extend(
{
cv.GenerateID(): cv.declare_id(MCP3204Sensor),
cv.GenerateID(CONF_MCP3204_ID): cv.use_id(MCP3204),
cv.Required(CONF_NUMBER): cv.int_range(min=0, max=7),
}
).extend(cv.polling_component_schema("60s"))
)
.extend(cv.polling_component_schema("60s"))
)
async def to_code(config):

View file

@ -32,11 +32,11 @@ ModbusSensor = modbus_controller_ns.class_(
)
CONFIG_SCHEMA = cv.All(
sensor.SENSOR_SCHEMA.extend(cv.COMPONENT_SCHEMA)
sensor.sensor_schema(ModbusSensor)
.extend(cv.COMPONENT_SCHEMA)
.extend(ModbusItemBaseSchema)
.extend(
{
cv.GenerateID(): cv.declare_id(ModbusSensor),
cv.Optional(CONF_REGISTER_TYPE): cv.enum(MODBUS_REGISTER_TYPE),
cv.Optional(CONF_VALUE_TYPE, default="U_WORD"): cv.enum(SENSOR_VALUE_TYPE),
cv.Optional(CONF_REGISTER_COUNT, default=0): cv.positive_int,

View file

@ -9,13 +9,16 @@ CODEOWNERS = ["@jesserockz"]
TuyaSensor = tuya_ns.class_("TuyaSensor", sensor.Sensor, cg.Component)
CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend(
CONFIG_SCHEMA = (
sensor.sensor_schema(TuyaSensor)
.extend(
{
cv.GenerateID(): cv.declare_id(TuyaSensor),
cv.GenerateID(CONF_TUYA_ID): cv.use_id(Tuya),
cv.Required(CONF_SENSOR_DATAPOINT): cv.uint8_t,
}
).extend(cv.COMPONENT_SCHEMA)
)
.extend(cv.COMPONENT_SCHEMA)
)
async def to_code(config):